Remove Freeze Time, Make all humans run together + Respawn

Helping Topics
Mystic Viper
Senior Member
Senior Member
Romania
Posts: 112
Joined: 1 Year Ago
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Remove Freeze Time, Make all humans run together + Respawn

#11

Post by Mystic Viper » 1 Month Ago

  1. #include <zombie_escape>
  2.  
  3. // Fowards
  4. enum _:TOTAL_FORWARDS
  5. {
  6.     FORWARD_NONE = 0,
  7.     FORWARD_ROUNDEND,
  8.     FORWARD_HUMANIZED,
  9.     FORWARD_PRE_INFECTED,
  10.     FORWARD_INFECTED,
  11.     FORWARD_ZOMBIE_APPEAR,
  12.     FORWARD_ZOMBIE_RELEASE,
  13.     FORWARD_GAME_STARTED_PRE,
  14.     FORWARD_GAME_STARTED,
  15.     FORWARD_DISCONNECT
  16. }
  17.  
  18. new g_iForwards[TOTAL_FORWARDS], g_iFwReturn, g_iTeam
  19.  
  20. // Tasks IDs
  21. enum
  22. {
  23.     TASK_COUNTDOWN = 1100,
  24.     TASK_COUNTDOWN2,
  25.     TASK_SCORE_MESSAGE,
  26.     FREEZE_ZOMBIES,
  27.     ROUND_TIME_LEFT
  28. }
  29.  
  30. // Colors (g_pCvarColors[] array indexes)
  31. enum
  32. {
  33.     Red = 0,
  34.     Green,
  35.     Blue
  36. }
  37.  
  38. // Variables
  39. new g_iAliveHumansNum,
  40.     g_iAliveZombiesNum,
  41.     g_iRoundTime,
  42.     g_iCountDown,
  43.     g_iReleaseNotice,
  44.     g_iMaxClients,
  45.     g_iHumansScore,
  46.     g_iZombiesScore,
  47.     g_iRoundNum,
  48.     g_iHSpeedFactor[33],
  49.     g_iZSpeedSet[33],
  50.     g_iUserGravity[33],
  51.     bool:g_bGameStarted,
  52.     bool:g_bIsZombie[33],
  53.     bool:g_bIsZombieFrozen[33],
  54.     bool:g_bZombieFreezeTime,
  55.     bool:g_bIsRoundEnding,
  56.     bool:g_bHSpeedUsed[33],
  57.     bool:g_bZSpeedUsed[33],
  58.     bool:g_bEndCalled,
  59.     bool:g_bIsKnockBackUsed[33],
  60.     bool:g_bIsGravityUsed[33],
  61.     bool:g_bEnteredNotChoosed[33],
  62.     Float:g_flReferenceTime,
  63.     Float:g_flUserKnockback[33],
  64.         Float:g_flReferenceTime2
  65.  
  66. // Cvars
  67. new g_pCvarHumanSpeedFactor,
  68.     g_pCvarHumanGravity,
  69.     g_pCvarHumanHealth,
  70.     g_pCvarZombieSpeed,
  71.     g_pCvarZombieGravity,
  72.     g_pCvarZombieReleaseTime,
  73.     g_pCvarFreezeTime,
  74.     g_pCvarRoundTime,
  75.     g_pCvarReqPlayers,
  76.     g_pCvarZombieHealth,
  77.     g_pCvarFirstZombiesHealth,
  78.     g_pCvarZombieKnockback,
  79.     g_pCvarScoreMessageType,
  80.     g_pCvarColors[3],
  81.     g_pCvarRoundEndDelay,
  82.     g_pCvarSmartRandom
  83.    
  84. // Dynamic Arrays
  85. new Array:g_aChosenPlayers
  86.  
  87. public plugin_natives()
  88. {
  89.     register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
  90.     register_native("ze_is_game_started", "native_ze_is_game_started", 1)
  91.     register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
  92.    
  93.     register_native("ze_get_round_number", "native_ze_get_round_number", 1)
  94.     register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
  95.     register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
  96.    
  97.     register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
  98.     register_native("ze_set_user_human", "native_ze_set_user_human", 1)
  99.     register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
  100.     register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
  101.    
  102.     register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
  103.     register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
  104.    
  105.     register_native("ze_get_user_knockback", "native_ze_get_user_knockback", 1)
  106.     register_native("ze_set_user_knockback", "native_ze_set_user_knockback", 1)
  107.     register_native("ze_reset_user_knockback", "native_ze_reset_user_knockback", 1)
  108.    
  109.     register_native("ze_set_user_gravity", "native_ze_set_user_gravity", 1)
  110.     register_native("ze_reset_user_gravity", "native_ze_reset_user_gravity", 1)
  111. }
  112.  
  113. public plugin_init()
  114. {
  115.     register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
  116.    
  117.     // Hook Chains
  118.     RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
  119.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
  120.     RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
  121.     RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
  122.     RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
  123.     RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
  124.     RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "Fw_RestMaxSpeed_Post", 1)
  125.     RegisterHookChain(RG_HandleMenu_ChooseTeam, "Fw_HandleMenu_ChooseTeam_Post", 1)
  126.     RegisterHookChain(RG_HandleMenu_ChooseAppearance, "Fw_HandleMenu_ChoosedAppearance_Post", 1)
  127.    
  128.     // Events
  129.     register_event("HLTV", "New_Round", "a", "1=0", "2=0")
  130.     register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
  131.     register_logevent("Round_Start", 2, "1=Round_Start")
  132.     register_logevent("Round_End", 2, "1=Round_End")
  133.    
  134.     // Create Forwards
  135.     g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
  136.     g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
  137.     g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
  138.     g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
  139.     g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
  140.     g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
  141.     g_iForwards[FORWARD_GAME_STARTED_PRE] = CreateMultiForward("ze_game_started_pre", ET_CONTINUE)
  142.     g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
  143.     g_iForwards[FORWARD_DISCONNECT] = CreateMultiForward("ze_player_disconnect", ET_CONTINUE, FP_CELL)
  144.    
  145.     // Hud Messages
  146.     g_iReleaseNotice = CreateHudSyncObj()
  147.    
  148.     // Registering Messages
  149.     register_message(get_user_msgid("TeamScore"), "Message_Teamscore")
  150.    
  151.     // Sequential files (.txt)
  152.     register_dictionary("zombie_escape.txt")
  153.    
  154.     // Humans Cvars
  155.     g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
  156.     g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
  157.     g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
  158.    
  159.     // Zombie Cvars
  160.     g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
  161.     g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
  162.     g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
  163.     g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
  164.     g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
  165.    
  166.     // General Cvars
  167.     g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
  168.     g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
  169.     g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
  170.     g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
  171.     g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
  172.     g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
  173.     g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
  174.     g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
  175.     g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
  176.     g_pCvarSmartRandom = register_cvar("ze_smart_random", "1")
  177.    
  178.     // Default Values
  179.     g_bGameStarted = false
  180.    
  181.     // Static Values
  182.     g_iMaxClients = get_member_game(m_nMaxPlayers)
  183.    
  184.     // Check Round Time to Terminate it
  185.     set_task(1.0, "Check_RoundTimeleft", ROUND_TIME_LEFT, _, _, "b")
  186. }
  187.  
  188. public plugin_cfg()
  189. {
  190.     // Get our configiration file and Execute it
  191.     new szCfgDir[64]
  192.     get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir))
  193.     server_cmd("exec %s/zombie_escape.cfg", szCfgDir)
  194.    
  195.     // Set Game Name
  196.     new szGameName[64]
  197.     formatex(szGameName, sizeof(szGameName), "Zombie Escape v%s", ZE_VERSION)
  198.     set_member_game(m_GameDesc, szGameName)
  199.    
  200.     // Set Version
  201.     register_cvar("ze_version", ZE_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
  202.     set_cvar_string("ze_version", ZE_VERSION)
  203.    
  204.     // Delay so cvars be loaded from zombie_escape.cfg
  205.     set_task(0.1, "DelaySmartRandom")
  206.    
  207.     // Delay some settings
  208.     set_task(0.1, "DelaySettings")
  209. }
  210.  
  211. public DelaySettings()
  212. {
  213.     // Set some cvars, not allowed to be changed from any other .cfg file (Not recommended to remove them)
  214.     new pCvarRoundTime, pCvarFreezeTime, pCvarMaxSpeed
  215.    
  216.     pCvarRoundTime = get_cvar_pointer("mp_roundtime")
  217.     pCvarFreezeTime = get_cvar_pointer("mp_freezetime")
  218.     pCvarMaxSpeed = get_cvar_pointer("sv_maxspeed")
  219.    
  220.     set_pcvar_num(pCvarRoundTime, get_pcvar_num(g_pCvarRoundTime))
  221.     set_pcvar_num(pCvarFreezeTime, 3)
  222.    
  223.     // Max speed at least equal to zombies speed. Here zombies speed assumed to be higher than humans one.
  224.     if (get_pcvar_num(pCvarMaxSpeed) < get_pcvar_num(g_pCvarZombieSpeed))
  225.     {
  226.         set_pcvar_num(pCvarMaxSpeed, get_pcvar_num(g_pCvarZombieSpeed))
  227.     }
  228. }
  229.  
  230. public DelaySmartRandom()
  231. {
  232.     if (get_pcvar_num(g_pCvarSmartRandom))
  233.     {
  234.         // Create our array to store SteamIDs in
  235.         g_aChosenPlayers = ArrayCreate(34)
  236.     }
  237. }
  238.  
  239. public Fw_CheckMapConditions_Post()
  240. {
  241.     // Block Game Commencing
  242.     set_member_game(m_bGameStarted, true)
  243.    
  244.     // Set Freeze Time
  245.     set_member_game(m_iIntroRoundTime, get_pcvar_num(g_pCvarFreezeTime))
  246.    
  247.     // Set Round Time
  248.     set_member_game(m_iRoundTime, floatround(get_pcvar_float(g_pCvarRoundTime) * 60.0))
  249. }
  250.  
  251. public Fw_PlayerKilled_Post(id)
  252. {
  253.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  254.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  255.    
  256.     if (g_iAliveHumansNum == 0 && g_iAliveZombiesNum == 0)
  257.     {
  258.         // No Winner, All Players in one team killed Or Both teams Killed
  259.         client_print(0, print_center, "%L", LANG_PLAYER, "NO_WINNER")
  260.     }
  261. }
  262.  
  263. public Fw_RestMaxSpeed_Post(id)
  264. {
  265.     if (!g_bIsZombie[id])
  266.     {
  267.         static Float:flMaxSpeed
  268.         get_entvar(id, var_maxspeed, flMaxSpeed)
  269.        
  270.         if (flMaxSpeed != 1.0 && is_user_alive(id))
  271.         {
  272.             if (g_bHSpeedUsed[id])
  273.             {
  274.                 // Set New Human Speed Factor
  275.                 set_entvar(id, var_maxspeed, flMaxSpeed + float(g_iHSpeedFactor[id]))
  276.                 return HC_CONTINUE
  277.             }
  278.                
  279.             // Set Human Speed Factor, native not used
  280.             set_entvar(id, var_maxspeed, flMaxSpeed + get_pcvar_float(g_pCvarHumanSpeedFactor))
  281.             return HC_CONTINUE
  282.         }
  283.     }
  284.    
  285.     return HC_SUPERCEDE
  286. }
  287.  
  288. public Fw_PlayerSpawn_Post(id)
  289. {  
  290.     if (!g_bGameStarted)
  291.     {
  292.         // Force All player to be Humans if Game not started yet
  293.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
  294.     }
  295.     else
  296.     {
  297.         if ((floatround(g_flReferenceTime2)+get_pcvar_num(g_pCvarFreezeTime)) > floatround(get_gametime())+2)
  298.         {
  299.             // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
  300.             Set_User_Human(id)
  301.             g_bIsZombieFrozen[id] = false
  302.         }
  303.         else
  304.         {
  305.             if (g_bZombieFreezeTime)
  306.             {
  307.                 // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
  308.                 Set_User_Zombie(id)
  309.                 g_bIsZombieFrozen[id] = true
  310.                 set_entvar(id, var_maxspeed, 1.0)
  311.             }
  312.             else
  313.             {
  314.                 // Respawn him as normal zombie
  315.                 Set_User_Zombie(id)
  316.                 g_bIsZombieFrozen[id] = false
  317.             }
  318.         }
  319.     }
  320. }
  321.  
  322. public New_Round()
  323. {
  324.         g_flReferenceTime2 = get_gametime()
  325.  
  326.     if (g_bGameStarted)
  327.     {
  328.         g_iRoundNum++
  329.     }
  330.    
  331.     ExecuteForward(g_iForwards[FORWARD_GAME_STARTED_PRE], g_iFwReturn)
  332.    
  333.     if (g_iFwReturn > 0)
  334.     {
  335.         return
  336.     }
  337.    
  338.     // Remove All tasks in the New Round
  339.     remove_task(TASK_COUNTDOWN)
  340.     remove_task(TASK_COUNTDOWN2)
  341.     remove_task(TASK_SCORE_MESSAGE)
  342.     remove_task(FREEZE_ZOMBIES)
  343.    
  344.     // Score Message Task
  345.     set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
  346.    
  347.     if (g_bGameStarted)
  348.     {
  349.         if (g_iRoundNum == 1)
  350.         {
  351.             // 2 is Hardcoded Value, It's Fix for the countdown to work correctly first round
  352.             g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
  353.         }
  354.         else
  355.         {
  356.             // 3 is Hardcoded Value, It's Fix for the countdown to work correctly after first round
  357.             g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 3
  358.         }
  359.     }
  360.    
  361.     if (!g_bGameStarted)
  362.     {
  363.         // No Enough Players
  364.         ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
  365.         return // Block the execution of the blew code
  366.     }
  367.    
  368.     // Game Already started, Countdown now started
  369.     set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
  370.     ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
  371.     ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
  372.    
  373.     // Round Starting
  374.     g_bIsRoundEnding = false
  375.     g_bEndCalled = false
  376. }
  377.  
  378. // Score Message Task
  379. public Score_Message(TaskID)
  380. {
  381.     switch(get_pcvar_num(g_pCvarScoreMessageType))
  382.     {
  383.         case 0: // Disabled
  384.         {
  385.             return
  386.         }
  387.         case 1: // DHUD
  388.         {
  389.             set_dhudmessage(get_pcvar_num(g_pCvarColors[Red]), get_pcvar_num(g_pCvarColors[Green]), get_pcvar_num(g_pCvarColors[Blue]), -1.0, 0.01, 0, 0.0, 9.0)
  390.             show_dhudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
  391.         }
  392.         case 2: // HUD
  393.         {
  394.             set_hudmessage(get_pcvar_num(g_pCvarColors[Red]), get_pcvar_num(g_pCvarColors[Green]), get_pcvar_num(g_pCvarColors[Blue]), -1.0, 0.01, 0, 0.0, 9.0)
  395.             show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
  396.         }
  397.     }
  398. }
  399.  
  400. public Countdown_Start(TaskID)
  401. {
  402.     // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
  403.     if (!g_bGameStarted)
  404.         return
  405.    
  406.     if (!g_iCountDown)
  407.     {
  408.         Choose_Zombies()
  409.         remove_task(TASK_COUNTDOWN) // Remove the task
  410.         return // Block the execution of the blew code
  411.     }
  412.    
  413.     set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
  414.     show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
  415.  
  416.     g_iCountDown--
  417. }
  418.  
  419. public Choose_Zombies()
  420. {
  421.     new iZombies, id, iAliveCount
  422.     new iReqZombies
  423.    
  424.     // Get total alive players and required players
  425.     iAliveCount  = GetAllAlivePlayersNum()
  426.     iReqZombies = RequiredZombies()
  427.    
  428.     // Loop till we find req players
  429.     while(iZombies < iReqZombies)
  430.     {
  431.         id = GetRandomAlive(random_num(1, iAliveCount))
  432.        
  433.         if (!is_user_alive(id) || g_bIsZombie[id])
  434.             continue
  435.        
  436.         if (get_pcvar_num(g_pCvarSmartRandom))
  437.         {
  438.             // If player in the array, it means he chosen previous round so skip him this round
  439.             if (IsPlayerInArray(g_aChosenPlayers, id))
  440.                 continue
  441.         }
  442.  
  443.         Set_User_Zombie(id)
  444.         set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
  445.         g_bIsZombieFrozen[id] = true
  446.         g_bZombieFreezeTime = true
  447.         set_entvar(id, var_maxspeed, 1.0)
  448.         set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
  449.         ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
  450.         iZombies++
  451.  
  452.                 // Respawn Zombies to base
  453.                 rg_round_respawn(id)
  454.     }
  455.    
  456.     if (get_pcvar_num(g_pCvarSmartRandom))
  457.     {
  458.         // Clear the array first
  459.         ArrayClear(g_aChosenPlayers)
  460.        
  461.         new szAuthId[34]
  462.        
  463.         // Add steamid of chosen zombies, so we don't choose them next round again (using steamid means it support reconnect)
  464.         for (new id = 1; id <= g_iMaxClients; id++)
  465.         {
  466.             if(!is_user_connected(id) || !g_bIsZombie[id])
  467.                 continue
  468.            
  469.             get_user_authid(id, szAuthId, charsmax(szAuthId))
  470.            
  471.             ArrayPushString(g_aChosenPlayers, szAuthId)
  472.         }
  473.     }
  474.    
  475.     // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
  476.     g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
  477.    
  478.     set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
  479. }
  480.  
  481. public ReleaseZombie_CountDown(TaskID)
  482. {
  483.     if (!g_iCountDown)
  484.     {
  485.         ReleaseZombie()
  486.         remove_task(TASK_COUNTDOWN2)
  487.         return
  488.     }
  489.    
  490.     // Release Hud Message
  491.     set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
  492.     ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
  493.    
  494.     g_iCountDown --
  495. }
  496.  
  497. public ReleaseZombie()
  498. {
  499.     ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
  500.    
  501.     for(new id = 1; id <= g_iMaxClients; id++)
  502.     {
  503.         if (is_user_alive(id) && g_bIsZombie[id])
  504.         {
  505.             g_bIsZombieFrozen[id] = false
  506.             g_bZombieFreezeTime = false
  507.         }
  508.     }
  509. }
  510.  
  511. public Freeze_Zombies(TaskID)
  512. {
  513.     for(new id = 1; id <= g_iMaxClients; id++)
  514.     {
  515.         if(!is_user_alive(id) || !g_bIsZombie[id])
  516.             continue
  517.        
  518.         if (g_bIsZombieFrozen[id])
  519.         {
  520.             // Zombie & Frozen, then Freeze him
  521.             set_entvar(id, var_maxspeed, 1.0)
  522.         }
  523.         else
  524.         {
  525.             if (g_bZSpeedUsed[id])
  526.             {
  527.                 // Zombie but Not Frozen the set his speed form .cfg
  528.                 set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
  529.                 continue;
  530.             }
  531.                
  532.             // Zombie but Not Frozen the set his speed form .cfg
  533.             set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
  534.         }
  535.     }
  536. }
  537.  
  538. public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
  539. {
  540.     if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
  541.         return HC_CONTINUE
  542.    
  543.     // Attacker and Victim is in same teams? Skip code blew
  544.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
  545.         return HC_CONTINUE
  546.    
  547.     // In freeze time? Skip all other plugins (Skip the real trace attack event)
  548.     if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
  549.         return HC_SUPERCEDE
  550.    
  551.     // Execute pre-infection forward
  552.     ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker, floatround(flDamage))
  553.    
  554.     if (g_iFwReturn > 0)
  555.     {
  556.         return HC_SUPERCEDE
  557.     }
  558.    
  559.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  560.    
  561.     if (g_bIsZombie[iAttacker])
  562.     {
  563.         // Death Message with Infection style [Added here because of delay in Forward use]
  564.         SendDeathMsg(iAttacker, iVictim)
  565.        
  566.         Set_User_Zombie(iVictim)
  567.        
  568.         ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
  569.        
  570.         if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
  571.         {
  572.             // End round event called one time
  573.             g_bEndCalled = true
  574.            
  575.             // Round is Ending
  576.             g_bIsRoundEnding = true
  577.            
  578.             // Zombie Win, Leave text blank so we use ours from ML
  579.             rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  580.            
  581.             // Show Our Message
  582.             client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  583.            
  584.             // This needed so forward work also to add +1 for Zombies
  585.             g_iTeam = ZE_TEAM_ZOMBIE
  586.             ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  587.         }
  588.     }
  589.    
  590.     return HC_CONTINUE
  591. }
  592.  
  593. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:flDamage, bitsDamageType)
  594. {
  595.     // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
  596.     if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
  597.         return HC_CONTINUE
  598.    
  599.     // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
  600.     if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
  601.     {
  602.         // Remove Shock Pain
  603.         set_member(iVictim, m_flVelocityModifier, 1.0)
  604.        
  605.         // Set Knockback
  606.         static Float:flOrigin[3]
  607.         get_entvar(iAttacker, var_origin, flOrigin)
  608.         Set_Knockback(iVictim, flOrigin, g_bIsKnockBackUsed[iVictim] ? g_flUserKnockback[iVictim]:get_pcvar_float(g_pCvarZombieKnockback), 2)
  609.     }
  610.    
  611.     return HC_CONTINUE
  612. }
  613.  
  614. public Round_End()
  615. {
  616.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  617.    
  618.     if (g_iAliveZombiesNum == 0 && g_bGameStarted)
  619.     {
  620.         g_iTeam = ZE_TEAM_HUMAN
  621.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  622.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  623.         g_iHumansScore++
  624.         g_bIsRoundEnding = true
  625.         return // To block Execute the code blew
  626.     }
  627.    
  628.     g_iTeam = ZE_TEAM_ZOMBIE
  629.     g_iZombiesScore++
  630.     g_bIsRoundEnding = true
  631.    
  632.     // If it's already called one time, don't call it again
  633.     if (!g_bEndCalled)
  634.     {
  635.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  636.     }
  637.    
  638.     client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  639. }
  640.  
  641. public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
  642. {
  643.     // The two unhandeld cases by rg_round_end() native in our Mod
  644.     if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
  645.     {
  646.         SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
  647.     }
  648. }
  649.  
  650. public Round_Start()
  651. {
  652.     g_flReferenceTime = get_gametime()
  653.     g_iRoundTime = get_member_game(m_iRoundTime)
  654. }
  655.  
  656. public Check_RoundTimeleft()
  657. {
  658.     new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
  659.    
  660.     if (floatround(flRoundTimeLeft) == 0 && !g_bIsRoundEnding && !get_member_game(m_bFreezePeriod))
  661.     {
  662.         // Round is Ending
  663.         g_bIsRoundEnding = true
  664.        
  665.         // If Time is Out then Terminate the Round
  666.         rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  667.        
  668.         // Show our Message
  669.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  670.     }
  671. }
  672.  
  673. public client_disconnected(id)
  674. {
  675.     // Reset speed for this dropped id
  676.     g_bHSpeedUsed[id] = false
  677.     g_bZSpeedUsed[id] = false
  678.     g_bIsKnockBackUsed[id] = false
  679.     g_bIsGravityUsed[id] = false
  680.     g_flUserKnockback[id] = 0.0
  681.     g_iUserGravity[id] = 0
  682.    
  683.     remove_task(id)
  684.    
  685.     // Execute our disconnected forward
  686.     ExecuteForward(g_iForwards[FORWARD_DISCONNECT], g_iFwReturn, id)
  687.    
  688.     if (g_iFwReturn > 0)
  689.     {
  690.         // Here return, function ended here, below won't be executed
  691.         return
  692.     }
  693.    
  694.     // Delay Then Check Players to Terminate The round (Delay needed)
  695.     set_task(0.1, "Check_AlivePlayers")
  696. }
  697.  
  698. // This check done when player disconnect
  699. public Check_AlivePlayers()
  700. {
  701.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  702.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  703.    
  704.     // Game Started? (There is at least 2 players Alive?)
  705.     if (g_bGameStarted)
  706.     {
  707.         // We are in freeze time?
  708.         if (get_member_game(m_bFreezePeriod))
  709.         {
  710.             // Humans alive number = 1 and no zombies?
  711.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
  712.             {
  713.                 // Game started false again
  714.                 g_bGameStarted = false
  715.             }
  716.         }
  717.         else // Not freeze time?
  718.         {
  719.             // Variables
  720.             new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
  721.             iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
  722.             iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
  723.             iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
  724.    
  725.             // Alive humans number = 1 and no zombies at all, And no dead humans?
  726.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
  727.             {
  728.                 // Game started is false and humans wins (Escape Success)
  729.                 g_bGameStarted = false
  730.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
  731.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  732.             }
  733.            
  734.             // Alive zombies number = 1 and no humans at all, And no dead zombies?
  735.             if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
  736.             {
  737.                 // Game started is false and zombies wins (Escape Fail)
  738.                 g_bGameStarted = false
  739.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  740.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  741.             }
  742.            
  743.             // Humans number more than 1 and no zombies?
  744.             if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding)
  745.             {
  746.                 // Then Escape success as there is no Zombies
  747.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
  748.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  749.             }
  750.            
  751.             // Zombies number more than 1 and no humans?
  752.             if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
  753.             {
  754.                 // Then Escape Fail as there is no humans
  755.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  756.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  757.             }
  758.         }
  759.     }
  760. }
  761.  
  762. public client_putinserver(id)
  763. {
  764.     // Add Delay and Check Conditions To start the Game (Delay needed)
  765.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
  766.    
  767.     // Check for dead terrorists - Bug fix
  768.     set_task(0.1, "CheckTerrorists", id, _, _, "b")
  769. }
  770.  
  771. public CheckTerrorists(id)
  772. {
  773.     if (g_bEnteredNotChoosed[id] && g_bGameStarted)
  774.     {
  775.         if (is_user_connected(id))
  776.         {
  777.             rg_join_team(id, TEAM_CT) // Force user to choose CT
  778.             g_bEnteredNotChoosed[id] = false
  779.         }
  780.     }
  781. }
  782.  
  783. public Fw_HandleMenu_ChoosedAppearance_Post(const index, const slot)
  784. {
  785.     g_bEnteredNotChoosed[index] = false
  786. }
  787.  
  788. public Fw_HandleMenu_ChooseTeam_Post(id, MenuChooseTeam:iSlot)
  789. {
  790.     // Fixing Dead-T restarting the round
  791.     if (iSlot == MenuChoose_T) // Choosed T, Still not choosed a player
  792.     {
  793.         g_bEnteredNotChoosed[id] = true
  794.     }
  795.    
  796.     if ((iSlot == MenuChoose_AutoSelect) && (get_member(id, m_iTeam) == TEAM_TERRORIST))
  797.     {
  798.         g_bEnteredNotChoosed[id] = true
  799.     }
  800.    
  801.     // Add Delay and Check Conditions To start the Game (Delay needed)
  802.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
  803. }
  804.  
  805. public Check_AllPlayersNumber(TaskID)
  806. {
  807.     if (g_bGameStarted)
  808.     {
  809.         // If game started remove the task and block the blew Checks
  810.         remove_task(TaskID)
  811.         return
  812.     }
  813.    
  814.     if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
  815.     {
  816.         // Players In server == The Required so game started is true
  817.         g_bGameStarted = true
  818.        
  819.         // Restart the game
  820.         server_cmd("sv_restart 2")
  821.        
  822.         // Print Fake game Commencing Message
  823.         client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
  824.        
  825.         // Remove the task
  826.         remove_task(TaskID)
  827.     }
  828. }
  829.  
  830. public Set_User_Human(id)
  831. {
  832.     if (!is_user_alive(id))
  833.         return
  834.    
  835.     g_bIsZombie[id] = false
  836.     set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
  837.     set_entvar(id, var_gravity, float(g_bIsGravityUsed[id] ? g_iUserGravity[id]:get_pcvar_num(g_pCvarHumanGravity))/800.0)
  838.     ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
  839.    
  840.     // Reset Nightvision (Useful for antidote, so when someone use sethuman native the nightvision also reset)
  841.     Set_NightVision(id, 0, 0, 0x0000, 0, 0, 0, 0)
  842.    
  843.     if (get_member(id, m_iTeam) != TEAM_CT)
  844.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
  845. }
  846.  
  847. public Set_User_Zombie(id)
  848. {
  849.     if (!is_user_alive(id))
  850.         return
  851.    
  852.     g_bIsZombie[id] = true
  853.     set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
  854.     set_entvar(id, var_gravity, float(g_bIsGravityUsed[id] ? g_iUserGravity[id] : get_pcvar_num(g_pCvarZombieGravity))/800.0)
  855.     rg_remove_all_items(id)
  856.     rg_give_item(id, "weapon_knife", GT_APPEND)
  857.     ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
  858.    
  859.     if (get_member(id, m_iTeam) != TEAM_TERRORIST)
  860.         rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
  861. }
  862.  
  863. public Map_Restart()
  864. {
  865.     // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
  866.     set_task(0.1, "Reset_Score_Message")
  867. }
  868.  
  869. public Reset_Score_Message()
  870. {
  871.     g_iHumansScore = 0
  872.     g_iZombiesScore = 0
  873.     g_iRoundNum = 0
  874. }
  875.  
  876. public plugin_end()
  877. {
  878.     if (get_pcvar_num(g_pCvarSmartRandom))
  879.     {
  880.         ArrayDestroy(g_aChosenPlayers)
  881.     }
  882. }
  883.  
  884. public Message_Teamscore()
  885. {
  886.     new szTeam[2]
  887.     get_msg_arg_string(1, szTeam, charsmax(szTeam))
  888.    
  889.     switch (szTeam[0])
  890.     {
  891.         case 'C': set_msg_arg_int(2, get_msg_argtype(2), g_iHumansScore)
  892.         case 'T': set_msg_arg_int(2, get_msg_argtype(2), g_iZombiesScore)
  893.     }
  894. }
  895.  
  896. // Natives
  897. public native_ze_is_user_zombie(id)
  898. {
  899.     if (!is_user_connected(id))
  900.     {
  901.         return -1;
  902.     }
  903.    
  904.     return g_bIsZombie[id]
  905. }
  906.  
  907. public native_ze_set_user_zombie(id)
  908. {
  909.     if (!is_user_connected(id))
  910.     {
  911.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  912.         return false;
  913.     }
  914.    
  915.     Set_User_Zombie(id)
  916.     return true;
  917. }
  918.  
  919. public native_ze_set_user_human(id)
  920. {
  921.     if (!is_user_connected(id))
  922.     {
  923.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  924.         return false;
  925.     }
  926.    
  927.     Set_User_Human(id)
  928.     return true;
  929. }
  930.  
  931. public native_ze_is_game_started()
  932. {
  933.     return g_bGameStarted
  934. }
  935.  
  936. public native_ze_is_zombie_frozen(id)
  937. {
  938.     if (!is_user_connected(id) || !g_bIsZombie[id])
  939.     {
  940.         return -1;
  941.     }
  942.    
  943.     return g_bIsZombieFrozen[id]
  944. }
  945.  
  946. public native_ze_get_round_number()
  947. {
  948.     if (!g_bGameStarted)
  949.     {
  950.         return -1;
  951.     }
  952.    
  953.     return g_iRoundNum
  954. }
  955.  
  956. public native_ze_get_humans_number()
  957. {
  958.     return GetAlivePlayersNum(CsTeams:TEAM_CT)
  959. }
  960.  
  961. public native_ze_get_zombies_number()
  962. {
  963.     return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  964. }
  965.  
  966. public native_ze_set_human_speed_factor(id, iFactor)
  967. {
  968.     if (!is_user_connected(id))
  969.     {
  970.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  971.         return false;
  972.     }
  973.    
  974.     g_bHSpeedUsed[id] = true
  975.     g_iHSpeedFactor[id] = iFactor
  976.     rg_reset_maxspeed(id)
  977.     return true;
  978. }
  979.  
  980. public native_ze_reset_human_speed(id)
  981. {
  982.     if (!is_user_connected(id))
  983.     {
  984.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  985.         return false;
  986.     }
  987.    
  988.     g_bHSpeedUsed[id] = false
  989.     rg_reset_maxspeed(id)
  990.     return true;
  991. }
  992.  
  993. public native_ze_set_zombie_speed(id, iSpeed)
  994. {
  995.     if (!is_user_connected(id))
  996.     {
  997.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  998.         return false;
  999.     }
  1000.    
  1001.     g_bZSpeedUsed[id] = true
  1002.     g_iZSpeedSet[id] = iSpeed
  1003.     return true;
  1004. }
  1005.  
  1006. public native_ze_reset_zombie_speed(id)
  1007. {
  1008.     if (!is_user_connected(id))
  1009.     {
  1010.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1011.         return false;
  1012.     }
  1013.    
  1014.     g_bZSpeedUsed[id] = false
  1015.     return true;
  1016. }
  1017.  
  1018. public native_ze_get_user_knockback(id)
  1019. {
  1020.     if (!is_user_connected(id))
  1021.     {
  1022.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1023.         return -1
  1024.     }
  1025.  
  1026.     return floatround(g_bIsKnockBackUsed[id] ? g_flUserKnockback[id]:get_pcvar_float(g_pCvarZombieKnockback))
  1027. }
  1028.  
  1029. public native_ze_set_user_knockback(id, Float:flKnockback)
  1030. {
  1031.     if (!is_user_connected(id))
  1032.     {
  1033.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1034.         return false
  1035.     }
  1036.    
  1037.     g_bIsKnockBackUsed[id] = true
  1038.     g_flUserKnockback[id] = flKnockback
  1039.     return true
  1040. }
  1041.  
  1042. public native_ze_reset_user_knockback(id)
  1043. {
  1044.     if (!is_user_connected(id))
  1045.     {
  1046.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1047.         return false
  1048.     }
  1049.  
  1050.     g_bIsKnockBackUsed[id] = false
  1051.     g_flUserKnockback[id] = 0.0
  1052.     return true
  1053. }
  1054.  
  1055. public native_ze_set_user_gravity(id, iGravity)
  1056. {
  1057.     if (!is_user_connected(id))
  1058.     {
  1059.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1060.         return false
  1061.     }
  1062.    
  1063.     g_bIsGravityUsed[id] = true
  1064.     g_iUserGravity[id] = iGravity
  1065.     set_entvar(id, var_gravity, float(iGravity) / 800.0)
  1066.  
  1067.     return true
  1068. }
  1069.  
  1070. public native_ze_reset_user_gravity(id)
  1071. {
  1072.     if (!is_user_connected(id))
  1073.     {
  1074.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1075.         return false
  1076.     }
  1077.  
  1078.     g_bIsGravityUsed[id] = false
  1079.     set_entvar(id, var_gravity, float(g_bIsZombie[id] ? get_pcvar_num(g_pCvarZombieGravity):get_pcvar_num(g_pCvarHumanGravity)) / 800.0)
  1080.  
  1081.     return true
  1082. }
