Remove Freeze Time, Make all humans run together + Respawn

Helping Topics
Post Reply
Templaso
Senior Member
Senior Member
Romania
Posts: 119
Joined: 5 years ago
Location: Bucharest
Contact:

#11

Post by Templaso » 4 years 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
Posts: 2214
Joined: 7 years ago
Contact:

#12

Post by Raheem » 4 years 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.
He who fails to plan is planning to fail

User avatar
z0h1r-LK
Mod Developer
Mod Developer
Morocco
Posts: 473
Joined: 5 years ago
Location: The Red City ❤
Contact:

#13

Post by z0h1r-LK » 3 years ago

Thanks so much @Raheem

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#14

Post by Raheem » 3 years ago

Edited ze_core.sma for version 1.6:
    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
    19.  
    20. // Tasks IDs
    21. enum
    22. {
    23.     TASK_COUNTDOWN = 1100,
    24.     TASK_COUNTDOWN2,
    25.     TASK_SCORE_MESSAGE,
    26.     ZOMBIES_SPEED,
    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.     bool:g_bDisconnectHumanWin,
    64.     bool:g_bZombieChosen,
    65.     Float:g_flReferenceTime,
    66.     Float:g_flReferenceTime2,
    67.     Float:g_flUserKnockback[33]
    68.  
    69. // Cvars
    70. new g_pCvarHumanSpeedFactor,
    71.     g_pCvarHumanGravity,
    72.     g_pCvarHumanHealth,
    73.     g_pCvarZombieSpeed,
    74.     g_pCvarZombieGravity,
    75.     g_pCvarZombieReleaseTime,
    76.     g_pCvarFreezeTime,
    77.     g_pCvarRoundTime,
    78.     g_pCvarReqPlayers,
    79.     g_pCvarZombieHealth,
    80.     g_pCvarFirstZombiesHealth,
    81.     g_pCvarZombieKnockback,
    82.     g_pCvarScoreMessageType,
    83.     g_pCvarColors[3],
    84.     g_pCvarRoundEndDelay,
    85.     g_pCvarSmartRandom
    86.    
    87. // Dynamic Arrays
    88. new Array:g_aChosenPlayers
    89.  
    90. public plugin_natives()
    91. {
    92.     register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
    93.     register_native("ze_is_game_started", "native_ze_is_game_started", 1)
    94.     register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
    95.    
    96.     register_native("ze_get_round_number", "native_ze_get_round_number", 1)
    97.     register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
    98.     register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
    99.    
    100.     register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
    101.     register_native("ze_set_user_human", "native_ze_set_user_human", 1)
    102.     register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
    103.     register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
    104.    
    105.     register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
    106.     register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
    107.    
    108.     register_native("ze_get_user_knockback", "native_ze_get_user_knockback", 1)
    109.     register_native("ze_set_user_knockback", "native_ze_set_user_knockback", 1)
    110.     register_native("ze_reset_user_knockback", "native_ze_reset_user_knockback", 1)
    111.    
    112.     register_native("ze_set_user_gravity", "native_ze_set_user_gravity", 1)
    113.     register_native("ze_reset_user_gravity", "native_ze_reset_user_gravity", 1)
    114.    
    115.     register_native("ze_remove_zombie_freeze_msg", "native_ze_remove_zombie_freeze_msg", 1)
    116. }
    117.  
    118. public plugin_init()
    119. {
    120.     register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
    121.    
    122.     // Hook Chains
    123.     RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
    124.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    125.     RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
    126.     RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
    127.     RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
    128.     RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
    129.     RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "Fw_RestMaxSpeed_Post", 1)
    130.     RegisterHookChain(RG_HandleMenu_ChooseTeam, "Fw_HandleMenu_ChooseTeam_Post", 1)
    131.     RegisterHookChain(RG_HandleMenu_ChooseAppearance, "Fw_HandleMenu_ChoosedAppearance_Post", 1)
    132.    
    133.     // Events
    134.     register_event("HLTV", "New_Round", "a", "1=0", "2=0")
    135.     register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
    136.     register_logevent("Round_Start", 2, "1=Round_Start")
    137.     register_logevent("Round_End", 2, "1=Round_End")
    138.    
    139.     // Create Forwards
    140.     g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
    141.     g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
    142.     g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
    143.     g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
    144.     g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
    145.     g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
    146.     g_iForwards[FORWARD_GAME_STARTED_PRE] = CreateMultiForward("ze_game_started_pre", ET_CONTINUE)
    147.     g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
    148.     g_iForwards[FORWARD_DISCONNECT] = CreateMultiForward("ze_player_disconnect", ET_CONTINUE, FP_CELL)
    149.    
    150.     // Hud Messages
    151.     g_iReleaseNotice = CreateHudSyncObj()
    152.    
    153.     // Registering Messages
    154.     register_message(get_user_msgid("TeamScore"), "Message_Teamscore")
    155.    
    156.     // Sequential files (.txt)
    157.     register_dictionary("zombie_escape.txt")
    158.    
    159.     // Humans Cvars
    160.     g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
    161.     g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
    162.     g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
    163.    
    164.     // Zombie Cvars
    165.     g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
    166.     g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
    167.     g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
    168.     g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
    169.     g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
    170.    
    171.     // General Cvars
    172.     g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
    173.     g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
    174.     g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
    175.     g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
    176.     g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
    177.     g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
    178.     g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
    179.     g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
    180.     g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
    181.     g_pCvarSmartRandom = register_cvar("ze_smart_random", "1")
    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, 0)
    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.     else
    287.     {
    288.         if (g_bZombieFreezeTime)
    289.         {
    290.             // Fix for zombie weapon switching that can give him small speed in zombie freeze time
    291.             set_entvar(id, var_maxspeed, 1.0)
    292.         }
    293.     }
    294.    
    295.     return HC_SUPERCEDE
    296. }
    297.  
    298. public Fw_PlayerSpawn_Post(id)
    299. {  
    300.     if (!g_bGameStarted)
    301.     {
    302.         // Force All player to be Humans if Game not started yet
    303.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
    304.     }
    305.     else
    306.     {
    307.         if ((floatround(g_flReferenceTime2)+get_pcvar_num(g_pCvarFreezeTime)) > floatround(get_gametime())+2)
    308.         {
    309.             // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
    310.             Set_User_Human(id)
    311.             g_bIsZombieFrozen[id] = false
    312.         }
    313.         else
    314.         {
    315.             if (g_bZombieFreezeTime)
    316.             {
    317.                 // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
    318.                 Set_User_Zombie(id)
    319.                 g_bIsZombieFrozen[id] = true
    320.                 set_entvar(id, var_maxspeed, 1.0)
    321.             }
    322.             else
    323.             {
    324.                 // Respawn him as normal zombie
    325.                 Set_User_Zombie(id)
    326.                 g_bIsZombieFrozen[id] = false
    327.             }
    328.         }
    329.     }
    330. }
    331.  
    332. public New_Round()
    333. {
    334.     g_flReferenceTime2 = get_gametime()
    335.    
    336.     // Remove All tasks in the New Round
    337.     remove_task(TASK_COUNTDOWN)
    338.     remove_task(TASK_COUNTDOWN2)
    339.     remove_task(TASK_SCORE_MESSAGE)
    340.     remove_task(ZOMBIES_SPEED)
    341.     remove_task(CHOOSED_TASK_ID)
    342.    
    343.     if (g_bGameStarted)
    344.     {
    345.         g_iRoundNum++
    346.     }
    347.    
    348.     ExecuteForward(g_iForwards[FORWARD_GAME_STARTED_PRE], g_iFwReturn)
    349.    
    350.     if (g_iFwReturn >= ZE_STOP)
    351.         return
    352.    
    353.     // Score Message Task
    354.     set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
    355.    
    356.     if (!g_bGameStarted)
    357.     {
    358.         // No Enough Players
    359.         ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
    360.         return // Block the execution of the blew code
    361.     }
    362.    
    363.     if (g_iRoundNum == 1)
    364.     {
    365.         // 2 is Hardcoded Value, It's Fix for the countdown to work correctly first round
    366.         g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
    367.     }
    368.     else
    369.     {
    370.         // 3 is Hardcoded Value, It's Fix for the countdown to work correctly after first round
    371.         g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 3
    372.     }
    373.    
    374.     // Game Already started, Countdown now started
    375.     set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
    376.     ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
    377.     ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
    378.    
    379.     // Round Starting
    380.     g_bIsRoundEnding = false
    381.     g_bEndCalled = false
    382.     g_bZombieChosen = false
    383.    
    384.     set_task(get_pcvar_float(g_pCvarFreezeTime)+1.0, "Choosed", CHOOSED_TASK_ID)
    385. }
    386.  
    387. public Choosed()
    388. {
    389.     g_bZombieChosen = true
    390. }
    391.  
    392. // Score Message Task
    393. public Score_Message(TaskID)
    394. {
    395.     // If value is 0, there is nothing to do for this case this means CVAR is disabled
    396.     switch(get_pcvar_num(g_pCvarScoreMessageType))
    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 (+Stop sounds)
    414.     if (!g_bGameStarted)
    415.     {
    416.         StopSound()
    417.         remove_task(TaskID) // Remove the task
    418.         return
    419.     }
    420.    
    421.     if (!g_iCountDown)
    422.     {
    423.         Choose_Zombies()
    424.         remove_task(TaskID) // Remove the task
    425.         return // Block the execution of the blew code
    426.     }
    427.    
    428.     set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
    429.     show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown--)
    430. }
    431.  
    432. public Choose_Zombies()
    433. {
    434.     new iZombies, id, iAliveCount
    435.     new iReqZombies
    436.    
    437.     // Get total alive players and required players
    438.     iAliveCount  = GetAllAlivePlayersNum()
    439.     iReqZombies = RequiredZombies()
    440.    
    441.     // Loop till we find req players
    442.     while(iZombies < iReqZombies)
    443.     {
    444.         id = GetRandomAlive(random_num(1, iAliveCount))
    445.        
    446.         if (!is_user_alive(id) || g_bIsZombie[id])
    447.             continue
    448.        
    449.         // Check if CVAR enabled and if player in the array, it means he chosen previous round so skip him this round
    450.         if (get_pcvar_num(g_pCvarSmartRandom) && IsPlayerInArray(g_aChosenPlayers, id))
    451.             continue
    452.  
    453.         Set_User_Zombie(id)
    454.         set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
    455.         g_bIsZombieFrozen[id] = true
    456.         set_entvar(id, var_maxspeed, 1.0)
    457.         iZombies++
    458.        
    459.         // Respawn Zombies to base
    460.         rg_round_respawn(id)
    461.     }
    462.    
    463.     if (iZombies > 0)
    464.     {
    465.         g_bZombieFreezeTime = true
    466.         set_task(0.1, "Zombies_Speed", ZOMBIES_SPEED, _, _, "b") // Better than PreThink
    467.         ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
    468.     }
    469.    
    470.     if (get_pcvar_num(g_pCvarSmartRandom))
    471.     {
    472.         // Clear the array first
    473.         ArrayClear(g_aChosenPlayers)
    474.        
    475.         new szAuthId[34]
    476.        
    477.         // Add steamid of chosen zombies, so we don't choose them next round again (using steamid means it support reconnect)
    478.         for (new id = 1; id <= g_iMaxClients; id++)
    479.         {
    480.             if(!is_user_connected(id) || !g_bIsZombie[id])
    481.                 continue
    482.            
    483.             get_user_authid(id, szAuthId, charsmax(szAuthId))
    484.            
    485.             ArrayPushString(g_aChosenPlayers, szAuthId)
    486.         }
    487.     }
    488.    
    489.     // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    490.     g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
    491.    
    492.     set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
    493. }
    494.  
    495. public ReleaseZombie_CountDown(TaskID)
    496. {
    497.     if (!g_iCountDown)
    498.     {
    499.         ReleaseZombie()
    500.         remove_task(TaskID)
    501.         return
    502.     }
    503.    
    504.     // Release Hud Message
    505.     set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
    506.     ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown--)
    507. }
    508.  
    509. public ReleaseZombie()
    510. {
    511.     ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
    512.    
    513.     g_bZombieFreezeTime = false
    514.    
    515.     for(new id = 1; id <= g_iMaxClients; id++)
    516.     {
    517.         if (is_user_alive(id) && g_bIsZombie[id])
    518.         {
    519.             g_bIsZombieFrozen[id] = false
    520.         }
    521.     }
    522. }
    523.  
    524. public Zombies_Speed(TaskID)
    525. {
    526.     for(new id = 1; id <= g_iMaxClients; id++)
    527.     {
    528.         if(!is_user_alive(id) || !g_bIsZombie[id])
    529.             continue
    530.        
    531.         if (g_bIsZombieFrozen[id])
    532.         {
    533.             // Zombie & Frozen, then Freeze him
    534.             set_entvar(id, var_maxspeed, 1.0)
    535.         }
    536.         else
    537.         {
    538.             if (g_bZSpeedUsed[id])
    539.             {
    540.                 // Zombie but Not Frozen the set his speed form .cfg
    541.                 set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
    542.                 continue;
    543.             }
    544.                
    545.             // Zombie but Not Frozen the set his speed form .cfg
    546.             set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
    547.         }
    548.     }
    549. }
    550.  
    551. public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
    552. {
    553.     if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
    554.         return HC_CONTINUE
    555.    
    556.     // Attacker and Victim is in same teams? Skip code blew
    557.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
    558.         return HC_CONTINUE
    559.    
    560.     // In freeze time? Skip all other plugins (Skip the real trace attack event)
    561.     if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
    562.         return HC_SUPERCEDE
    563.    
    564.     if (g_bIsZombie[iAttacker])
    565.     {
    566.         g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    567.        
    568.         if (!Set_User_Zombie(iVictim, iAttacker, flDamage))
    569.             return HC_SUPERCEDE
    570.        
    571.         if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
    572.         {
    573.             // End round event called one time
    574.             g_bEndCalled = true
    575.            
    576.             // Round is Ending
    577.             g_bIsRoundEnding = true
    578.            
    579.             // Zombie Win, Leave text blank so we use ours from ML
    580.             rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
    581.            
    582.             // Show Our Message
    583.             client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    584.            
    585.             // Excecute round end forward
    586.             ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, ZE_TEAM_ZOMBIE)
    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.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    618.    
    619.     if ((g_iAliveZombiesNum == 0 && g_bGameStarted) || (g_bDisconnectHumanWin))
    620.     {
    621.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, ZE_TEAM_HUMAN)
    622.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
    623.         g_iHumansScore++
    624.         g_bIsRoundEnding = true
    625.         g_bDisconnectHumanWin = false
    626.         return // To block Execute the code blew
    627.     }
    628.    
    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, ZE_TEAM_ZOMBIE)
    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 >= ZE_STOP)
    689.         return
    690.    
    691.     // Delay Then Check Players to Terminate The round (Delay needed)
    692.     set_task(0.1, "Check_AlivePlayers")
    693. }
    694.  
    695. // This check done when player disconnect
    696. public Check_AlivePlayers()
    697. {
    698.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    699.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    700.    
    701.     // Game Started? (There is at least 2 players Alive?)
    702.     if (g_bGameStarted)
    703.     {
    704.         // We are in freeze time?
    705.         if (get_member_game(m_bFreezePeriod))
    706.         {
    707.             // Humans alive number = 1 and no zombies?
    708.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
    709.             {
    710.                 // Game started false again
    711.                 g_bGameStarted = false
    712.             }
    713.         }
    714.         else // Not freeze time?
    715.         {
    716.             // Variables
    717.             new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
    718.             iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
    719.             iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
    720.             iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
    721.    
    722.             // Alive humans number = 1 and no zombies at all, And no dead humans?
    723.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
    724.             {
    725.                 // Game started is false and humans wins (Escape Success)
    726.                 g_bGameStarted = false
    727.                 g_bDisconnectHumanWin = true
    728.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
    729.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
    730.             }
    731.            
    732.             // Alive zombies number = 1 and no humans at all, And no dead zombies?
    733.             if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
    734.             {
    735.                 // Game started is false and zombies wins (Escape Fail)
    736.                 g_bGameStarted = false
    737.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
    738.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    739.             }
    740.            
    741.             // Humans number more than 1 and no zombies?
    742.             if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding && g_bZombieChosen)
    743.             {
    744.                 // Then Escape success as there is no Zombies
    745.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
    746.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
    747.             }
    748.            
    749.             // Zombies number more than 1 and no humans?
    750.             if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
    751.             {
    752.                 // Then Escape Fail as there is no humans
    753.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
    754.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    755.             }
    756.         }
    757.     }
    758. }
    759.  
    760. public client_putinserver(id)
    761. {
    762.     // Add Delay and Check Conditions To start the Game (Delay needed)
    763.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
    764.    
    765.     // Check for dead terrorists - Bug fix
    766.     set_task(0.1, "CheckTerrorists", id, _, _, "b")
    767. }
    768.  
    769. public CheckTerrorists(id)
    770. {
    771.     if (g_bEnteredNotChoosed[id] && g_bGameStarted)
    772.     {
    773.         if (is_user_connected(id))
    774.         {
    775.             rg_join_team(id, TEAM_CT) // Force user to choose CT
    776.             g_bEnteredNotChoosed[id] = false
    777.         }
    778.     }
    779. }
    780.  
    781. public Fw_HandleMenu_ChoosedAppearance_Post(const index, const slot)
    782. {
    783.     g_bEnteredNotChoosed[index] = false
    784. }
    785.  
    786. public Fw_HandleMenu_ChooseTeam_Post(id, MenuChooseTeam:iSlot)
    787. {
    788.     // Fixing Dead-T restarting the round
    789.     if (iSlot == MenuChoose_T) // Choosed T, Still not choosed a player
    790.     {
    791.         g_bEnteredNotChoosed[id] = true
    792.     }
    793.    
    794.     if ((iSlot == MenuChoose_AutoSelect) && (get_member(id, m_iTeam) == TEAM_TERRORIST))
    795.     {
    796.         g_bEnteredNotChoosed[id] = true
    797.     }
    798.    
    799.     // Add Delay and Check Conditions To start the Game (Delay needed)
    800.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
    801. }
    802.  
    803. public Check_AllPlayersNumber(TaskID)
    804. {
    805.     if (g_bGameStarted)
    806.     {
    807.         // If game started remove the task and block the blew Checks
    808.         remove_task(TaskID)
    809.         return
    810.     }
    811.    
    812.     if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
    813.     {
    814.         // Players In server == The Required so game started is true
    815.         g_bGameStarted = true
    816.        
    817.         // Restart the game
    818.         server_cmd("sv_restart 2")
    819.        
    820.         // Print Fake game Commencing Message
    821.         client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
    822.        
    823.         // Remove the task
    824.         remove_task(TaskID)
    825.     }
    826. }
    827.  
    828. Set_User_Human(id)
    829. {
    830.     if (!is_user_alive(id))
    831.         return
    832.    
    833.     g_bIsZombie[id] = false
    834.     set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
    835.     set_entvar(id, var_gravity, float(g_bIsGravityUsed[id] ? g_iUserGravity[id]:get_pcvar_num(g_pCvarHumanGravity))/800.0)
    836.     ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
    837.    
    838.     // Reset Nightvision (Useful for antidote, so when someone use sethuman native the nightvision also reset)
    839.     Set_NightVision(id, 0, 0, 0x0000, 0, 0, 0, 0)
    840.    
    841.     if (get_member(id, m_iTeam) != TEAM_CT)
    842.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
    843. }
    844.  
    845. Set_User_Zombie(id, iAttacker = 0, Float:flDamage = 0.0)
    846. {
    847.     if (!is_user_alive(id))
    848.         return false
    849.        
    850.     // Execute pre-infection forward
    851.     ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, id, iAttacker, floatround(flDamage))
    852.    
    853.     if (g_iFwReturn >= ZE_STOP)
    854.     {
    855.         return false
    856.     }
    857.    
    858.     if (iAttacker > 0)
    859.     {
    860.         // Death Message with Infection style, only if infection caused by player not server
    861.         SendDeathMsg(iAttacker, id)
    862.     }
    863.    
    864.     g_bIsZombie[id] = true
    865.     set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
    866.     set_entvar(id, var_gravity, float(g_bIsGravityUsed[id] ? g_iUserGravity[id] : get_pcvar_num(g_pCvarZombieGravity))/800.0)
    867.     rg_remove_all_items(id)
    868.     rg_give_item(id, "weapon_knife", GT_APPEND)
    869.     ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
    870.    
    871.     if (get_member(id, m_iTeam) != TEAM_TERRORIST)
    872.         rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
    873.    
    874.     return true
    875. }
    876.  
    877. public Map_Restart()
    878. {
    879.     // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
    880.     set_task(0.1, "Reset_Score_Message")
    881. }
    882.  
    883. public Reset_Score_Message()
    884. {
    885.     g_iHumansScore = 0
    886.     g_iZombiesScore = 0
    887.     g_iRoundNum = 0
    888. }
    889.  
    890. public plugin_end()
    891. {
    892.     if (get_pcvar_num(g_pCvarSmartRandom))
    893.     {
    894.         ArrayDestroy(g_aChosenPlayers)
    895.     }
    896. }
    897.  
    898. public Message_Teamscore()
    899. {
    900.     new szTeam[2]
    901.     get_msg_arg_string(1, szTeam, charsmax(szTeam))
    902.    
    903.     switch (szTeam[0])
    904.     {
    905.         case 'C': set_msg_arg_int(2, get_msg_argtype(2), g_iHumansScore)
    906.         case 'T': set_msg_arg_int(2, get_msg_argtype(2), g_iZombiesScore)
    907.     }
    908. }
    909.  
    910. // Natives
    911. public native_ze_is_user_zombie(id)
    912. {
    913.     if (!is_user_connected(id))
    914.     {
    915.         return -1;
    916.     }
    917.    
    918.     return g_bIsZombie[id]
    919. }
    920.  
    921. public native_ze_set_user_zombie(id)
    922. {
    923.     if (!is_user_connected(id))
    924.     {
    925.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    926.         return false;
    927.     }
    928.    
    929.     Set_User_Zombie(id)
    930.     return true;
    931. }
    932.  
    933. public native_ze_set_user_human(id)
    934. {
    935.     if (!is_user_connected(id))
    936.     {
    937.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    938.         return false;
    939.     }
    940.    
    941.     Set_User_Human(id)
    942.     return true;
    943. }
    944.  
    945. public native_ze_is_game_started()
    946. {
    947.     return g_bGameStarted
    948. }
    949.  
    950. public native_ze_is_zombie_frozen(id)
    951. {
    952.     if (!is_user_connected(id) || !g_bIsZombie[id])
    953.     {
    954.         return -1;
    955.     }
    956.    
    957.     return g_bIsZombieFrozen[id]
    958. }
    959.  
    960. public native_ze_get_round_number()
    961. {
    962.     if (!g_bGameStarted)
    963.     {
    964.         return -1;
    965.     }
    966.    
    967.     return g_iRoundNum
    968. }
    969.  
    970. public native_ze_get_humans_number()
    971. {
    972.     return GetAlivePlayersNum(CsTeams:TEAM_CT)
    973. }
    974.  
    975. public native_ze_get_zombies_number()
    976. {
    977.     return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    978. }
    979.  
    980. public native_ze_set_human_speed_factor(id, iFactor)
    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] = true
    989.     g_iHSpeedFactor[id] = iFactor
    990.     rg_reset_maxspeed(id)
    991.     return true;
    992. }
    993.  
    994. public native_ze_reset_human_speed(id)
    995. {
    996.     if (!is_user_connected(id))
    997.     {
    998.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    999.         return false;
    1000.     }
    1001.    
    1002.     g_bHSpeedUsed[id] = false
    1003.     rg_reset_maxspeed(id)
    1004.     return true;
    1005. }
    1006.  
    1007. public native_ze_set_zombie_speed(id, iSpeed)
    1008. {
    1009.     if (!is_user_connected(id))
    1010.     {
    1011.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    1012.         return false;
    1013.     }
    1014.    
    1015.     g_bZSpeedUsed[id] = true
    1016.     g_iZSpeedSet[id] = iSpeed
    1017.     return true;
    1018. }
    1019.  
    1020. public native_ze_reset_zombie_speed(id)
    1021. {
    1022.     if (!is_user_connected(id))
    1023.     {
    1024.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    1025.         return false;
    1026.     }
    1027.    
    1028.     g_bZSpeedUsed[id] = false
    1029.     return true;
    1030. }
    1031.  
    1032. public native_ze_get_user_knockback(id)
    1033. {
    1034.     if (!is_user_connected(id))
    1035.     {
    1036.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    1037.         return -1
    1038.     }
    1039.  
    1040.     return floatround(g_bIsKnockBackUsed[id] ? g_flUserKnockback[id]:get_pcvar_float(g_pCvarZombieKnockback))
    1041. }
    1042.  
    1043. public native_ze_set_user_knockback(id, Float:flKnockback)
    1044. {
    1045.     if (!is_user_connected(id))
    1046.     {
    1047.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    1048.         return false
    1049.     }
    1050.    
    1051.     g_bIsKnockBackUsed[id] = true
    1052.     g_flUserKnockback[id] = flKnockback
    1053.     return true
    1054. }
    1055.  
    1056. public native_ze_reset_user_knockback(id)
    1057. {
    1058.     if (!is_user_connected(id))
    1059.     {
    1060.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    1061.         return false
    1062.     }
    1063.  
    1064.     g_bIsKnockBackUsed[id] = false
    1065.     g_flUserKnockback[id] = 0.0
    1066.     return true
    1067. }
    1068.  
    1069. public native_ze_set_user_gravity(id, iGravity)
    1070. {
    1071.     if (!is_user_connected(id))
    1072.     {
    1073.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    1074.         return false
    1075.     }
    1076.    
    1077.     g_bIsGravityUsed[id] = true
    1078.     g_iUserGravity[id] = iGravity
    1079.     set_entvar(id, var_gravity, float(iGravity) / 800.0)
    1080.  
    1081.     return true
    1082. }
    1083.  
    1084. public native_ze_reset_user_gravity(id)
    1085. {
    1086.     if (!is_user_connected(id))
    1087.     {
    1088.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    1089.         return false
    1090.     }
    1091.  
    1092.     g_bIsGravityUsed[id] = false
    1093.     set_entvar(id, var_gravity, float(g_bIsZombie[id] ? get_pcvar_num(g_pCvarZombieGravity):get_pcvar_num(g_pCvarHumanGravity)) / 800.0)
    1094.  
    1095.     return true
    1096. }
    1097.  
    1098. public native_ze_remove_zombie_freeze_msg()
    1099. {
    1100.     if (task_exists(TASK_COUNTDOWN2))
    1101.     {
    1102.         remove_task(TASK_COUNTDOWN2)
    1103.         return true
    1104.     }
    1105.    
    1106.     return false
    1107. }
Also ze_countdown.sma edited:
    1. #include <zombie_escape>
    2.  
    3. // Setting File
    4. new const ZE_SETTING_RESOURCES[] = "zombie_escape.ini"
    5.  
    6. // Defines
    7. #define SOUND_MAX_LENGTH 64
    8. #define TASK_COUNTDOWN 2010
    9.  
    10. // Default Countdown Sounds
    11. new const szCountDownSound[][] =
    12. {
    13.     "zombie_escape/1.wav",
    14.     "zombie_escape/2.wav",
    15.     "zombie_escape/3.wav",
    16.     "zombie_escape/4.wav",
    17.     "zombie_escape/5.wav",
    18.     "zombie_escape/6.wav",
    19.     "zombie_escape/7.wav",
    20.     "zombie_escape/8.wav",
    21.     "zombie_escape/9.wav",
    22.     "zombie_escape/10.wav"
    23. }
    24.  
    25. // Dynamic Arrays
    26. new Array:g_szCountDownSound
    27.  
    28. // Variables
    29. new g_iCountDown
    30.  
    31. // CVARs
    32. new g_pCvarFreezeTime
    33.  
    34. public plugin_precache()
    35. {
    36.     // Initialize arrays
    37.     g_szCountDownSound = ArrayCreate(SOUND_MAX_LENGTH, 1)
    38.    
    39.     // Load from external file
    40.     amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Sounds", "COUNT DOWN", g_szCountDownSound)
    41.    
    42.     // If we couldn't load custom sounds from file, use and save default ones
    43.     new iIndex
    44.    
    45.     if (ArraySize(g_szCountDownSound) == 0)
    46.     {
    47.         for (iIndex = 0; iIndex < sizeof szCountDownSound; iIndex++)
    48.         {
    49.             // Get Defaults Sounds and Store them in the Array
    50.             ArrayPushString(g_szCountDownSound, szCountDownSound[iIndex])
    51.         }
    52.        
    53.         // Save values stored in Array to External file
    54.         amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Sounds", "COUNT DOWN", g_szCountDownSound)
    55.     }
    56.    
    57.     // Precache sounds stored in the Array
    58.     new szSound[SOUND_MAX_LENGTH]
    59.    
    60.     for (iIndex = 0; iIndex < ArraySize(g_szCountDownSound); iIndex++)
    61.     {
    62.         ArrayGetString(g_szCountDownSound, iIndex, szSound, charsmax(szSound))
    63.         precache_sound(szSound)
    64.     }
    65. }
    66.  
    67. public plugin_init()
    68. {
    69.     register_plugin("[ZE] Sound Countdown", ZE_VERSION, AUTHORS)
    70.    
    71.     // Map restart event
    72.     register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
    73.  
    74.         g_pCvarFreezeTime = get_cvar_pointer("ze_freeze_time")
    75. }
    76.  
    77. public ze_game_started()
    78. {
    79.     if (ze_get_round_number() == 1)
    80.     {
    81.         // 2 is Hardcoded Value, It's Fix for the countdown to work correctly first round
    82.         g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
    83.     }
    84.     else
    85.     {
    86.         // 3 is Hardcoded Value, It's Fix for the countdown to work correctly after first round
    87.         g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 3
    88.     }
    89.    
    90.     set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
    91. }
    92.  
    93. public Countdown_Start()
    94. {
    95.     if ((g_iCountDown - 1 < 0) || !ze_is_game_started())
    96.     {
    97.         remove_task(TASK_COUNTDOWN) // Remove the task
    98.         return // Block the execution of the blew code
    99.     }
    100.    
    101.     // Start the count down when remains 10 seconds
    102.     if (g_iCountDown <= 10)
    103.     {
    104.         static szSound[SOUND_MAX_LENGTH]
    105.         ArrayGetString(g_szCountDownSound, g_iCountDown - 1, szSound, charsmax(szSound))
    106.         PlaySound(0, szSound)
    107.     }
    108.    
    109.     g_iCountDown--
    110. }
    111.  
    112. public ze_roundend(WinTeam)
    113. {
    114.     // At round end, remove countdown task to block interference next round
    115.     remove_task(TASK_COUNTDOWN)
    116. }
    117.  
    118. public Map_Restart()
    119. {
    120.     // At map restart, remove countdown task to block interference next rounds
    121.     remove_task(TASK_COUNTDOWN)
    122. }
NOTE: Make sure also to use ze_release_time 2
He who fails to plan is planning to fail

ngamerz
Member
Member
Philippines
Posts: 37
Joined: 3 years ago
Location: Philippines From South Korea

#15

Post by ngamerz » 3 years ago

Please fix that code, when you get infected the infector doesn't get frags.

I'm talking about ze_core.

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 2 guests