Zombie selection

Unpaid Requests, Public Plugins
Post Reply
User avatar
DarkZombie
Member
Member
Hungary
Posts: 76
Joined: 5 years ago
Contact:

Zombie selection

#1

Post by DarkZombie » 5 years ago

When the game starts, there are several times that the same players will be zombies, can this somehow be modified to not always be the same?
Or is not that simple?

User avatar
Night Fury
Mod Developer
Mod Developer
Posts: 677
Joined: 7 years ago
Contact:

#2

Post by Night Fury » 5 years ago

It chooses randomly among all alive players.
Want your own mod edition? PM me.
Accepting private projects.
Discord: Fury#7469
Image

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

#3

Post by Raheem » 5 years ago

We can make idea, if this user chosen the previous round and there is another enough users, so we can choose from them randomly and exclude this player from random process.

I'll find time to implement this and post to you to test.
He who fails to plan is planning to fail

User avatar
DarkZombie
Member
Member
Hungary
Posts: 76
Joined: 5 years ago
Contact:

#4

Post by DarkZombie » 5 years ago

Raheem wrote: 5 years ago We can make idea, if this user chosen the previous round and there is another enough users, so we can choose from them randomly and exclude this player from random process.

I'll find time to implement this and post to you to test.
Okay, thank you very much , Raheem.

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

#5

Post by Raheem » 5 years ago

Here it's, now i store the chosen players steamid so they not chosen again next round.
I use steamid this mean this supports player reconnect. So if player chosen previous round and disconnected before new round and connected again but still zombies not chosen he will not be chosen.

Confirm that this work and it will be added officially to our Mod.

Here is ze_core.sma test it:

  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
  14. }
  15.  
  16. new g_iForwards[TOTAL_FORWARDS], g_iFwReturn, g_iTeam
  17.  
  18. // Tasks IDs
  19. enum
  20. {
  21.     TASK_COUNTDOWN = 1100,
  22.     TASK_COUNTDOWN2,
  23.     TASK_SCORE_MESSAGE,
  24.     FREEZE_ZOMBIES,
  25.     ROUND_TIME_LEFT
  26. }
  27.  
  28. // Colors (g_pCvarColors[] array indexes)
  29. enum
  30. {
  31.     Red = 0,
  32.     Green,
  33.     Blue
  34. }
  35.  
  36. // Variables
  37. new g_iAliveHumansNum,
  38.     g_iAliveZombiesNum,
  39.     g_iRoundTime,
  40.     g_iCountDown,
  41.     g_iReleaseNotice,
  42.     g_iMaxClients,
  43.     g_iHumansScore,
  44.     g_iZombiesScore,
  45.     g_iRoundNum,
  46.     g_iHSpeedFactor[33],
  47.     g_iZSpeedSet[33],
  48.     bool:g_bGameStarted,
  49.     bool:g_bIsZombie[33],
  50.     bool:g_bIsZombieFrozen[33],
  51.     bool:g_bZombieFreezeTime,
  52.     bool:g_bIsRoundEnding,
  53.     bool:g_bHSpeedUsed[33],
  54.     bool:g_bZSpeedUsed[33],
  55.     bool:g_bEndCalled,
  56.     Float:g_flReferenceTime
  57.  
  58. // Cvars
  59. new g_pCvarHumanSpeedFactor,
  60.     g_pCvarHumanGravity,
  61.     g_pCvarHumanHealth,
  62.     g_pCvarZombieSpeed,
  63.     g_pCvarZombieGravity,
  64.     g_pCvarZombieReleaseTime,
  65.     g_pCvarFreezeTime,
  66.     g_pCvarRoundTime,
  67.     g_pCvarReqPlayers,
  68.     g_pCvarZombieHealth,
  69.     g_pCvarFirstZombiesHealth,
  70.     g_pCvarZombieKnockback,
  71.     g_pCvarScoreMessageType,
  72.     g_pCvarColors[3],
  73.     g_pCvarRoundEndDelay
  74.    
  75. // Dynamic
  76. new Array:g_aChosenPlayers
  77.  
  78. public plugin_natives()
  79. {
  80.     register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
  81.     register_native("ze_is_game_started", "native_ze_is_game_started", 1)
  82.     register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
  83.    
  84.     register_native("ze_get_round_number", "native_ze_get_round_number", 1)
  85.     register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
  86.     register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
  87.    
  88.     register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
  89.     register_native("ze_set_user_human", "native_ze_set_user_human", 1)
  90.     register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
  91.     register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
  92.    
  93.     register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
  94.     register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
  95. }
  96.  
  97. public plugin_init()
  98. {
  99.     register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
  100.    
  101.     // Hook Chains
  102.     RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
  103.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
  104.     RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
  105.     RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
  106.     RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
  107.     RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
  108.    
  109.     // Events
  110.     register_event("HLTV", "New_Round", "a", "1=0", "2=0")
  111.     register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
  112.     register_logevent("Round_Start", 2, "1=Round_Start")
  113.     register_logevent("Round_End", 2, "1=Round_End")
  114.    
  115.     // Hams
  116.     RegisterHam(Ham_Item_PreFrame, "player", "Fw_RestMaxSpeed_Post", 1)
  117.    
  118.     // Create Forwards (All Return Values Ignored)
  119.     g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
  120.     g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
  121.     g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
  122.     g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
  123.     g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
  124.     g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
  125.     g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
  126.    
  127.     // Hud Messages
  128.     g_iReleaseNotice = CreateHudSyncObj()
  129.    
  130.     // Sequential files (.txt)
  131.     register_dictionary("zombie_escape.txt")
  132.    
  133.     // Humans Cvars
  134.     g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
  135.     g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
  136.     g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
  137.    
  138.     // Zombie Cvars
  139.     g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
  140.     g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
  141.     g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
  142.     g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
  143.     g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
  144.    
  145.     // General Cvars
  146.     g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
  147.     g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
  148.     g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
  149.     g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
  150.     g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
  151.     g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
  152.     g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
  153.     g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
  154.     g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
  155.    
  156.     // Default Values
  157.     g_bGameStarted = false
  158.    
  159.     // Static Values
  160.     g_iMaxClients = get_member_game(m_nMaxPlayers)
  161.    
  162.     // Check Round Time to Terminate it
  163.     set_task(1.0, "Check_RoundTimeleft", ROUND_TIME_LEFT, _, _, "b")
  164.    
  165.     // Create our array to store SteamIDs in
  166.     g_aChosenPlayers = ArrayCreate(34)
  167. }
  168.  
  169. public plugin_cfg()
  170. {
  171.     // Get our configiration file and Execute it
  172.     new szCfgDir[64]
  173.     get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir))
  174.     server_cmd("exec %s/zombie_escape.cfg", szCfgDir)
  175.    
  176.     // Set Game Name
  177.     new szGameName[64]
  178.     formatex(szGameName, sizeof(szGameName), "Zombie Escape v%s", ZE_VERSION)
  179.     set_member_game(m_GameDesc, szGameName)
  180.    
  181.     // Set Version
  182.     register_cvar("ze_version", ZE_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
  183.     set_cvar_string("ze_version", ZE_VERSION)
  184. }
  185.  
  186. public Fw_CheckMapConditions_Post()
  187. {
  188.     // Block Game Commencing
  189.     set_member_game(m_bGameStarted, true)
  190.    
  191.     // Set Freeze Time
  192.     set_member_game(m_iIntroRoundTime, get_pcvar_num(g_pCvarFreezeTime))
  193.    
  194.     // Set Round Time
  195.     set_member_game(m_iRoundTime, floatround(get_pcvar_float(g_pCvarRoundTime) * 60.0))
  196. }
  197.  
  198. public Fw_PlayerKilled_Post(id)
  199. {
  200.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  201.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  202.    
  203.     if (g_iAliveHumansNum == 0 && g_iAliveZombiesNum == 0)
  204.     {
  205.         // No Winner, All Players in one team killed Or Both teams Killed
  206.         client_print(0, print_center, "%L", LANG_PLAYER, "NO_WINNER")
  207.     }
  208. }
  209.  
  210. public Fw_RestMaxSpeed_Post(id)
  211. {
  212.     if (!g_bIsZombie[id])
  213.     {
  214.         static Float:flMaxSpeed
  215.         get_entvar(id, var_maxspeed, flMaxSpeed)
  216.        
  217.         if (flMaxSpeed != 1.0 && is_user_alive(id))
  218.         {
  219.             if (g_bHSpeedUsed[id])
  220.             {
  221.                 // Set New Human Speed Factor
  222.                 set_entvar(id, var_maxspeed, flMaxSpeed + float(g_iHSpeedFactor[id]))
  223.                 return HAM_IGNORED
  224.             }
  225.                
  226.             // Set Human Speed Factor, native not used
  227.             set_entvar(id, var_maxspeed, flMaxSpeed + get_pcvar_float(g_pCvarHumanSpeedFactor))
  228.             return HAM_IGNORED
  229.         }
  230.     }
  231.    
  232.     return HAM_SUPERCEDE
  233. }
  234.  
  235. public Fw_PlayerSpawn_Post(id)
  236. {  
  237.     if (!g_bGameStarted)
  238.     {
  239.         // Force All player to be Humans if Game not started yet
  240.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
  241.     }
  242.     else
  243.     {
  244.         if (get_member_game(m_bFreezePeriod))
  245.         {
  246.             // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
  247.             Set_User_Human(id)
  248.             g_bIsZombieFrozen[id] = false
  249.         }
  250.         else
  251.         {
  252.             if (g_bZombieFreezeTime)
  253.             {
  254.                 // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
  255.                 Set_User_Zombie(id)
  256.                 g_bIsZombieFrozen[id] = true
  257.                 set_entvar(id, var_maxspeed, 1.0)
  258.             }
  259.             else
  260.             {
  261.                 // Respawn him as normal zombie
  262.                 Set_User_Zombie(id)
  263.                 g_bIsZombieFrozen[id] = false
  264.             }
  265.         }
  266.     }
  267. }
  268.  
  269. public New_Round()
  270. {
  271.     // Remove All tasks in the New Round
  272.     remove_task(TASK_COUNTDOWN)
  273.     remove_task(TASK_COUNTDOWN2)
  274.     remove_task(TASK_SCORE_MESSAGE)
  275.     remove_task(FREEZE_ZOMBIES)
  276.    
  277.     // Score Message Task
  278.     set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
  279.    
  280.     // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
  281.     g_iCountDown = get_member_game(m_iIntroRoundTime) - 2
  282.    
  283.     if (!g_bGameStarted)
  284.     {
  285.         // No Enough Players
  286.         ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
  287.         return // Block the execution of the blew code
  288.     }
  289.    
  290.     // Game Already started, Countdown now started
  291.     set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
  292.     ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
  293.     ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
  294.    
  295.     g_iRoundNum++
  296.    
  297.     // Round Starting
  298.     g_bIsRoundEnding = false
  299.     g_bEndCalled = false
  300. }
  301.  
  302. // Score Message Task
  303. public Score_Message(TaskID)
  304. {
  305.     switch(get_pcvar_num(g_pCvarScoreMessageType))
  306.     {
  307.         case 0: // Disabled
  308.         {
  309.             return
  310.         }
  311.         case 1: // DHUD
  312.         {
  313.             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)
  314.             show_dhudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
  315.         }
  316.         case 2: // HUD
  317.         {
  318.             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)
  319.             show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
  320.         }
  321.     }
  322. }
  323.  
  324. public Countdown_Start(TaskID)
  325. {
  326.     // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
  327.     if (!g_bGameStarted)
  328.         return
  329.    
  330.     if (!g_iCountDown)
  331.     {
  332.         Choose_Zombies()
  333.         remove_task(TASK_COUNTDOWN) // Remove the task
  334.         return // Block the execution of the blew code
  335.     }
  336.    
  337.     set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
  338.     show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
  339.  
  340.     g_iCountDown--
  341. }
  342.  
  343. public Choose_Zombies()
  344. {
  345.     new iZombies, id, iAliveCount
  346.     new iReqZombies
  347.    
  348.     // Get total alive players and required players
  349.     iAliveCount  = GetAllAlivePlayersNum()
  350.     iReqZombies = RequiredZombies()
  351.    
  352.     // Loop till we find req players
  353.     while(iZombies < iReqZombies)
  354.     {
  355.         id = GetRandomAlive(random_num(1, iAliveCount))
  356.        
  357.         // If player in array (Players steamid), it means he has chosen the previous round so skip him
  358.         if (!is_user_alive(id) || g_bIsZombie[id] || PlayerInArray(id))
  359.             continue
  360.  
  361.         Set_User_Zombie(id)
  362.         set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
  363.         g_bIsZombieFrozen[id] = true
  364.         g_bZombieFreezeTime = true
  365.         set_entvar(id, var_maxspeed, 1.0)
  366.         set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
  367.         ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
  368.         iZombies++
  369.     }
  370.    
  371.     // After choose, we clear the array
  372.     ArrayClear(g_aChosenPlayers)
  373.    
  374.     // Now we loop through all players and store the chosen zombies steamid so they not chosen the next round again
  375.     // Using steamid will add reconnect support
  376.     for(new id = 1; id <= g_iMaxClients; id++)
  377.     {
  378.         if(!is_user_connected(id) || !g_bIsZombie[id])
  379.             continue
  380.        
  381.         new szAuthId[34];
  382.        
  383.         get_user_authid(id, szAuthId, charsmax(szAuthId));
  384.        
  385.         ArrayPushString(g_aChosenPlayers, szAuthId)
  386.     }
  387.    
  388.     // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
  389.     g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
  390.    
  391.     set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
  392. }
  393.  
  394. public ReleaseZombie_CountDown(TaskID)
  395. {
  396.     if (!g_iCountDown)
  397.     {
  398.         ReleaseZombie()
  399.         remove_task(TASK_COUNTDOWN2)
  400.         return
  401.     }
  402.    
  403.     // Release Hud Message
  404.     set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
  405.     ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
  406.    
  407.     g_iCountDown --
  408. }
  409.  
  410. public ReleaseZombie()
  411. {
  412.     ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
  413.    
  414.     for(new id = 1; id <= g_iMaxClients; id++)
  415.     {
  416.         if (is_user_alive(id) && g_bIsZombie[id])
  417.         {
  418.             g_bIsZombieFrozen[id] = false
  419.             g_bZombieFreezeTime = false
  420.         }
  421.     }
  422. }
  423.  
  424. public Freeze_Zombies(TaskID)
  425. {
  426.     for(new id = 1; id <= g_iMaxClients; id++)
  427.     {
  428.         if(!is_user_alive(id) || !g_bIsZombie[id])
  429.             continue
  430.        
  431.         if (g_bIsZombieFrozen[id])
  432.         {
  433.             // Zombie & Frozen, then Freeze him
  434.             set_entvar(id, var_maxspeed, 1.0)
  435.         }
  436.         else
  437.         {
  438.             if (g_bZSpeedUsed[id])
  439.             {
  440.                 // Zombie but Not Frozen the set his speed form .cfg
  441.                 set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
  442.                 continue;
  443.             }
  444.                
  445.             // Zombie but Not Frozen the set his speed form .cfg
  446.             set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
  447.         }
  448.     }
  449. }
  450.  
  451. public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
  452. {
  453.     if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
  454.         return HC_CONTINUE
  455.    
  456.     // Attacker and Victim is in same teams? Skip code blew
  457.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
  458.         return HC_CONTINUE
  459.    
  460.     // In freeze time? Skip all other plugins (Skip the real trace attack event)
  461.     if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
  462.         return HC_SUPERCEDE
  463.    
  464.     // Execute pre-infection forward
  465.     ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker, floatround(flDamage))
  466.    
  467.     if (g_iFwReturn > 0)
  468.     {
  469.         return HC_SUPERCEDE
  470.     }
  471.    
  472.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  473.    
  474.     if (g_bIsZombie[iAttacker])
  475.     {
  476.         // Death Message with Infection style [Added here because of delay in Forward use]
  477.         SendDeathMsg(iAttacker, iVictim)
  478.        
  479.         Set_User_Zombie(iVictim)
  480.        
  481.         ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
  482.        
  483.         if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
  484.         {
  485.             // End round event called one time
  486.             g_bEndCalled = true
  487.            
  488.             // Round is Ending
  489.             g_bIsRoundEnding = true
  490.            
  491.             // Zombie Win, Leave text blank so we use ours from ML
  492.             rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  493.            
  494.             // Show Our Message
  495.             client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  496.            
  497.             // This needed so forward work also to add +1 for Zombies
  498.             g_iTeam = 1 // ZE_TEAM_ZOMBIE
  499.             ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  500.         }
  501.     }
  502.    
  503.     return HC_CONTINUE
  504. }
  505.  
  506. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
  507. {
  508.     // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
  509.     if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
  510.         return HC_CONTINUE
  511.    
  512.     // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
  513.     if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
  514.     {
  515.         // Remove Shock Pain
  516.         set_member(iVictim, m_flVelocityModifier, 1.0)
  517.        
  518.         // Set Knockback
  519.         static Float:flOrigin[3]
  520.         get_entvar(iAttacker, var_origin, flOrigin)
  521.         Set_Knockback(iVictim, flOrigin, get_pcvar_float(g_pCvarZombieKnockback), 2)
  522.     }
  523.    
  524.     return HC_CONTINUE
  525. }
  526.  
  527. public Round_End()
  528. {
  529.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  530.    
  531.     if (g_iAliveZombiesNum == 0 && g_bGameStarted)
  532.     {
  533.         g_iTeam = 2 // ZE_TEAM_HUMAN
  534.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  535.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  536.         g_iHumansScore++
  537.         g_bIsRoundEnding = true
  538.         return // To block Execute the code blew
  539.     }
  540.    
  541.     g_iTeam = 1 // ZE_TEAM_ZOMBIE
  542.     g_iZombiesScore++
  543.     g_bIsRoundEnding = true
  544.    
  545.     // If it's already called one time, don't call it again
  546.     if (!g_bEndCalled)
  547.     {
  548.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  549.     }
  550.    
  551.     client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  552. }
  553.  
  554. public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
  555. {
  556.     // The two unhandeld cases by rg_round_end() native in our Mod
  557.     if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
  558.     {
  559.         SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
  560.     }
  561. }
  562.  
  563. public Round_Start()
  564. {
  565.     g_flReferenceTime = get_gametime()
  566.     g_iRoundTime = get_member_game(m_iRoundTime)
  567. }
  568.  
  569. public Check_RoundTimeleft()
  570. {
  571.     new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
  572.    
  573.     if (floatround(flRoundTimeLeft) == 0)
  574.     {
  575.         // Round is Ending
  576.         g_bIsRoundEnding = true
  577.        
  578.         // If Time is Out then Terminate the Round
  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. }
  585.  
  586. public client_disconnected(id)
  587. {
  588.     // Delay Then Check Players to Terminate The round (Delay needed)
  589.     set_task(0.1, "Check_AlivePlayers")
  590.    
  591.     // Reset speed for this dropped id
  592.     g_bHSpeedUsed[id] = false
  593.     g_bZSpeedUsed[id] = false
  594. }
  595.  
  596. // This check done when player disconnect
  597. public Check_AlivePlayers()
  598. {
  599.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  600.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  601.    
  602.     // Game Started? (There is at least 2 players Alive?)
  603.     if (g_bGameStarted)
  604.     {
  605.         // We are in freeze time?
  606.         if (get_member_game(m_bFreezePeriod))
  607.         {
  608.             // Humans alive number = 1 and no zombies?
  609.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
  610.             {
  611.                 // Game started false again
  612.                 g_bGameStarted = false
  613.             }
  614.         }
  615.         else // Not freeze time?
  616.         {
  617.             // Variables
  618.             new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
  619.             iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
  620.             iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
  621.             iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
  622.    
  623.             // Alive humans number = 1 and no zombies at all, And no dead humans?
  624.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
  625.             {
  626.                 // Game started is false and humans wins (Escape Success)
  627.                 g_bGameStarted = false
  628.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
  629.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  630.             }
  631.            
  632.             // Alive zombies number = 1 and no humans at all, And no dead zombies?
  633.             if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
  634.             {
  635.                 // Game started is false and zombies wins (Escape Fail)
  636.                 g_bGameStarted = false
  637.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  638.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  639.             }
  640.            
  641.             // Humans number more than 1 and no zombies?
  642.             if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding)
  643.             {
  644.                 // Then Escape success as there is no Zombies
  645.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
  646.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  647.             }
  648.            
  649.             // Zombies number more than 1 and no humans?
  650.             if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
  651.             {
  652.                 // Then Escape Fail as there is no humans
  653.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  654.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  655.             }
  656.         }
  657.     }
  658. }
  659.  
  660. public client_putinserver(id)
  661. {
  662.     // Add Delay and Check Conditions To start the Game (Delay needed)
  663.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
  664. }
  665.  
  666. public Check_AllPlayersNumber(TaskID)
  667. {
  668.     if (g_bGameStarted)
  669.     {
  670.         // If game started remove the task and block the blew Checks
  671.         remove_task(TaskID)
  672.         return
  673.     }
  674.    
  675.     if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
  676.     {
  677.         // Players In server == The Required so game started is true
  678.         g_bGameStarted = true
  679.        
  680.         // Restart the game
  681.         server_cmd("sv_restart 2")
  682.        
  683.         // Print Fake game Commencing Message
  684.         client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
  685.        
  686.         // Remove the task
  687.         remove_task(TaskID)
  688.     }
  689. }
  690.  
  691. public Set_User_Human(id)
  692. {
  693.     if (!is_user_alive(id))
  694.         return
  695.    
  696.     g_bIsZombie[id] = false
  697.     set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
  698.     set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHumanGravity)/800.0)
  699.     ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
  700.    
  701.     if (get_member(id, m_iTeam) != TEAM_CT)
  702.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
  703. }
  704.  
  705. public Set_User_Zombie(id)
  706. {
  707.     if (!is_user_alive(id))
  708.         return
  709.    
  710.     g_bIsZombie[id] = true
  711.     set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
  712.     set_entvar(id, var_gravity, get_pcvar_float(g_pCvarZombieGravity)/800.0)
  713.     rg_remove_all_items(id)
  714.     rg_give_item(id, "weapon_knife", GT_APPEND)
  715.     ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
  716.    
  717.     if (get_member(id, m_iTeam) != TEAM_TERRORIST)
  718.         rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
  719. }
  720.  
  721. public Map_Restart()
  722. {
  723.     // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
  724.     set_task(0.1, "Reset_Score_Message")
  725. }
  726.  
  727. public Reset_Score_Message()
  728. {
  729.     g_iHumansScore = 0
  730.     g_iZombiesScore = 0
  731.     g_iRoundNum = 0
  732. }
  733.  
  734.  
  735. /*
  736. *   Simple function to check if given player steamid in our array or not
  737. *   This is used to save the previous users steamid so they not chosen again next round
  738. */
  739. public PlayerInArray(id)
  740. {
  741.     new szAuthId[34], szSavedAuthId[34];
  742.    
  743.     get_user_authid(id, szAuthId, charsmax(szAuthId))
  744.    
  745.     for(new i = 0; i < ArraySize(g_aChosenPlayers); i++)
  746.     {
  747.         ArrayGetString(g_aChosenPlayers, i, szSavedAuthId, charsmax(szSavedAuthId))
  748.        
  749.         if (equal(szSavedAuthId, szAuthId))
  750.         {
  751.             return true;
  752.         }
  753.     }
  754.    
  755.     return false;
  756. }
  757.  
  758. // Natives
  759. public native_ze_is_user_zombie(id)
  760. {
  761.     if (!is_user_connected(id))
  762.     {
  763.         return -1;
  764.     }
  765.    
  766.     return g_bIsZombie[id]
  767. }
  768.  
  769. public native_ze_set_user_zombie(id)
  770. {
  771.     if (!is_user_connected(id))
  772.     {
  773.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  774.         return false;
  775.     }
  776.    
  777.     Set_User_Zombie(id)
  778.     return true;
  779. }
  780.  
  781. public native_ze_set_user_human(id)
  782. {
  783.     if (!is_user_connected(id))
  784.     {
  785.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  786.         return false;
  787.     }
  788.    
  789.     Set_User_Human(id)
  790.     return true;
  791. }
  792.  
  793. public native_ze_is_game_started()
  794. {
  795.     return g_bGameStarted
  796. }
  797.  
  798. public native_ze_is_zombie_frozen(id)
  799. {
  800.     if (!is_user_connected(id) || !g_bIsZombie[id])
  801.     {
  802.         return -1;
  803.     }
  804.    
  805.     return g_bIsZombieFrozen[id]
  806. }
  807.  
  808. public native_ze_get_round_number()
  809. {
  810.     if (!g_bGameStarted)
  811.     {
  812.         return -1;
  813.     }
  814.    
  815.     return g_iRoundNum
  816. }
  817.  
  818. public native_ze_get_humans_number()
  819. {
  820.     return GetAlivePlayersNum(CsTeams:TEAM_CT)
  821. }
  822.  
  823. public native_ze_get_zombies_number()
  824. {
  825.     return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  826. }
  827.  
  828. public native_ze_set_human_speed_factor(id, iFactor)
  829. {
  830.     if (!is_user_connected(id))
  831.     {
  832.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  833.         return false;
  834.     }
  835.    
  836.     g_bHSpeedUsed[id] = true
  837.     g_iHSpeedFactor[id] = iFactor
  838.     ExecuteHamB(Ham_Item_PreFrame, id)
  839.     return true;
  840. }
  841.  
  842. public native_ze_reset_human_speed(id)
  843. {
  844.     if (!is_user_connected(id))
  845.     {
  846.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  847.         return false;
  848.     }
  849.    
  850.     g_bHSpeedUsed[id] = false
  851.     ExecuteHamB(Ham_Item_PreFrame, id)
  852.     return true;
  853. }
  854.  
  855. public native_ze_set_zombie_speed(id, iSpeed)
  856. {
  857.     if (!is_user_connected(id))
  858.     {
  859.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  860.         return false;
  861.     }
  862.    
  863.     g_bZSpeedUsed[id] = true
  864.     g_iZSpeedSet[id] = iSpeed
  865.     return true;
  866. }
  867.  
  868. public native_ze_reset_zombie_speed(id)
  869. {
  870.     if (!is_user_connected(id))
  871.     {
  872.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  873.         return false;
  874.     }
  875.    
  876.     g_bZSpeedUsed[id] = false
  877.     return true;
  878. }
He who fails to plan is planning to fail

User avatar
DarkZombie
Member
Member
Hungary
Posts: 76
Joined: 5 years ago
Contact:

#6

Post by DarkZombie » 5 years ago

I tested it, but unfortunately it does not work.

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

#7

Post by Raheem » 5 years ago

Working for me, make sure you updated right.
Also this became in our Mod check: https://github.com/raheem-cs/Zombie-Esc ... 62c3ef8d73
He who fails to plan is planning to fail

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 598
Joined: 7 years ago
Contact:

#8

Post by czirimbolo » 5 years ago

I updated ze_core but:

L 09/10/2018 - 13:41:31: [ReAPI] rg_set_user_team: player 3 is not connected
L 09/10/2018 - 13:41:31: [AMXX] Displaying debug trace (plugin "ze_core.amxx", version "1.3")
L 09/10/2018 - 13:41:31: [AMXX] Run time error 10: native error (native "rg_set_user_team")
L 09/10/2018 - 13:41:31: [AMXX] [0] ze_core.sma::Fw_PlayerSpawn_Post (line 240)
Image

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

#9

Post by Raheem » 5 years ago

czirimbolo wrote: 5 years ago I updated ze_core but:

L 09/10/2018 - 13:41:31: [ReAPI] rg_set_user_team: player 3 is not connected
L 09/10/2018 - 13:41:31: [AMXX] Displaying debug trace (plugin "ze_core.amxx", version "1.3")
L 09/10/2018 - 13:41:31: [AMXX] Run time error 10: native error (native "rg_set_user_team")
L 09/10/2018 - 13:41:31: [AMXX] [0] ze_core.sma::Fw_PlayerSpawn_Post (line 240)
Which core you used, this: viewtopic.php?p=7959#p7959 or this: https://github.com/raheem-cs/Zombie-Esc ... 62c3ef8d73
He who fails to plan is planning to fail

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 598
Joined: 7 years ago
Contact:

#10

Post by czirimbolo » 5 years ago

Code: Select all

#include <zombie_escape>
 
// Fowards
enum _:TOTAL_FORWARDS
{
    FORWARD_NONE = 0,
    FORWARD_ROUNDEND,
    FORWARD_HUMANIZED,
    FORWARD_PRE_INFECTED,
    FORWARD_INFECTED,
    FORWARD_ZOMBIE_APPEAR,
    FORWARD_ZOMBIE_RELEASE,
    FORWARD_GAME_STARTED
}
 
new g_iForwards[TOTAL_FORWARDS], g_iFwReturn, g_iTeam
 
// Tasks IDs
enum
{
    TASK_COUNTDOWN = 1100,
    TASK_COUNTDOWN2,
    TASK_SCORE_MESSAGE,
    FREEZE_ZOMBIES,
    ROUND_TIME_LEFT
}
 
// Colors (g_pCvarColors[] array indexes)
enum
{
    Red = 0,
    Green,
    Blue
}
 
// Variables
new g_iAliveHumansNum,
    g_iAliveZombiesNum,
    g_iRoundTime,
    g_iCountDown,
    g_iReleaseNotice,
    g_iMaxClients,
    g_iHumansScore,
    g_iZombiesScore,
    g_iRoundNum,
    g_iHSpeedFactor[33],
    g_iZSpeedSet[33],
    bool:g_bGameStarted,
    bool:g_bIsZombie[33],
    bool:g_bIsZombieFrozen[33],
    bool:g_bZombieFreezeTime,
    bool:g_bIsRoundEnding,
    bool:g_bHSpeedUsed[33],
    bool:g_bZSpeedUsed[33],
    bool:g_bEndCalled,
    Float:g_flReferenceTime
 
// Cvars
new g_pCvarHumanSpeedFactor,
    g_pCvarHumanGravity,
    g_pCvarHumanHealth,
    g_pCvarZombieSpeed,
    g_pCvarZombieGravity,
    g_pCvarZombieReleaseTime,
    g_pCvarFreezeTime,
    g_pCvarRoundTime,
    g_pCvarReqPlayers,
    g_pCvarZombieHealth,
    g_pCvarFirstZombiesHealth,
    g_pCvarZombieKnockback,
    g_pCvarScoreMessageType,
    g_pCvarColors[3],
    g_pCvarRoundEndDelay
   
// Dynamic
new Array:g_aChosenPlayers
 
public plugin_natives()
{
    register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
    register_native("ze_is_game_started", "native_ze_is_game_started", 1)
    register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
   
    register_native("ze_get_round_number", "native_ze_get_round_number", 1)
    register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
    register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
   
    register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
    register_native("ze_set_user_human", "native_ze_set_user_human", 1)
    register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
    register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
   
    register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
    register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
}
 
public plugin_init()
{
    register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
    RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
    RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
    RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
   
    // Events
    register_event("HLTV", "New_Round", "a", "1=0", "2=0")
    register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
    register_logevent("Round_Start", 2, "1=Round_Start")
    register_logevent("Round_End", 2, "1=Round_End")
   
    // Hams
    RegisterHam(Ham_Item_PreFrame, "player", "Fw_RestMaxSpeed_Post", 1)
   
    // Create Forwards (All Return Values Ignored)
    g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
    g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
    g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
    g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
    g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
    g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
    g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
   
    // Hud Messages
    g_iReleaseNotice = CreateHudSyncObj()
   
    // Sequential files (.txt)
    register_dictionary("zombie_escape.txt")
   
    // Humans Cvars
    g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
    g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
    g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
   
    // Zombie Cvars
    g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
    g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
    g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
    g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
    g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
   
    // General Cvars
    g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
    g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
    g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
    g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
    g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
    g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
    g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
    g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
    g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
   
    // Default Values
    g_bGameStarted = false
   
    // Static Values
    g_iMaxClients = get_member_game(m_nMaxPlayers)
   
    // Check Round Time to Terminate it
    set_task(1.0, "Check_RoundTimeleft", ROUND_TIME_LEFT, _, _, "b")
   
    // Create our array to store SteamIDs in
    g_aChosenPlayers = ArrayCreate(34)
}
 
public plugin_cfg()
{
    // Get our configiration file and Execute it
    new szCfgDir[64]
    get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir))
    server_cmd("exec %s/zombie_escape.cfg", szCfgDir)
   
    // Set Game Name
    new szGameName[64]
    formatex(szGameName, sizeof(szGameName), "Zombie Escape v%s", ZE_VERSION)
    set_member_game(m_GameDesc, szGameName)
   
    // Set Version
    register_cvar("ze_version", ZE_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
    set_cvar_string("ze_version", ZE_VERSION)
}
 
public Fw_CheckMapConditions_Post()
{
    // Block Game Commencing
    set_member_game(m_bGameStarted, true)
   
    // Set Freeze Time
    set_member_game(m_iIntroRoundTime, get_pcvar_num(g_pCvarFreezeTime))
   
    // Set Round Time
    set_member_game(m_iRoundTime, floatround(get_pcvar_float(g_pCvarRoundTime) * 60.0))
}
 
public Fw_PlayerKilled_Post(id)
{
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
   
    if (g_iAliveHumansNum == 0 && g_iAliveZombiesNum == 0)
    {
        // No Winner, All Players in one team killed Or Both teams Killed
        client_print(0, print_center, "%L", LANG_PLAYER, "NO_WINNER")
    }
}
 
public Fw_RestMaxSpeed_Post(id)
{
    if (!g_bIsZombie[id])
    {
        static Float:flMaxSpeed
        get_entvar(id, var_maxspeed, flMaxSpeed)
       
        if (flMaxSpeed != 1.0 && is_user_alive(id))
        {
            if (g_bHSpeedUsed[id])
            {
                // Set New Human Speed Factor
                set_entvar(id, var_maxspeed, flMaxSpeed + float(g_iHSpeedFactor[id]))
                return HAM_IGNORED
            }
               
            // Set Human Speed Factor, native not used
            set_entvar(id, var_maxspeed, flMaxSpeed + get_pcvar_float(g_pCvarHumanSpeedFactor))
            return HAM_IGNORED
        }
    }
   
    return HAM_SUPERCEDE
}
 
public Fw_PlayerSpawn_Post(id)
{  
    if (!g_bGameStarted)
    {
        // Force All player to be Humans if Game not started yet
        rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
    }
    else
    {
        if (get_member_game(m_bFreezePeriod))
        {
            // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
            Set_User_Human(id)
            g_bIsZombieFrozen[id] = false
        }
        else
        {
            if (g_bZombieFreezeTime)
            {
                // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
                Set_User_Zombie(id)
                g_bIsZombieFrozen[id] = true
                set_entvar(id, var_maxspeed, 1.0)
            }
            else
            {
                // Respawn him as normal zombie
                Set_User_Zombie(id)
                g_bIsZombieFrozen[id] = false
            }
        }
    }
}
 
public New_Round()
{
    // Remove All tasks in the New Round
    remove_task(TASK_COUNTDOWN)
    remove_task(TASK_COUNTDOWN2)
    remove_task(TASK_SCORE_MESSAGE)
    remove_task(FREEZE_ZOMBIES)
   
    // Score Message Task
    set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
   
    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_member_game(m_iIntroRoundTime) - 2
   
    if (!g_bGameStarted)
    {
        // No Enough Players
        ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
        return // Block the execution of the blew code
    }
   
    // Game Already started, Countdown now started
    set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
    ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
    ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
   
    g_iRoundNum++
   
    // Round Starting
    g_bIsRoundEnding = false
    g_bEndCalled = false
}
 
// Score Message Task
public Score_Message(TaskID)
{
    switch(get_pcvar_num(g_pCvarScoreMessageType))
    {
        case 0: // Disabled
        {
            return
        }
        case 1: // DHUD
        {
            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)
            show_dhudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
        }
        case 2: // HUD
        {
            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)
            show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
        }
    }
}
 
public Countdown_Start(TaskID)
{
    // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
    if (!g_bGameStarted)
        return
   
    if (!g_iCountDown)
    {
        Choose_Zombies()
        remove_task(TASK_COUNTDOWN) // Remove the task
        return // Block the execution of the blew code
    }
   
    set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
    show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
 
    g_iCountDown--
}
 
public Choose_Zombies()
{
    new iZombies, id, iAliveCount
    new iReqZombies
   
    // Get total alive players and required players
    iAliveCount  = GetAllAlivePlayersNum()
    iReqZombies = RequiredZombies()
   
    // Loop till we find req players
    while(iZombies < iReqZombies)
    {
        id = GetRandomAlive(random_num(1, iAliveCount))
       
        // If player in array (Players steamid), it means he has chosen the previous round so skip him
        if (!is_user_alive(id) || g_bIsZombie[id] || PlayerInArray(id))
            continue
 
        Set_User_Zombie(id)
        set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
        g_bIsZombieFrozen[id] = true
        g_bZombieFreezeTime = true
        set_entvar(id, var_maxspeed, 1.0)
        set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
        ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
        iZombies++
    }
   
    // After choose, we clear the array
    ArrayClear(g_aChosenPlayers)
   
    // Now we loop through all players and store the chosen zombies steamid so they not chosen the next round again
    // Using steamid will add reconnect support
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if(!is_user_connected(id) || !g_bIsZombie[id])
            continue
       
        new szAuthId[34];
       
        get_user_authid(id, szAuthId, charsmax(szAuthId));
       
        ArrayPushString(g_aChosenPlayers, szAuthId)
    }
   
    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
   
    set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
}
 
public ReleaseZombie_CountDown(TaskID)
{
    if (!g_iCountDown)
    {
        ReleaseZombie()
        remove_task(TASK_COUNTDOWN2)
        return
    }
   
    // Release Hud Message
    set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
    ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
   
    g_iCountDown --
}
 
public ReleaseZombie()
{
    ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
   
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if (is_user_alive(id) && g_bIsZombie[id])
        {
            g_bIsZombieFrozen[id] = false
            g_bZombieFreezeTime = false
        }
    }
}
 
public Freeze_Zombies(TaskID)
{
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if(!is_user_alive(id) || !g_bIsZombie[id])
            continue
       
        if (g_bIsZombieFrozen[id])
        {
            // Zombie & Frozen, then Freeze him
            set_entvar(id, var_maxspeed, 1.0)
        }
        else
        {
            if (g_bZSpeedUsed[id])
            {
                // Zombie but Not Frozen the set his speed form .cfg
                set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
                continue;
            }
               
            // Zombie but Not Frozen the set his speed form .cfg
            set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
        }
    }
}
 
public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
{
    if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
        return HC_CONTINUE
   
    // Attacker and Victim is in same teams? Skip code blew
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // In freeze time? Skip all other plugins (Skip the real trace attack event)
    if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
        return HC_SUPERCEDE
   
    // Execute pre-infection forward
    ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker, floatround(flDamage))
   
    if (g_iFwReturn > 0)
    {
        return HC_SUPERCEDE
    }
   
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
   
    if (g_bIsZombie[iAttacker])
    {
        // Death Message with Infection style [Added here because of delay in Forward use]
        SendDeathMsg(iAttacker, iVictim)
       
        Set_User_Zombie(iVictim)
       
        ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
       
        if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
        {
            // End round event called one time
            g_bEndCalled = true
           
            // Round is Ending
            g_bIsRoundEnding = true
           
            // Zombie Win, Leave text blank so we use ours from ML
            rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
           
            // Show Our Message
            client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
           
            // This needed so forward work also to add +1 for Zombies
            g_iTeam = 1 // ZE_TEAM_ZOMBIE
            ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
        }
    }
   
    return HC_CONTINUE
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
    if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
        return HC_CONTINUE
   
    // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
    if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
    {
        // Remove Shock Pain
        set_member(iVictim, m_flVelocityModifier, 1.0)
       
        // Set Knockback
        static Float:flOrigin[3]
        get_entvar(iAttacker, var_origin, flOrigin)
        Set_Knockback(iVictim, flOrigin, get_pcvar_float(g_pCvarZombieKnockback), 2)
    }
   
    return HC_CONTINUE
}
 
public Round_End()
{
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
   
    if (g_iAliveZombiesNum == 0 && g_bGameStarted)
    {
        g_iTeam = 2 // ZE_TEAM_HUMAN
        ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
        client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
        g_iHumansScore++
        g_bIsRoundEnding = true
        return // To block Execute the code blew
    }
   
    g_iTeam = 1 // ZE_TEAM_ZOMBIE
    g_iZombiesScore++
    g_bIsRoundEnding = true
   
    // If it's already called one time, don't call it again
    if (!g_bEndCalled)
    {
        ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
    }
   
    client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
}
 
public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
{
    // The two unhandeld cases by rg_round_end() native in our Mod
    if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
    {
        SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
    }
}
 
public Round_Start()
{
    g_flReferenceTime = get_gametime()
    g_iRoundTime = get_member_game(m_iRoundTime)
}
 
public Check_RoundTimeleft()
{
    new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
   
    if (floatround(flRoundTimeLeft) == 0)
    {
        // Round is Ending
        g_bIsRoundEnding = true
       
        // If Time is Out then Terminate the Round
        rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
       
        // Show our Message
        client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    }
}
 
public client_disconnected(id)
{
    // Delay Then Check Players to Terminate The round (Delay needed)
    set_task(0.1, "Check_AlivePlayers")
   
    // Reset speed for this dropped id
    g_bHSpeedUsed[id] = false
    g_bZSpeedUsed[id] = false
}
 
// This check done when player disconnect
public Check_AlivePlayers()
{
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
   
    // Game Started? (There is at least 2 players Alive?)
    if (g_bGameStarted)
    {
        // We are in freeze time?
        if (get_member_game(m_bFreezePeriod))
        {
            // Humans alive number = 1 and no zombies?
            if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
            {
                // Game started false again
                g_bGameStarted = false
            }
        }
        else // Not freeze time?
        {
            // Variables
            new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
            iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
            iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
            iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
   
            // Alive humans number = 1 and no zombies at all, And no dead humans?
            if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
            {
                // Game started is false and humans wins (Escape Success)
                g_bGameStarted = false
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
            }
           
            // Alive zombies number = 1 and no humans at all, And no dead zombies?
            if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
            {
                // Game started is false and zombies wins (Escape Fail)
                g_bGameStarted = false
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
            }
           
            // Humans number more than 1 and no zombies?
            if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding)
            {
                // Then Escape success as there is no Zombies
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
            }
           
            // Zombies number more than 1 and no humans?
            if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
            {
                // Then Escape Fail as there is no humans
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
            }
        }
    }
}
 
public client_putinserver(id)
{
    // Add Delay and Check Conditions To start the Game (Delay needed)
    set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
}
 
public Check_AllPlayersNumber(TaskID)
{
    if (g_bGameStarted)
    {
        // If game started remove the task and block the blew Checks
        remove_task(TaskID)
        return
    }
   
    if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
    {
        // Players In server == The Required so game started is true
        g_bGameStarted = true
       
        // Restart the game
        server_cmd("sv_restart 2")
       
        // Print Fake game Commencing Message
        client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
       
        // Remove the task
        remove_task(TaskID)
    }
}
 
public Set_User_Human(id)
{
    if (!is_user_alive(id))
        return
   
    g_bIsZombie[id] = false
    set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
    set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHumanGravity)/800.0)
    ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
   
    if (get_member(id, m_iTeam) != TEAM_CT)
        rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
}
 
public Set_User_Zombie(id)
{
    if (!is_user_alive(id))
        return
   
    g_bIsZombie[id] = true
    set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
    set_entvar(id, var_gravity, get_pcvar_float(g_pCvarZombieGravity)/800.0)
    rg_remove_all_items(id)
    rg_give_item(id, "weapon_knife", GT_APPEND)
    ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
   
    if (get_member(id, m_iTeam) != TEAM_TERRORIST)
        rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
}
 
public Map_Restart()
{
    // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
    set_task(0.1, "Reset_Score_Message")
}
 
public Reset_Score_Message()
{
    g_iHumansScore = 0
    g_iZombiesScore = 0
    g_iRoundNum = 0
}
 
 
/*
*   Simple function to check if given player steamid in our array or not
*   This is used to save the previous users steamid so they not chosen again next round
*/
public PlayerInArray(id)
{
    new szAuthId[34], szSavedAuthId[34];
   
    get_user_authid(id, szAuthId, charsmax(szAuthId))
   
    for(new i = 0; i < ArraySize(g_aChosenPlayers); i++)
    {
        ArrayGetString(g_aChosenPlayers, i, szSavedAuthId, charsmax(szSavedAuthId))
       
        if (equal(szSavedAuthId, szAuthId))
        {
            return true;
        }
    }
   
    return false;
}
 
// Natives
public native_ze_is_user_zombie(id)
{
    if (!is_user_connected(id))
    {
        return -1;
    }
   
    return g_bIsZombie[id]
}
 
public native_ze_set_user_zombie(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    Set_User_Zombie(id)
    return true;
}
 
public native_ze_set_user_human(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    Set_User_Human(id)
    return true;
}
 
public native_ze_is_game_started()
{
    return g_bGameStarted
}
 
public native_ze_is_zombie_frozen(id)
{
    if (!is_user_connected(id) || !g_bIsZombie[id])
    {
        return -1;
    }
   
    return g_bIsZombieFrozen[id]
}
 
public native_ze_get_round_number()
{
    if (!g_bGameStarted)
    {
        return -1;
    }
   
    return g_iRoundNum
}
 
public native_ze_get_humans_number()
{
    return GetAlivePlayersNum(CsTeams:TEAM_CT)
}
 
public native_ze_get_zombies_number()
{
    return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
}
 
public native_ze_set_human_speed_factor(id, iFactor)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bHSpeedUsed[id] = true
    g_iHSpeedFactor[id] = iFactor
    ExecuteHamB(Ham_Item_PreFrame, id)
    return true;
}
 
public native_ze_reset_human_speed(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bHSpeedUsed[id] = false
    ExecuteHamB(Ham_Item_PreFrame, id)
    return true;
}
 
public native_ze_set_zombie_speed(id, iSpeed)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bZSpeedUsed[id] = true
    g_iZSpeedSet[id] = iSpeed
    return true;
}
 
public native_ze_reset_zombie_speed(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bZSpeedUsed[id] = false
    return true;
}
Image

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

#11

Post by Raheem » 5 years ago

You are using first one not which on github, ok here it's fixed:

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

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 0 guests