When we are in countdown and someone is going to join on server then round restart everytime. But it happens randomly.

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1997
Joined: 3 Years Ago
Location: Egypt
Has thanked: 33 times
Been thanked: 111 times
Age: 22
Contact:

#12

Post by Raheem » 3 Weeks Ago

The problem is when someone disconnects, round restart with status "Escape Success".

Problem resolved:

  1. #include <zombie_escape>
  2.  
  3. // Fowards
  4. enum _:TOTAL_FORWARDS
  5. {
  6.     FORWARD_NONE = 0,
  7.     FORWARD_ROUNDEND,
  8.     FORWARD_HUMANIZED,
  9.     FORWARD_PRE_INFECTED,
  10.     FORWARD_INFECTED,
  11.     FORWARD_ZOMBIE_APPEAR,
  12.     FORWARD_ZOMBIE_RELEASE,
  13.     FORWARD_GAME_STARTED_PRE,
  14.     FORWARD_GAME_STARTED,
  15.     FORWARD_DISCONNECT
  16. }
  17.  
  18. new g_iForwards[TOTAL_FORWARDS], g_iFwReturn, g_iTeam
  19.  
  20. // Tasks IDs
  21. enum
  22. {
  23.     TASK_COUNTDOWN = 1100,
  24.     TASK_COUNTDOWN2,
  25.     TASK_SCORE_MESSAGE,
  26.     FREEZE_ZOMBIES,
  27.     ROUND_TIME_LEFT,
  28.     CHOOSED_TASK_ID
  29. }
  30.  
  31. // Colors (g_pCvarColors[] array indexes)
  32. enum
  33. {
  34.     Red = 0,
  35.     Green,
  36.     Blue
  37. }
  38.  
  39. // Variables
  40. new g_iAliveHumansNum,
  41.     g_iAliveZombiesNum,
  42.     g_iRoundTime,
  43.     g_iCountDown,
  44.     g_iReleaseNotice,
  45.     g_iMaxClients,
  46.     g_iHumansScore,
  47.     g_iZombiesScore,
  48.     g_iRoundNum,
  49.     g_iHSpeedFactor[33],
  50.     g_iZSpeedSet[33],
  51.     g_iUserGravity[33],
  52.     bool:g_bGameStarted,
  53.     bool:g_bIsZombie[33],
  54.     bool:g_bIsZombieFrozen[33],
  55.     bool:g_bZombieFreezeTime,
  56.     bool:g_bIsRoundEnding,
  57.     bool:g_bHSpeedUsed[33],
  58.     bool:g_bZSpeedUsed[33],
  59.     bool:g_bEndCalled,
  60.     bool:g_bIsKnockBackUsed[33],
  61.     bool:g_bIsGravityUsed[33],
  62.     bool:g_bEnteredNotChoosed[33],
  63.     Float:g_flReferenceTime,
  64.     Float:g_flUserKnockback[33],
  65.     Float:g_flReferenceTime2,
  66.     bool:g_bZombieChosen
  67.  
  68. // Cvars
  69. new g_pCvarHumanSpeedFactor,
  70.     g_pCvarHumanGravity,
  71.     g_pCvarHumanHealth,
  72.     g_pCvarZombieSpeed,
  73.     g_pCvarZombieGravity,
  74.     g_pCvarZombieReleaseTime,
  75.     g_pCvarFreezeTime,
  76.     g_pCvarRoundTime,
  77.     g_pCvarReqPlayers,
  78.     g_pCvarZombieHealth,
  79.     g_pCvarFirstZombiesHealth,
  80.     g_pCvarZombieKnockback,
  81.     g_pCvarScoreMessageType,
  82.     g_pCvarColors[3],
  83.     g_pCvarRoundEndDelay,
  84.     g_pCvarSmartRandom
  85.    
  86. // Dynamic Arrays
  87. new Array:g_aChosenPlayers
  88.  
  89. public plugin_natives()
  90. {
  91.     register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
  92.     register_native("ze_is_game_started", "native_ze_is_game_started", 1)
  93.     register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
  94.    
  95.     register_native("ze_get_round_number", "native_ze_get_round_number", 1)
  96.     register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
  97.     register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
  98.    
  99.     register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
  100.     register_native("ze_set_user_human", "native_ze_set_user_human", 1)
  101.     register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
  102.     register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
  103.    
  104.     register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
  105.     register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
  106.    
  107.     register_native("ze_get_user_knockback", "native_ze_get_user_knockback", 1)
  108.     register_native("ze_set_user_knockback", "native_ze_set_user_knockback", 1)
  109.     register_native("ze_reset_user_knockback", "native_ze_reset_user_knockback", 1)
  110.    
  111.     register_native("ze_set_user_gravity", "native_ze_set_user_gravity", 1)
  112.     register_native("ze_reset_user_gravity", "native_ze_reset_user_gravity", 1)
  113. }
  114.  
  115. public plugin_init()
  116. {
  117.     register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
  118.    
  119.     // Hook Chains
  120.     RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
  121.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
  122.     RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
  123.     RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
  124.     RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
  125.     RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
  126.     RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "Fw_RestMaxSpeed_Post", 1)
  127.     RegisterHookChain(RG_HandleMenu_ChooseTeam, "Fw_HandleMenu_ChooseTeam_Post", 1)
  128.     RegisterHookChain(RG_HandleMenu_ChooseAppearance, "Fw_HandleMenu_ChoosedAppearance_Post", 1)
  129.    
  130.     // Events
  131.     register_event("HLTV", "New_Round", "a", "1=0", "2=0")
  132.     register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
  133.     register_logevent("Round_Start", 2, "1=Round_Start")
  134.     register_logevent("Round_End", 2, "1=Round_End")
  135.    
  136.     // Create Forwards
  137.     g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
  138.     g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
  139.     g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
  140.     g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
  141.     g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
  142.     g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
  143.     g_iForwards[FORWARD_GAME_STARTED_PRE] = CreateMultiForward("ze_game_started_pre", ET_CONTINUE)
  144.     g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
  145.     g_iForwards[FORWARD_DISCONNECT] = CreateMultiForward("ze_player_disconnect", ET_CONTINUE, FP_CELL)
  146.    
  147.     // Hud Messages
  148.     g_iReleaseNotice = CreateHudSyncObj()
  149.    
  150.     // Registering Messages
  151.     register_message(get_user_msgid("TeamScore"), "Message_Teamscore")
  152.    
  153.     // Sequential files (.txt)
  154.     register_dictionary("zombie_escape.txt")
  155.    
  156.     // Humans Cvars
  157.     g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
  158.     g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
  159.     g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
  160.    
  161.     // Zombie Cvars
  162.     g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
  163.     g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
  164.     g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
  165.     g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
  166.     g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
  167.    
  168.     // General Cvars
  169.     g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
  170.     g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
  171.     g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
  172.     g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
  173.     g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
  174.     g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
  175.     g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
  176.     g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
  177.     g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
  178.     g_pCvarSmartRandom = register_cvar("ze_smart_random", "1")
  179.    
  180.     // Default Values
  181.     g_bGameStarted = false
  182.    
  183.     // Static Values
  184.     g_iMaxClients = get_member_game(m_nMaxPlayers)
  185.    
  186.     // Check Round Time to Terminate it
  187.     set_task(1.0, "Check_RoundTimeleft", ROUND_TIME_LEFT, _, _, "b")
  188. }
  189.  
  190. public plugin_cfg()
  191. {
  192.     // Get our configiration file and Execute it
  193.     new szCfgDir[64]
  194.     get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir))
  195.     server_cmd("exec %s/zombie_escape.cfg", szCfgDir)
  196.    
  197.     // Set Game Name
  198.     new szGameName[64]
  199.     formatex(szGameName, sizeof(szGameName), "Zombie Escape v%s", ZE_VERSION)
  200.     set_member_game(m_GameDesc, szGameName)
  201.    
  202.     // Set Version
  203.     register_cvar("ze_version", ZE_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
  204.     set_cvar_string("ze_version", ZE_VERSION)
  205.    
  206.     // Delay so cvars be loaded from zombie_escape.cfg
  207.     set_task(0.1, "DelaySmartRandom")
  208.    
  209.     // Delay some settings
  210.     set_task(0.1, "DelaySettings")
  211. }
  212.  
  213. public DelaySettings()
  214. {
  215.     // Set some cvars, not allowed to be changed from any other .cfg file (Not recommended to remove them)
  216.     new pCvarRoundTime, pCvarFreezeTime, pCvarMaxSpeed
  217.    
  218.     pCvarRoundTime = get_cvar_pointer("mp_roundtime")
  219.     pCvarFreezeTime = get_cvar_pointer("mp_freezetime")
  220.     pCvarMaxSpeed = get_cvar_pointer("sv_maxspeed")
  221.    
  222.     set_pcvar_num(pCvarRoundTime, get_pcvar_num(g_pCvarRoundTime))
  223.     set_pcvar_num(pCvarFreezeTime, 3)
  224.    
  225.     // Max speed at least equal to zombies speed. Here zombies speed assumed to be higher than humans one.
  226.     if (get_pcvar_num(pCvarMaxSpeed) < get_pcvar_num(g_pCvarZombieSpeed))
  227.     {
  228.         set_pcvar_num(pCvarMaxSpeed, get_pcvar_num(g_pCvarZombieSpeed))
  229.     }
  230. }
  231.  
  232. public DelaySmartRandom()
  233. {
  234.     if (get_pcvar_num(g_pCvarSmartRandom))
  235.     {
  236.         // Create our array to store SteamIDs in
  237.         g_aChosenPlayers = ArrayCreate(34)
  238.     }
  239. }
  240.  
  241. public Fw_CheckMapConditions_Post()
  242. {
  243.     // Block Game Commencing
  244.     set_member_game(m_bGameStarted, true)
  245.    
  246.     // Set Freeze Time
  247.     set_member_game(m_iIntroRoundTime, get_pcvar_num(g_pCvarFreezeTime))
  248.    
  249.     // Set Round Time
  250.     set_member_game(m_iRoundTime, floatround(get_pcvar_float(g_pCvarRoundTime) * 60.0))
  251. }
  252.  
  253. public Fw_PlayerKilled_Post(id)
  254. {
  255.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  256.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  257.    
  258.     if (g_iAliveHumansNum == 0 && g_iAliveZombiesNum == 0)
  259.     {
  260.         // No Winner, All Players in one team killed Or Both teams Killed
  261.         client_print(0, print_center, "%L", LANG_PLAYER, "NO_WINNER")
  262.     }
  263. }
  264.  
  265. public Fw_RestMaxSpeed_Post(id)
  266. {
  267.     if (!g_bIsZombie[id])
  268.     {
  269.         static Float:flMaxSpeed
  270.         get_entvar(id, var_maxspeed, flMaxSpeed)
  271.        
  272.         if (flMaxSpeed != 1.0 && is_user_alive(id))
  273.         {
  274.             if (g_bHSpeedUsed[id])
  275.             {
  276.                 // Set New Human Speed Factor
  277.                 set_entvar(id, var_maxspeed, flMaxSpeed + float(g_iHSpeedFactor[id]))
  278.                 return HC_CONTINUE
  279.             }
  280.                
  281.             // Set Human Speed Factor, native not used
  282.             set_entvar(id, var_maxspeed, flMaxSpeed + get_pcvar_float(g_pCvarHumanSpeedFactor))
  283.             return HC_CONTINUE
  284.         }
  285.     }
  286.    
  287.     return HC_SUPERCEDE
  288. }
  289.  
  290. public Fw_PlayerSpawn_Post(id)
  291. {  
  292.     if (!g_bGameStarted)
  293.     {
  294.         // Force All player to be Humans if Game not started yet
  295.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
  296.     }
  297.     else
  298.     {
  299.         if ((floatround(g_flReferenceTime2)+get_pcvar_num(g_pCvarFreezeTime)) > floatround(get_gametime())+2)
  300.         {
  301.             // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
  302.             Set_User_Human(id)
  303.             g_bIsZombieFrozen[id] = false
  304.         }
  305.         else
  306.         {
  307.             if (g_bZombieFreezeTime)
  308.             {
  309.                 // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
  310.                 Set_User_Zombie(id)
  311.                 g_bIsZombieFrozen[id] = true
  312.                 set_entvar(id, var_maxspeed, 1.0)
  313.             }
  314.             else
  315.             {
  316.                 // Respawn him as normal zombie
  317.                 Set_User_Zombie(id)
  318.                 g_bIsZombieFrozen[id] = false
  319.             }
  320.         }
  321.     }
  322. }
  323.  
  324. public New_Round()
  325. {
  326.         g_flReferenceTime2 = get_gametime()
  327.  
  328.     if (g_bGameStarted)
  329.     {
  330.         g_iRoundNum++
  331.     }
  332.    
  333.     ExecuteForward(g_iForwards[FORWARD_GAME_STARTED_PRE], g_iFwReturn)
  334.    
  335.     if (g_iFwReturn > 0)
  336.     {
  337.         return
  338.     }
  339.    
  340.     // Remove All tasks in the New Round
  341.     remove_task(TASK_COUNTDOWN)
  342.     remove_task(TASK_COUNTDOWN2)
  343.     remove_task(TASK_SCORE_MESSAGE)
  344.     remove_task(FREEZE_ZOMBIES)
  345.     remove_task(CHOOSED_TASK_ID)
  346.    
  347.     // Score Message Task
  348.     set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
  349.    
  350.     if (g_bGameStarted)
  351.     {
  352.         if (g_iRoundNum == 1)
  353.         {
  354.             // 2 is Hardcoded Value, It's Fix for the countdown to work correctly first round
  355.             g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
  356.         }
  357.         else
  358.         {
  359.             // 3 is Hardcoded Value, It's Fix for the countdown to work correctly after first round
  360.             g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 3
  361.         }
  362.     }
  363.    
  364.     if (!g_bGameStarted)
  365.     {
  366.         // No Enough Players
  367.         ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
  368.         return // Block the execution of the blew code
  369.     }
  370.    
  371.     // Game Already started, Countdown now started
  372.     set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
  373.     ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
  374.     ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
  375.    
  376.     // Round Starting
  377.     g_bIsRoundEnding = false
  378.     g_bEndCalled = false
  379.     g_bZombieChosen = false
  380.    
  381.     set_task(get_pcvar_float(g_pCvarFreezeTime)+1.0, "Choosed", CHOOSED_TASK_ID)
  382. }
  383.  
  384. public Choosed()
  385. {
  386.     g_bZombieChosen = true
  387. }
  388.  
  389. // Score Message Task
  390. public Score_Message(TaskID)
  391. {
  392.     switch(get_pcvar_num(g_pCvarScoreMessageType))
  393.     {
  394.         case 0: // Disabled
  395.         {
  396.             return
  397.         }
  398.         case 1: // DHUD
  399.         {
  400.             set_dhudmessage(get_pcvar_num(g_pCvarColors[Red]), get_pcvar_num(g_pCvarColors[Green]), get_pcvar_num(g_pCvarColors[Blue]), -1.0, 0.01, 0, 0.0, 9.0)
  401.             show_dhudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
  402.         }
  403.         case 2: // HUD
  404.         {
  405.             set_hudmessage(get_pcvar_num(g_pCvarColors[Red]), get_pcvar_num(g_pCvarColors[Green]), get_pcvar_num(g_pCvarColors[Blue]), -1.0, 0.01, 0, 0.0, 9.0)
  406.             show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
  407.         }
  408.     }
  409. }
  410.  
  411. public Countdown_Start(TaskID)
  412. {
  413.     // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
  414.     if (!g_bGameStarted)
  415.         return
  416.    
  417.     if (!g_iCountDown)
  418.     {
  419.         Choose_Zombies()
  420.         remove_task(TASK_COUNTDOWN) // Remove the task
  421.         return // Block the execution of the blew code
  422.     }
  423.    
  424.     set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
  425.     show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
  426.  
  427.     g_iCountDown--
  428. }
  429.  
  430. public Choose_Zombies()
  431. {
  432.     new iZombies, id, iAliveCount
  433.     new iReqZombies
  434.    
  435.     // Get total alive players and required players
  436.     iAliveCount  = GetAllAlivePlayersNum()
  437.     iReqZombies = RequiredZombies()
  438.    
  439.     // Loop till we find req players
  440.     while(iZombies < iReqZombies)
  441.     {
  442.         id = GetRandomAlive(random_num(1, iAliveCount))
  443.        
  444.         if (!is_user_alive(id) || g_bIsZombie[id])
  445.             continue
  446.        
  447.         if (get_pcvar_num(g_pCvarSmartRandom))
  448.         {
  449.             // If player in the array, it means he chosen previous round so skip him this round
  450.             if (IsPlayerInArray(g_aChosenPlayers, id))
  451.                 continue
  452.         }
  453.  
  454.         Set_User_Zombie(id)
  455.         set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
  456.         g_bIsZombieFrozen[id] = true
  457.         g_bZombieFreezeTime = true
  458.         set_entvar(id, var_maxspeed, 1.0)
  459.         set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
  460.         ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
  461.         iZombies++
  462.  
  463.                 // Respawn Zombies to base
  464.                 rg_round_respawn(id)
  465.     }
  466.    
  467.     if (get_pcvar_num(g_pCvarSmartRandom))
  468.     {
  469.         // Clear the array first
  470.         ArrayClear(g_aChosenPlayers)
  471.        
  472.         new szAuthId[34]
  473.        
  474.         // Add steamid of chosen zombies, so we don't choose them next round again (using steamid means it support reconnect)
  475.         for (new id = 1; id <= g_iMaxClients; id++)
  476.         {
  477.             if(!is_user_connected(id) || !g_bIsZombie[id])
  478.                 continue
  479.            
  480.             get_user_authid(id, szAuthId, charsmax(szAuthId))
  481.            
  482.             ArrayPushString(g_aChosenPlayers, szAuthId)
  483.         }
  484.     }
  485.    
  486.     // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
  487.     g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
  488.    
  489.     set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
  490. }
  491.  
  492. public ReleaseZombie_CountDown(TaskID)
  493. {
  494.     if (!g_iCountDown)
  495.     {
  496.         ReleaseZombie()
  497.         remove_task(TASK_COUNTDOWN2)
  498.         return
  499.     }
  500.    
  501.     // Release Hud Message
  502.     set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
  503.     ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
  504.    
  505.     g_iCountDown --
  506. }
  507.  
  508. public ReleaseZombie()
  509. {
  510.     ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
  511.    
  512.     for(new id = 1; id <= g_iMaxClients; id++)
  513.     {
  514.         if (is_user_alive(id) && g_bIsZombie[id])
  515.         {
  516.             g_bIsZombieFrozen[id] = false
  517.             g_bZombieFreezeTime = false
  518.         }
  519.     }
  520. }
  521.  
  522. public Freeze_Zombies(TaskID)
  523. {
  524.     for(new id = 1; id <= g_iMaxClients; id++)
  525.     {
  526.         if(!is_user_alive(id) || !g_bIsZombie[id])
  527.             continue
  528.        
  529.         if (g_bIsZombieFrozen[id])
  530.         {
  531.             // Zombie & Frozen, then Freeze him
  532.             set_entvar(id, var_maxspeed, 1.0)
  533.         }
  534.         else
  535.         {
  536.             if (g_bZSpeedUsed[id])
  537.             {
  538.                 // Zombie but Not Frozen the set his speed form .cfg
  539.                 set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
  540.                 continue;
  541.             }
  542.                
  543.             // Zombie but Not Frozen the set his speed form .cfg
  544.             set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
  545.         }
  546.     }
  547. }
  548.  
  549. public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
  550. {
  551.     if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
  552.         return HC_CONTINUE
  553.    
  554.     // Attacker and Victim is in same teams? Skip code blew
  555.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
  556.         return HC_CONTINUE
  557.    
  558.     // In freeze time? Skip all other plugins (Skip the real trace attack event)
  559.     if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
  560.         return HC_SUPERCEDE
  561.    
  562.     // Execute pre-infection forward
  563.     ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker, floatround(flDamage))
  564.    
  565.     if (g_iFwReturn > 0)
  566.     {
  567.         return HC_SUPERCEDE
  568.     }
  569.    
  570.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  571.    
  572.     if (g_bIsZombie[iAttacker])
  573.     {
  574.         // Death Message with Infection style [Added here because of delay in Forward use]
  575.         SendDeathMsg(iAttacker, iVictim)
  576.        
  577.         Set_User_Zombie(iVictim)
  578.        
  579.         ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
  580.        
  581.         if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
  582.         {
  583.             // End round event called one time
  584.             g_bEndCalled = true
  585.            
  586.             // Round is Ending
  587.             g_bIsRoundEnding = true
  588.            
  589.             // Zombie Win, Leave text blank so we use ours from ML
  590.             rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  591.            
  592.             // Show Our Message
  593.             client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  594.            
  595.             // This needed so forward work also to add +1 for Zombies
  596.             g_iTeam = ZE_TEAM_ZOMBIE
  597.             ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  598.         }
  599.     }
  600.    
  601.     return HC_CONTINUE
  602. }
  603.  
  604. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:flDamage, bitsDamageType)
  605. {
  606.     // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
  607.     if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
  608.         return HC_CONTINUE
  609.    
  610.     // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
  611.     if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
  612.     {
  613.         // Remove Shock Pain
  614.         set_member(iVictim, m_flVelocityModifier, 1.0)
  615.        
  616.         // Set Knockback
  617.         static Float:flOrigin[3]
  618.         get_entvar(iAttacker, var_origin, flOrigin)
  619.         Set_Knockback(iVictim, flOrigin, g_bIsKnockBackUsed[iVictim] ? g_flUserKnockback[iVictim]:get_pcvar_float(g_pCvarZombieKnockback), 2)
  620.     }
  621.    
  622.     return HC_CONTINUE
  623. }
  624.  
  625. public Round_End()
  626. {
  627.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  628.    
  629.     if (g_iAliveZombiesNum == 0 && g_bGameStarted)
  630.     {
  631.         g_iTeam = ZE_TEAM_HUMAN
  632.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  633.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  634.         g_iHumansScore++
  635.         g_bIsRoundEnding = true
  636.         return // To block Execute the code blew
  637.     }
  638.    
  639.     g_iTeam = ZE_TEAM_ZOMBIE
  640.     g_iZombiesScore++
  641.     g_bIsRoundEnding = true
  642.    
  643.     // If it's already called one time, don't call it again
  644.     if (!g_bEndCalled)
  645.     {
  646.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  647.     }
  648.    
  649.     client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  650. }
  651.  
  652. public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
  653. {
  654.     // The two unhandeld cases by rg_round_end() native in our Mod
  655.     if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
  656.     {
  657.         SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
  658.     }
  659. }
  660.  
  661. public Round_Start()
  662. {
  663.     g_flReferenceTime = get_gametime()
  664.     g_iRoundTime = get_member_game(m_iRoundTime)
  665. }
  666.  
  667. public Check_RoundTimeleft()
  668. {
  669.     new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
  670.    
  671.     if (floatround(flRoundTimeLeft) == 0 && !g_bIsRoundEnding && !get_member_game(m_bFreezePeriod))
  672.     {
  673.         // Round is Ending
  674.         g_bIsRoundEnding = true
  675.        
  676.         // If Time is Out then Terminate the Round
  677.         rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  678.        
  679.         // Show our Message
  680.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  681.     }
  682. }
  683.  
  684. public client_disconnected(id)
  685. {
  686.     // Reset speed for this dropped id
  687.     g_bHSpeedUsed[id] = false
  688.     g_bZSpeedUsed[id] = false
  689.     g_bIsKnockBackUsed[id] = false
  690.     g_bIsGravityUsed[id] = false
  691.     g_flUserKnockback[id] = 0.0
  692.     g_iUserGravity[id] = 0
  693.    
  694.     remove_task(id)
  695.    
  696.     // Execute our disconnected forward
  697.     ExecuteForward(g_iForwards[FORWARD_DISCONNECT], g_iFwReturn, id)
  698.    
  699.     if (g_iFwReturn > 0)
  700.     {
  701.         // Here return, function ended here, below won't be executed
  702.         return
  703.     }
  704.    
  705.     // Delay Then Check Players to Terminate The round (Delay needed)
  706.     set_task(0.1, "Check_AlivePlayers")
  707. }
  708.  
  709. // This check done when player disconnect
  710. public Check_AlivePlayers()
  711. {
  712.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  713.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  714.    
  715.     // Game Started? (There is at least 2 players Alive?)
  716.     if (g_bGameStarted)
  717.     {
  718.         // We are in freeze time?
  719.         if (get_member_game(m_bFreezePeriod))
  720.         {
  721.             // Humans alive number = 1 and no zombies?
  722.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
  723.             {
  724.                 // Game started false again
  725.                 g_bGameStarted = false
  726.             }
  727.         }
  728.         else // Not freeze time?
  729.         {
  730.             // Variables
  731.             new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
  732.             iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
  733.             iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
  734.             iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
  735.    
  736.             // Alive humans number = 1 and no zombies at all, And no dead humans?
  737.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
  738.             {
  739.                 // Game started is false and humans wins (Escape Success)
  740.                 g_bGameStarted = false
  741.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
  742.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  743.             }
  744.            
  745.             // Alive zombies number = 1 and no humans at all, And no dead zombies?
  746.             if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
  747.             {
  748.                 // Game started is false and zombies wins (Escape Fail)
  749.                 g_bGameStarted = false
  750.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  751.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  752.             }
  753.            
  754.             // Humans number more than 1 and no zombies?
  755.             if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding && g_bZombieChosen)
  756.             {
  757.                 // Then Escape success as there is no Zombies
  758.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
  759.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  760.             }
  761.            
  762.             // Zombies number more than 1 and no humans?
  763.             if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
  764.             {
  765.                 // Then Escape Fail as there is no humans
  766.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  767.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  768.             }
  769.         }
  770.     }
  771. }
  772.  
  773. public client_putinserver(id)
  774. {
  775.     // Add Delay and Check Conditions To start the Game (Delay needed)
  776.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
  777.    
  778.     // Check for dead terrorists - Bug fix
  779.     set_task(0.1, "CheckTerrorists", id, _, _, "b")
  780. }
  781.  
  782. public CheckTerrorists(id)
  783. {
  784.     if (g_bEnteredNotChoosed[id] && g_bGameStarted)
  785.     {
  786.         if (is_user_connected(id))
  787.         {
  788.             rg_join_team(id, TEAM_CT) // Force user to choose CT
  789.             g_bEnteredNotChoosed[id] = false
  790.         }
  791.     }
  792. }
  793.  
  794. public Fw_HandleMenu_ChoosedAppearance_Post(const index, const slot)
  795. {
  796.     g_bEnteredNotChoosed[index] = false
  797. }
  798.  
  799. public Fw_HandleMenu_ChooseTeam_Post(id, MenuChooseTeam:iSlot)
  800. {
  801.     // Fixing Dead-T restarting the round
  802.     if (iSlot == MenuChoose_T) // Choosed T, Still not choosed a player
  803.     {
  804.         g_bEnteredNotChoosed[id] = true
  805.     }
  806.    
  807.     if ((iSlot == MenuChoose_AutoSelect) && (get_member(id, m_iTeam) == TEAM_TERRORIST))
  808.     {
  809.         g_bEnteredNotChoosed[id] = true
  810.     }
  811.    
  812.     // Add Delay and Check Conditions To start the Game (Delay needed)
  813.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
  814. }
  815.  
  816. public Check_AllPlayersNumber(TaskID)
  817. {
  818.     if (g_bGameStarted)
  819.     {
  820.         // If game started remove the task and block the blew Checks
  821.         remove_task(TaskID)
  822.         return
  823.     }
  824.    
  825.     if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
  826.     {
  827.         // Players In server == The Required so game started is true
  828.         g_bGameStarted = true
  829.        
  830.         // Restart the game
  831.         server_cmd("sv_restart 2")
  832.        
  833.         // Print Fake game Commencing Message
  834.         client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
  835.        
  836.         // Remove the task
  837.         remove_task(TaskID)
  838.     }
  839. }
  840.  
  841. public Set_User_Human(id)
  842. {
  843.     if (!is_user_alive(id))
  844.         return
  845.    
  846.     g_bIsZombie[id] = false
  847.     set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
  848.     set_entvar(id, var_gravity, float(g_bIsGravityUsed[id] ? g_iUserGravity[id]:get_pcvar_num(g_pCvarHumanGravity))/800.0)
  849.     ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
  850.    
  851.     // Reset Nightvision (Useful for antidote, so when someone use sethuman native the nightvision also reset)
  852.     Set_NightVision(id, 0, 0, 0x0000, 0, 0, 0, 0)
  853.    
  854.     if (get_member(id, m_iTeam) != TEAM_CT)
  855.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
  856. }
  857.  
  858. public Set_User_Zombie(id)
  859. {
  860.     if (!is_user_alive(id))
  861.         return
  862.    
  863.     g_bIsZombie[id] = true
  864.     set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
  865.     set_entvar(id, var_gravity, float(g_bIsGravityUsed[id] ? g_iUserGravity[id] : get_pcvar_num(g_pCvarZombieGravity))/800.0)
  866.     rg_remove_all_items(id)
  867.     rg_give_item(id, "weapon_knife", GT_APPEND)
  868.     ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
  869.    
  870.     if (get_member(id, m_iTeam) != TEAM_TERRORIST)
  871.         rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
  872. }
  873.  
  874. public Map_Restart()
  875. {
  876.     // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
  877.     set_task(0.1, "Reset_Score_Message")
  878. }
  879.  
  880. public Reset_Score_Message()
  881. {
  882.     g_iHumansScore = 0
  883.     g_iZombiesScore = 0
  884.     g_iRoundNum = 0
  885. }
  886.  
  887. public plugin_end()
  888. {
  889.     if (get_pcvar_num(g_pCvarSmartRandom))
  890.     {
  891.         ArrayDestroy(g_aChosenPlayers)
  892.     }
  893. }
  894.  
  895. public Message_Teamscore()
  896. {
  897.     new szTeam[2]
  898.     get_msg_arg_string(1, szTeam, charsmax(szTeam))
  899.    
  900.     switch (szTeam[0])
  901.     {
  902.         case 'C': set_msg_arg_int(2, get_msg_argtype(2), g_iHumansScore)
  903.         case 'T': set_msg_arg_int(2, get_msg_argtype(2), g_iZombiesScore)
  904.     }
  905. }
  906.  
  907. // Natives
  908. public native_ze_is_user_zombie(id)
  909. {
  910.     if (!is_user_connected(id))
  911.     {
  912.         return -1;
  913.     }
  914.    
  915.     return g_bIsZombie[id]
  916. }
  917.  
  918. public native_ze_set_user_zombie(id)
  919. {
  920.     if (!is_user_connected(id))
  921.     {
  922.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  923.         return false;
  924.     }
  925.    
  926.     Set_User_Zombie(id)
  927.     return true;
  928. }
  929.  
  930. public native_ze_set_user_human(id)
  931. {
  932.     if (!is_user_connected(id))
  933.     {
  934.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  935.         return false;
  936.     }
  937.    
  938.     Set_User_Human(id)
  939.     return true;
  940. }
  941.  
  942. public native_ze_is_game_started()
  943. {
  944.     return g_bGameStarted
  945. }
  946.  
  947. public native_ze_is_zombie_frozen(id)
  948. {
  949.     if (!is_user_connected(id) || !g_bIsZombie[id])
  950.     {
  951.         return -1;
  952.     }
  953.    
  954.     return g_bIsZombieFrozen[id]
  955. }
  956.  
  957. public native_ze_get_round_number()
  958. {
  959.     if (!g_bGameStarted)
  960.     {
  961.         return -1;
  962.     }
  963.    
  964.     return g_iRoundNum
  965. }
  966.  
  967. public native_ze_get_humans_number()
  968. {
  969.     return GetAlivePlayersNum(CsTeams:TEAM_CT)
  970. }
  971.  
  972. public native_ze_get_zombies_number()
  973. {
  974.     return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  975. }
  976.  
  977. public native_ze_set_human_speed_factor(id, iFactor)
  978. {
  979.     if (!is_user_connected(id))
  980.     {
  981.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  982.         return false;
  983.     }
  984.    
  985.     g_bHSpeedUsed[id] = true
  986.     g_iHSpeedFactor[id] = iFactor
  987.     rg_reset_maxspeed(id)
  988.     return true;
  989. }
  990.  
  991. public native_ze_reset_human_speed(id)
  992. {
  993.     if (!is_user_connected(id))
  994.     {
  995.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  996.         return false;
  997.     }
  998.    
  999.     g_bHSpeedUsed[id] = false
  1000.     rg_reset_maxspeed(id)
  1001.     return true;
  1002. }
  1003.  
  1004. public native_ze_set_zombie_speed(id, iSpeed)
  1005. {
  1006.     if (!is_user_connected(id))
  1007.     {
  1008.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1009.         return false;
  1010.     }
  1011.    
  1012.     g_bZSpeedUsed[id] = true
  1013.     g_iZSpeedSet[id] = iSpeed
  1014.     return true;
  1015. }
  1016.  
  1017. public native_ze_reset_zombie_speed(id)
  1018. {
  1019.     if (!is_user_connected(id))
  1020.     {
  1021.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1022.         return false;
  1023.     }
  1024.    
  1025.     g_bZSpeedUsed[id] = false
  1026.     return true;
  1027. }
  1028.  
  1029. public native_ze_get_user_knockback(id)
  1030. {
  1031.     if (!is_user_connected(id))
  1032.     {
  1033.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1034.         return -1
  1035.     }
  1036.  
  1037.     return floatround(g_bIsKnockBackUsed[id] ? g_flUserKnockback[id]:get_pcvar_float(g_pCvarZombieKnockback))
  1038. }
  1039.  
  1040. public native_ze_set_user_knockback(id, Float:flKnockback)
  1041. {
  1042.     if (!is_user_connected(id))
  1043.     {
  1044.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1045.         return false
  1046.     }
  1047.    
  1048.     g_bIsKnockBackUsed[id] = true
  1049.     g_flUserKnockback[id] = flKnockback
  1050.     return true
  1051. }
  1052.  
  1053. public native_ze_reset_user_knockback(id)
  1054. {
  1055.     if (!is_user_connected(id))
  1056.     {
  1057.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1058.         return false
  1059.     }
  1060.  
  1061.     g_bIsKnockBackUsed[id] = false
  1062.     g_flUserKnockback[id] = 0.0
  1063.     return true
  1064. }
  1065.  
  1066. public native_ze_set_user_gravity(id, iGravity)
  1067. {
  1068.     if (!is_user_connected(id))
  1069.     {
  1070.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1071.         return false
  1072.     }
  1073.    
  1074.     g_bIsGravityUsed[id] = true
  1075.     g_iUserGravity[id] = iGravity
  1076.     set_entvar(id, var_gravity, float(iGravity) / 800.0)
  1077.  
  1078.     return true
  1079. }
  1080.  
  1081. public native_ze_reset_user_gravity(id)
  1082. {
  1083.     if (!is_user_connected(id))
  1084.     {
  1085.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  1086.         return false
  1087.     }
  1088.  
  1089.     g_bIsGravityUsed[id] = false
  1090.     set_entvar(id, var_gravity, float(g_bIsZombie[id] ? get_pcvar_num(g_pCvarZombieGravity):get_pcvar_num(g_pCvarHumanGravity)) / 800.0)
  1091.  
  1092.     return true
  1093. }

I'll update the fix in the main topic.
You don't know? Learn and you will know.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest