Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 85.01 KB | None | 0 0
  1.    --Creator: AelitePrime and Wizard
  2.     --Script Name: Zombie Script
  3.     --Website: http://phasorscripts.wordpress.com/
  4.         --Xfire: eliteprime14789x, and th3w1zard3
  5.         --Version: 4.0
  6.     --Reason for Update: Phasor Update
  7.  
  8. -- General infection settings
  9.  
  10. frag_nade = true -- Block Frag Grenades?
  11. plasma_nade = true -- Block Plasma Grenades?
  12.  
  13.  
  14. -- Gravity Rifle Info
  15. gravity = {}
  16. vehicles = {}
  17. activetime = {}
  18.  
  19. ------
  20.  
  21.  
  22.         -- Team Variables
  23. zombie_team = 1 -- 0 is red, 1 is blue
  24. human_team = 0
  25. join_team = zombie_team -- the team that people will join if a game is currently running
  26.  
  27.         -- Last Man Variables
  28. lastman_speed = 2.0 -- last man speed
  29. lastman_dmgmodifier = 2.0 -- damage modifier for the last man (on top of human damage)
  30. lastman_invistime = 20 -- in seconds
  31. last_man_next_zombie = true -- if this value is true the last man standing becomes the next zombie, if not it's random
  32. lastman_invulnerable = 5 -- time (in seconds) the last man is invulnerable for: replace with nil to disable
  33.  
  34.         -- Speed Variables
  35. zombie_speed = 3.0 -- zombie speed
  36. human_speed = 1.6 -- speed when not infected
  37.  
  38.         -- Alpha Zombie Variables
  39. alphazombie_frag_count = 0 -- number of frag nades they spawn with
  40. alphazombie_plasma_count = 0 -- number of plasma nades they spawn with
  41. alphazombie_clip_count = 0 -- number of shots in clip (loaded ammo)
  42. alphazombie_ammo_count = 0 -- backpack ammo they get (unloaded ammo)
  43. alphazombie_battery_count = 0 -- stored as a percent (0 to 1, do NOT go over or under)
  44.  
  45.         -- Zombie Variables
  46. zombie_count = 1 -- if value is less than 1 is it used as a percentage, more than or equal to one is absolute count
  47. max_zombie_count = 2 -- this caps what the zombie count would be w/ ratio (nil is disable)
  48. zombie_frag_count = 0 -- number of frag nades they spawn with
  49. zombie_plasma_count = 0 -- number of plasma nades they spawn with
  50. zombie_clip_count = 0 -- number of shots in clip for zombies once there are not only alpha zombies (loaded ammo)
  51. zombie_ammo_count = 0 -- backpack ammo zombies once there are not only alpha zombies (unloaded ammo)
  52. zombie_battery_count = 0 -- stored as a percent (0 to 1, do NOT go over or under)
  53.  
  54.         -- Damage Variable
  55. human_dmgmodifier = 1.5 -- damage modifier for humans.
  56.  
  57.         -- Invis Variables
  58. time_invis = 1 -- In seconds, how long the zombie/human should be invis when they crouch.
  59.  
  60.         -- Booleans
  61. zombie_instant_kill = true -- if this is set to true then a zombie melee will kill a human with one hit every time.
  62. infect_on_fall = true -- if this is set to true then people who die from fall damage will become zombies.
  63. infect_on_guardians = false -- if this is set to true then people who get killed by the guardians will become zombies.
  64. infect_on_suicide = true -- if this is set to true then people who kill themselves will become a zombie.
  65. infect_on_betray = true -- if this is set to true then people who betray their teammates will become a zombie.
  66. humans_allowed_in_vehis = false -- if this is set to false then humans cannot enter vehicles
  67. zombies_allowed_in_vehis = true -- if this is set to false then zombies cannot enter vehicles.
  68. zombies_invisible_on_crouch = true -- if this is set to true then zombies will be invisible when they crouch.
  69. humans_invisible_on_crouch = false -- if this is set to true then humans will become invisible when they crouch.
  70.  
  71. --Zombie weapons.
  72. -- Note: If you decide the player holds a flag or a ball, make sure the secondary, tertiary, and quarternary fields are "".
  73. -- DO NOT make zombies hold multiple weapons if you want them to hold an oddball or a flag. If you do it will not work right, and it's entirely your fault.
  74. zombie_weapon = {} -- don't touch this
  75. zombie_weapon[1] = "weapons\\shotgun\\shotgun" -- Primary weapon for zombies
  76. zombie_weapon[2] = "" -- Secondary weapon for zombies.
  77. zombie_weapon[3] = "" -- Tertiary weapon for zombies.
  78. zombie_weapon[4] = "" -- Quarternary weapon for zombies.
  79.  
  80. -- Game messages
  81. zombie_message = "YOU'RE A ZOMBIE! Melee Human Flesh!"
  82. human_message = "YOU'RE A HUMAN. Kill Zombies w/ VEHICLES!"
  83. rejoin_message = "Please don't leave and rejoin. You've been put back onto your last team."
  84. infected_message = " has been eaten alive!"
  85. teamkill_message = "What Are You Doing, Nigga. Don't team kill..."
  86. blockteamchange_message = "You're not allowed to change team."
  87. zombieinvis_message = "The zombies are invisible for 20 seconds!"
  88. timer_team_change_msg = "Thank you. The game will now continue"
  89. in_hill_too_long_msg = " has been infected because they were in the hill too long!"
  90. koth_additional_welcome_msg = "The hill is a safezone! Use it for quick getaways!"
  91. lastman_message = "%s is the last human alive and is invisible for %.0f seconds!"
  92. nozombiesleftmessage = "There are no zombies left. Someone needs to change team, otherwise a random player will be forced to."
  93. zombie_backtap_message = "Nice backtap!"
  94. human_backtap_message = "%s slaughtered you from behind." -- lol
  95.  
  96. -- Don't modify below variables unless you know what you're doing
  97. cur_zombie_count = 0
  98. cur_human_count = 0
  99. alpha_zombie_count = 0
  100. human_time = {}
  101. cur_players = 0
  102. cur_last_man = nil
  103. last_man_hash = 0
  104. processid = 0
  105. game_started = false
  106. allow_change = false
  107. map_reset_boolean = false
  108. flagball_weap = {}
  109. last_hill_time = {}
  110. hash_table = {}
  111. inhill_time = {}
  112. speed_count = {}
  113.  
  114. function GetRequiredVersion()
  115.         return 200
  116. end
  117.  
  118. function OnScriptLoad(process, game, persistent)
  119.         processid = process
  120.         Persistent = persistent
  121.         GetGameAddresses(game)
  122.         ScriptLoad()
  123. end
  124.  
  125. function OnNewGame(map)
  126.         if Persistent then
  127.                 ScriptLoad()
  128.         end
  129.        
  130.         -- reset our variables
  131.         cur_zombie_count = 0
  132.         cur_human_count = 0
  133.         cur_players = 0
  134.  
  135.         map = map
  136.  
  137.         -- the game hasn't started yet, will once timer runs down
  138.         game_started = false
  139.         if new_game_timer == nil then
  140.         new_game_timer = registertimer(1000, "NewGameTimer")
  141.         end
  142.         if map == "putput" or map == "longest" or map == "beavercreek" then
  143.                 zombie_speed = 1.5
  144.                 lastman_speed = 1.25
  145.         end
  146. end
  147.  
  148. function OnGameEnd(stage)
  149.     game_started = false
  150.         if stage == 1 then
  151.                 if humantimer then
  152.                 removetimer(humantimer)
  153.                         humantimer = nil
  154.                 end
  155.                 if new_game_timer then
  156.                         removetimer(new_game_timer)
  157.                         new_game_timer = nil
  158.                 end
  159.                 if crouch_timer then
  160.                         removetimer(crouch_timer)
  161.                         crouch_timer = nil
  162.                 end
  163.         if speedtimer then
  164.             removetimer(speedtimer)
  165.             speedtimer = nil
  166.         end
  167.         end
  168. end
  169.  
  170. function OnServerCommand(player, command)
  171.         local allow = nil
  172.         local cmd = tokenizecmdstring(command)
  173.         local tokencount = #cmd
  174.         if tokencount > 0 then
  175.                 if cmd[1] == "sv_changeteam" and tokencount == 2 then
  176.                         local player = cmd[2]
  177.                         player = rresolveplayer(player)
  178.                         if getplayer(player) then
  179.                                 local cur_team = getteam(player)
  180.                                 if cur_team == zombie_team then
  181.                                         makehuman(player, true)
  182.                                         privatesay(player, human_message)
  183.                                 elseif cur_team ~= zombie_team then
  184.                                         makezombie(player, true)
  185.                                         privatesay(player, zombie_message)
  186.                                 end
  187.                                 --sendresponse("The player's team has been changed.", player)
  188.                         else
  189.                                 sendresponse("The specified player is invalid", player)
  190.                         end
  191.                         allow = false
  192.                 elseif cmd[1] == "sv_map_reset" or cmd[1] == "sv_script_reload" then
  193.                         map_reset_boolean = true
  194.                         for i = 0,15 do
  195.                                 local m_player = getplayer(i)
  196.                                 if m_player then
  197.                                         local m_objectId = getplayerobjectid(i)
  198.                                         if m_objectId then
  199.                                                 local m_object = getobject(m_objectId)
  200.                                                 if m_object then
  201.                                                         local team = getteam(i)
  202.                                                         if team == zombie_team then
  203.                                                                 if m_objectId then
  204.                                                                         destroyobject(m_objectId)
  205.                                                                 end
  206.                                                         end
  207.                                                 end
  208.                                         end
  209.                                 end
  210.                         end
  211.                 end
  212.         end
  213.         return allow
  214. end
  215.  
  216. function OnPlayerJoin(player)
  217.  
  218.     speed_count[player] = 0
  219.         -- update the player counts
  220.         cur_players = cur_players + 1
  221.         local team = getteam(player)
  222.         -- onteamdecision isn't called for ffa gametypes
  223.         if not team_play then
  224.                 -- initialize the destination team as the join team
  225.                 local dest_team = join_team
  226.                 -- make sure the game is started
  227.                 if game_started then
  228.                         -- if no zombies make them human
  229.                         if cur_players == 0 then
  230.                                 -- change the destination team to human if cur_players 0 (doesn't matter if join_team is humanteam)
  231.                                 dest_team = human_team
  232.                         -- check if there are zombies but no humans
  233.                         elseif cur_zombie_count > 0 and cur_human_count == 0 then
  234.                                 -- change the destination team to human if condition met (doesn't matter if join_team is humanteam)
  235.                                 dest_team = human_team
  236.                         end
  237.                 end
  238.                 -- we need to overwrite the 'team' variable being passed to onplayerjoin
  239.                 if dest_team == zombie_team then
  240.                         team = zombie_team
  241.                 elseif tonumber(dest_team) then
  242.                         team = 2
  243.                 end
  244.         end
  245.         local thisTeamSize = 0 -- used so we don't create empty teams for rejoining players
  246.         if team == zombie_team then
  247.                 cur_zombie_count = cur_zombie_count + 1
  248.                 thisTeamSize = cur_zombie_count
  249.         else
  250.                 cur_human_count = cur_human_count + 1
  251.                 thisTeamSize = cur_human_count
  252.         end
  253.         alpha_zombie_count = getalphacount()
  254.         local thisHash = gethash(player)
  255.         local alreadyExists = false
  256.         -- check if the player has joined this game previously
  257.         for k,v in pairs(hash_table) do
  258.                 if thisHash == k then
  259.                         if thisTeamSize > 1 then
  260.                                 if v ~= team then
  261.                                         --check what team they currently are (only added for ffa gametypes)
  262.                                         if team == zombie_team then
  263.                                                 makehuman(player, false)
  264.                                         else
  265.                                                 makezombie(player, false)
  266.                                         end
  267.                                 end
  268.                                 privatesay(player, rejoin_message)
  269.                                 team = v
  270.                         end
  271.                         alreadyExists = true
  272.                         break
  273.                 end
  274.         end
  275.         -- add team entry for this hash
  276.         if alreadyExists == false then
  277.                 hash_table[thisHash] = team
  278.         end
  279.         -- make sure the game is started
  280.         if game_started == true then
  281.                 -- check if the player is a zombie
  282.                 if team == zombie_team then
  283.                         --we don't need to update the counters since they're already on the zombieteam
  284.                         makezombie(player, false, true)
  285.                         --send them the zombie message
  286.                         privatesay(player, zombie_message)
  287.                 else
  288.                         -- if we're at last man, make this player a zombie
  289.                         if cur_last_man then
  290.                                 --make this person a zombie (they're currently a human)
  291.                                 makezombie(player, true)
  292.                                 --send them the zombie message
  293.                                 privatesay(player, zombie_message)
  294.                         else
  295.                                 --make this person a human (they're currently a zombie)
  296.                                 makehuman(player, false, true)
  297.                                 --send them the human message
  298.                                 privatesay(player, human_message)
  299.                         end
  300.                 end
  301.                 registertimer(0,"checkgamestate",-1)
  302.         end
  303. end
  304.  
  305. function OnPlayerLeave(player)
  306.  
  307.     speed_count[player] = 0
  308.     gravity[player] = nil
  309.     local team = getteam(player)
  310.         --check if they're a zombie
  311.         if game_started and team == zombie_team then
  312.                 --get their object struct
  313.                 local m_objectId = getplayerobjectid(player)
  314.                 if m_objectId then
  315.                     local m_object = getobject(m_objectId)
  316.                         if m_object then -- make sure the player is alive
  317.                                 for i = 0,3 do -- loop through all their weapons (primary through quartenary)
  318.                                         --get their weapon's ID
  319.                                         local weapID = readdword(m_object + 0x2F8 + i*4)
  320.                     if weapID then
  321.                                         --get their weapon's struct
  322.                                         local weap = getobject(weapID)
  323.                                         --make sure the weapon exists
  324.                                         if weap then
  325.                                                 --weapon needs to be destroyed
  326.                                                 registertimer(0, "destroyweaps", weapID)
  327.                                                 destroyobject(weapID)
  328.                                         end
  329.                                     end
  330.                 end
  331.                         end
  332.                 end
  333.                 --take one away from the current zombie count
  334.                 cur_zombie_count = cur_zombie_count - 1
  335.         elseif team ~= zombie_team then
  336.                 --take one away from the current human count
  337.                 cur_human_count = cur_human_count - 1
  338.         end
  339.         -- if last man is leaving, reset it
  340.         if cur_last_man == player then
  341.                 cur_last_man = nil
  342.         end
  343.         --minus one from current players
  344.         cur_players = cur_players - 1
  345.         --check the current game state (the player that left might have been the last man or the only zombie)
  346.         registertimer(0,"checkgamestate",-1)
  347.         -- update team within table
  348.         local thisHash = gethash(player)
  349.         hash_table[thisHash] = team
  350. end
  351.  
  352. function OnPlayerSpawn(player)
  353.         --get the player's team
  354.         local team = getteam(player)
  355.         --check if the player is a zombie
  356.         if team == zombie_team then
  357.                 --get the player's object ID
  358.                 local m_objectId = getplayerobjectid(player)
  359.         if m_objectId == nil then
  360.             return
  361.         end
  362.                 --get the player's object struct
  363.                 local m_object = getobject(m_objectId)
  364.                 --make sure the player is alive (off chance that there's a glitch in phasor)
  365.                 if m_object then
  366.                         -- set nade counts
  367.                         writebyte(m_object + 0x31E, zombie_frag_count)
  368.                         writebyte(m_object + 0x31F, zombie_plasma_count)
  369.                         -- set the ammo
  370.                         local clipcount = alphazombie_clip_count
  371.                         local ammocount = alphazombie_ammo_count
  372.                         local batterycount = alphazombie_battery_count
  373.                         -- set ammo counts for zombies when others have been infected
  374.                         if cur_zombie_count > alpha_zombie_count then
  375.                                 clipcount = zombie_clip_count
  376.                                 ammocount = zombie_ammo_count
  377.                                 batterycount = zombie_battery_count
  378.                         else -- set alpha nades
  379.                                 writebyte(m_object + 0x31E, alphazombie_frag_count)
  380.                                 writebyte(m_object + 0x31F, alphazombie_plasma_count)
  381.                         end
  382.                         --check if the starting equipment is generic
  383.                         if starting_equipment == "Generic" then
  384.                                 -- initialize this boolean as false
  385.                                 local bool = false
  386.                                 for i=0,3 do --loop through the player's weapons (primary through quartenary)
  387.                                         --get the player's weapon's ID
  388.                                         local m_weaponId = readdword(m_object + 0x2F8 + i*4)
  389.                     if m_weaponId == nil then
  390.                         return
  391.                     end
  392.                                         --check if the zombie weapon is an oddball or a flag
  393.                                         if oddball_or_flag then
  394.                                                 --make sure the boolean is still false and the player's weapon exists.
  395.                                                 if bool == false and getobject(m_weaponId) then
  396.                                                         --get the weapon's tagname
  397.                                                         local tagName = getobjecttag(m_weaponId)
  398.                                                         --make sure the weapon's tagname is the zombie weapon (oddball/flag)
  399.                                                         if tagName == oddball_or_flag then
  400.                                                                 --store the weapon's ID in the flagball_weap table
  401.                                                                 flagball_weap[player] = m_weaponId
  402.                                                                 --set bool to true
  403.                                                                 bool = true
  404.                                                         end
  405.                                                 end
  406.                                         --zombie weapon is not a flag or a ball
  407.                                         elseif m_weaponId then
  408.                                                 --get the weapon's struct
  409.                                                 local m_weapon = getobject(m_weaponId)
  410.                                                 --make sure the weapon exists
  411.                                                 if m_weapon then
  412.                                                         -- set the ammo
  413.                                                         writeword(m_weapon + 0x2B6, ammocount)
  414.                                                         writeword(m_weapon + 0x2B8, clipcount)
  415.                                                         -- set the battery (math.abs is absolute value meaning it takes the opposite of battery count (meaning 0 needs to be 1 and 1 needs to be 0))
  416.                                                         writefloat(m_weapon + 0x240, math.abs(batterycount - 1))
  417.                                                         -- force it to sync
  418.                                                         updateammo(m_weaponId)
  419.                                                 end
  420.                                         end
  421.                                 end
  422.                                 -- check if we still need to assign leftover weapons to zombies (tertiary and quartenary weapons)
  423.                                 if (zombie_weapon[3] and zombie_weapon[3] ~= "") then -- make sure the script user isn't retarded
  424.                                         --assign the leftover weapons to the playerr
  425.                     if getplayer(player) then
  426.                                         table = {player, clipcount, ammocount, batterycount}
  427.                                             registertimer(0, "AssignLeftoverZombieWeapons", table)
  428.                     end
  429.                                 end
  430.                         elseif starting_equipment == "Custom" then
  431.                                 --assign the correct weapons to the player
  432.                 if getplayer(player) then
  433.                                 table = {player, clipcount, ammocount, batterycount}
  434.                                     registertimer(0, "AssignZombieWeapons", table)
  435.                 end
  436.                         end
  437.                 end
  438.         end
  439.         --check if the gametype is slayer
  440.         if gametype == "Slayer" then
  441.                 local m_player = getplayer(player)
  442.                 --check if we're at the last_man
  443.         if m_player == nil then
  444.             return
  445.         end
  446.                 if cur_last_man then
  447.                         --write the navpoint to the current last man
  448.                         writeword(m_player + 0x88, cur_last_man)
  449.                 else
  450.                         --there is no last man so put a nav above this player's head
  451.                         writeword(m_player + 0x88, player)
  452.                 end
  453.         end
  454. end
  455.  
  456. function OnPlayerSpawnEnd(player)
  457.     if getteam(player) == 1 then -- blue team
  458.         for i = 0,3 do
  459.             local m_objectId = getplayerobjectid(player)
  460.             local m_object = getobject(m_objectId)
  461.             if m_object then
  462.                 local weapID = readdword(m_object + 0x2F8 + i*4)
  463.                 local weap = getobject(weapID)
  464.                 if weap then
  465.                     destroyobject(weapID)
  466.                 end
  467.             end
  468.         end
  469.         local gun = createobject(gettagid("weap", "weapons\\shotgun\\shotgun"), 0, 1, false, 0, 0, 0)
  470.         if getobject(gun) then
  471.             assignweapon(player, gun)
  472.         end
  473.         registertimer(100, 'delay', player)
  474.     end
  475. end
  476.  
  477. function delay(id, count, player)
  478.  
  479.     if getplayer(player) then
  480.         local m_objectId = getplayerobjectid(player)
  481.         local m_object = getobject(m_objectId)
  482.         if m_object then
  483.             for i = 0, 3 do
  484.                 local m_weaponId = readdword(m_object + 0x2F8 + i*4)
  485.                 if m_weaponId then
  486.                     local m_weapon = getobject(m_weaponId)
  487.                     if m_weapon then
  488.                         writeword(m_weapon + 0x2B6, 0)
  489.                         writeword(m_weapon + 0x2B8, 0)
  490.                         writefloat(m_weapon + 0x240, math.abs(0 - 1))
  491.                         updateammo(m_weaponId)
  492.                     end
  493.                 end
  494.             end
  495.         end
  496.     end
  497.     return false
  498. end
  499.  
  500. function OnObjectCreationAttempt(mapId, parentId, player)
  501.     local tag_name, tag_type = gettaginfo(mapId)
  502.     if gametype == "CTF" then
  503.         if tag_name == "weapons\\flag\\flag" then
  504.             local m_objectId = readdword(ctf_globals + 0x8)
  505.             registertimer(0, "PutUnderMap", m_objectId)
  506.             return
  507.         end
  508.     end
  509.    
  510.     if getplayer(player) then
  511.         if getteam(player) == zombie_team then
  512.             if tag_type == "proj" then
  513.                 return false
  514.             end
  515.         end
  516.     end
  517.     return nil
  518. end
  519.  
  520. function OnObjectInteraction(player, objId, mapId)
  521.     local tagName,tagType = gettaginfo(mapId)
  522.     if tagName == "weapons\\flag\\flag" then
  523.         return false
  524.     end
  525.     if getteam(player) == zombie_team then
  526.         if tagName == "weapons\\frag grenade\\frag grenade" or tagName == "weapons\\plasma grenade\\plasma grenade" then
  527.             return false
  528.         end
  529.     end
  530.     if game_started == true then
  531.         if tagType == "weap" then
  532.             if getteam(player) == zombie_team then
  533.                 return false
  534.             end
  535.             if tagName == oddball_or_flag then
  536.                 return false
  537.             end
  538.         end
  539.         if getteam(player) == zombie_team then
  540.             if tagType == "eqip" then
  541.                 if tagName == "powerups\\active camouflage" then
  542.                     if getplayer(player) then
  543.                         local m_playerObjId = readdword(getplayer(player) + 0x34)
  544.                         local m_object = getobject(m_playerObjId)
  545.                         if m_object then
  546.                             local camoFlag = readdword(m_object + 0x204)
  547.                             if camoFlag ~= 0x51 then
  548.                                 local doInvis = getrandomnumber(1, 11)
  549.                                 if doInvis > 5 then
  550.                                     for x = 0,15 do
  551.                                         if getplayer(x) then
  552.                                             local team = getteam(x)
  553.                                             if team == zombie_team then
  554.                                                 applycamo(x, 30.00)
  555.                                             end
  556.                                         end
  557.                                     end
  558.                                     say(zombieinvis_message)
  559.                                 end
  560.                             end
  561.                         end
  562.                     end
  563.                     return true
  564.                 elseif tagName == "powerups\\over shield" then
  565.                     return true
  566.                 end
  567.                 return false
  568.             end
  569.         end
  570.     end
  571.     return true
  572. end
  573.  
  574. function OnPlayerKill(killer, victim, mode)
  575.     if getplayer(victim) then
  576.         gravity[victim] = nil
  577.     end
  578.     if getplayer(victim) then
  579.         speed_count[victim] = 0
  580.     end
  581.         -- make sure this kill doesn't add to the score so that the game won't end prematurely
  582.         if gametype == "Slayer" and killer and getplayer(killer) then writedword(slayer_globals + 0x40 + killer*4, 0) end
  583.         -- make sure the game is started
  584.         if game_started then
  585.                 -- get the victim's team
  586.                 local team = getteam(victim)
  587.                 if mode == 0 then -- server kill
  588.                 elseif mode == 1 and not map_reset_boolean then -- fall damage
  589.                         -- if this is true then a person who dies from falling will be infected
  590.                         if infect_on_fall then
  591.                                 --chech if the team is the human team
  592.                                 if tonumber(team) and team ~= zombie_team then
  593.                                         --get the victim's name
  594.                                         local name = getname(victim)
  595.                                         --send the victim the infected message
  596.                                         say(name .. infected_message)
  597.                                         --make the victim a zombie
  598.                                         registertimer(100, "makezombiedelay", {victim, false})
  599.                                 end
  600.                         end
  601.                 elseif mode == 2 then -- killed by guardians
  602.                         -- if this is true then a person who dies from the guardians will be infected
  603.                         if infect_on_guardians then
  604.                                 --check if the victim's team is the human team
  605.                                 if tonumber(team) and team ~= zombie_team then
  606.                                         --get the victim's name
  607.                                         local name = getname(victim)
  608.                                         --send the victim the infected message
  609.                                         say(name .. infected_message)
  610.                                         --make the victim a zombie
  611.                                         registertimer(100, "makezombiedelay", {victim, false})
  612.                                 end
  613.                         end
  614.                 elseif mode == 3 then -- killed by vehicle
  615.                 elseif mode == 4 then -- killed by another player
  616.                         --get the killer's team
  617.                         local killer_team = getteam(killer)
  618.                         -- check to see if a zombie killed them
  619.                         if tonumber(killer_team) and killer_team == zombie_team and tonumber(team) and team ~= zombie_team then
  620.                                 --get the victim's name
  621.                                 name = getname(victim)
  622.                                 --send the victim the infected message
  623.                                 say(name .. infected_message)
  624.                                 --make the victim a zombie
  625.                                 registertimer(100, "makezombiedelay", {victim, false})
  626.                                 privatesay(victim, zombie_message)
  627.                         elseif killer_team ~= zombie_team and team == zombie_team then
  628.                                 local hash = gethash(killer)
  629.                                 human_time[hash] = tonumber(human_time[hash]) + 10
  630.                         end
  631.                 elseif mode == 5 then -- betrayed
  632.                         --if this is true then a person who betrays will be infected
  633.                         if infect_on_betray then
  634.                                 --get the killer's team
  635.                                 local killer_team = getteam(killer)
  636.                                 --check if the killer is a human
  637.                                 if tonumber(killer_team) and killer_team ~= zombie_team then
  638.                                         --get the betrayer's name
  639.                                         name = getname(killer)
  640.                                         --send the betrayer the infected message
  641.                                         say(tostring(name) .. infected_message)
  642.                                         --make the betrayer a zombie
  643.                                         registertimer(100, "makezombiedelay", {killer, true})
  644.                                 end
  645.                         end
  646.                 elseif mode == 6 then -- suicide
  647.                         --if this is true then a person who suicides will be come a zombie
  648.                         if infect_on_suicide then
  649.                                 -- if they're human, make them zombies
  650.                                 if tonumber(team) and team ~= zombie_team then
  651.                                         --get the suicider's name
  652.                                         name = getname(victim)
  653.                                         --they're not going to end their life that easily
  654.                                         say(name .. infected_message)
  655.                                         --make the suicider a zombie
  656.                                         registertimer(100, "makezombiedelay", {victim, false})
  657.                                 end
  658.                         end
  659.                 end
  660.                 -- this next block of code gets rid of any weapons a zombie is holding
  661.                 if tonumber(team) and team == zombie_team then
  662.                         local m_player = getplayer(victim) --get the player's struct
  663.             if m_player == nil then
  664.                 return
  665.             end
  666.                         local m_object = getobject(readdword(m_player +  0x34)) -- get the player's object struct
  667.                         --there's an off chance that the player might be dead (phasor bug) can't hurt to add this check
  668.                         if m_object then
  669.                                 for i = 0,3 do -- loop through the player's weapons (primary to quartenary)
  670.                                         local weapID = readdword(m_object + 0x2F8 + i*4)
  671.                     if weapID then
  672.                                         local weap = getobject(weapID)
  673.                                         --make sure the weapon exists
  674.                                         if weap then
  675.                                                 --destroy their weapons
  676.                                                 registertimer(0, "destroyweaps", weapID)
  677.                                                 destroyobject(weapID)
  678.                                         end
  679.                     end
  680.                                 end
  681.                         end
  682.                 end
  683.         end
  684.         registertimer(200,"checkgamestate",victim)
  685. end
  686.  
  687. function OnTeamDecision(team)
  688.         local dest_team = join_team
  689.         if game_started then
  690.                 if cur_players == 0  then -- if no zombies make them human
  691.                         dest_team = human_team
  692.                 elseif cur_zombie_count > 0 and cur_human_count == 0 then
  693.                         dest_team = human_team
  694.                 end
  695.         end
  696.         return dest_team
  697. end
  698.  
  699. function OnTeamChange(player, old_team, dest_team, relevant)
  700.         if relevant == 1 or relevant == true then
  701.                 if not allow_change then
  702.                         privatesay(player, blockteamchange_message)
  703.                 elseif allow_change and old_team == zombie_team then
  704.                         -- this is so memory is updated for processing
  705.                         -- when relevant is 0 OnTeamChange is called once the changes
  706.                         -- have been committed
  707.                 setspeed(player, zombie_speed)
  708.                         ChangeTeam(player, 1)
  709.                 end
  710.                 -- we don't let people change team
  711.         elseif (relevant == 0 or relevant == false) and dest_team ~= team then -- we can't stop the person changing teams, bein done by an admin
  712.                 -- update team counts
  713.                 if dest_team == zombie_team then
  714.                         cur_human_count = cur_human_count - 1
  715.                         cur_zombie_count = cur_zombie_count + 1
  716.                 elseif dest_team ~= zombie_team then
  717.                         cur_human_count = cur_human_count + 1
  718.                         cur_zombie_count = cur_zombie_count - 1
  719.                 end
  720.                 -- they're allowed to change if the timer is active, if it is disable it
  721.                 if allow_change == true and dest_team == zombie_team then
  722.  
  723.                         allow_change = false
  724.                         --remove change timer
  725.                         if player_change_timer then
  726.                         removetimer(player_change_timer)
  727.                                 player_change_timer = nil
  728.                         end
  729.  
  730.                         say(timer_team_change_msg)
  731.                 end
  732.                 -- check if the game has started yet
  733.                 if game_started == true then
  734.                         -- set attributes
  735.                         if dest_team == zombie_team then
  736.                                 makezombie(player, false)
  737.                         elseif dest_team ~= zombie_team then
  738.                                 makehuman(player, false)
  739.                         end
  740.  
  741.                         registertimer(0,"checkgamestate",player)
  742.                 end
  743.                 -- update team withf
  744.                 local thisHash = gethash(player)
  745.                 hash_table[thisHash] = dest_team
  746.                
  747.         end
  748.         return allow_change
  749. end
  750.  
  751. function OnDamageApplication(receiving, causing, tagid, hit, backtap)
  752.     if backtap then
  753.         if causing and receiving then
  754.                 local r_object = getobject(receiving)
  755.                 local c_object = getobject(causing)
  756.             if r_object and c_object then
  757.                         local causer = objectaddrtoplayer(c_object)
  758.                         local receiver = objectaddrtoplayer(r_object)
  759.                         if causer and receiver then
  760.                                 local c_team = getteam(causer)
  761.                         local r_team = getteam(receiver)
  762.                                 if c_team == zombie_team and r_team == human_team then
  763.                                         privatesay(causer, zombie_backtap_message)
  764.                                         privatesay(receiver, string.format(human_backtap_message,getname(causer)))
  765.                                 end
  766.                 end
  767.                 end
  768.         end
  769.         end
  770. end
  771.  
  772. function OnDamageLookup(receiver, causer, mapId, tagdata)
  773.  
  774.     local tagname = gettaginfo(mapId)
  775.     if causing and receiving then
  776.         local c_object = getobject(causing)
  777.         local r_object = getobject(receiving)
  778.         if c_object and r_object then
  779.             local causer = objectaddrtoplayer(c_object)
  780.             local receiver = objectaddrtoplayer(r_object)
  781.             if causer and receiver then
  782.                 local c_team = getteam(causer)
  783.                 local r_team = getteam(receiver)
  784.                 if not team_play and r_team == c_team and causer ~= receiver then
  785.                         return false
  786.                 end
  787.                 if c_team then
  788.                     local tagname, tagtype = gettaginfo(mapId)
  789.                     if string.find(tagname, "melee") then
  790.                         odl_multiplier(500.0)
  791.                     end
  792.                     if c_team ~= zombie_team then
  793.                         if cur_last_man then
  794.                             modifier = lastman_dmgmodifier
  795.                         else
  796.                             modifier = human_dmgmodifier
  797.                         end
  798.                         if tagtype == "jpt!" then
  799.                             odl_multiplier(modifier)
  800.                         end
  801.                     elseif c_team == zombie_team then
  802.                         if not team_play and c_team == r_team and causer ~= receiver then
  803.                             privatesay(causer, "Do not hit your own team.")
  804.                             return false
  805.                         end
  806.                     end
  807.                 end
  808.             end
  809.         end
  810.     end
  811.    
  812.     local tagname = gettaginfo(mapId)
  813.     local rplayer, cplayer = nil, nil
  814.     if receiver ~= nil then
  815.         if getobject(receiver) then
  816.             if tonumber(receiver) then
  817.                 local rplayer = objectidtoplayer(receiver)
  818.             end
  819.         end
  820.     end
  821.     if causer ~= nil then
  822.         if getobject(causer) then
  823.             if tonumber(causer) then
  824.                 local cplayer = objectidtoplayer(causer)
  825.             end
  826.         end
  827.     end
  828.    
  829.     if cplayer and rplayer ~= nil then
  830.         if getteam(cplayer) == getteam(rplayer) then
  831.             return false
  832.         end
  833.     end
  834.    
  835.     if tagname == "weapons\\plasma rifle\\bolt" then
  836.         local player = objectidtoplayer(causer)
  837.         if player then
  838.             local m_causer = getobject(causer)
  839.             local m_receiver = getobject(receiver)
  840.             if m_receiver and m_causer then
  841.                 local mapId = readdword(m_receiver)
  842.                 local tagname, tagtype = gettaginfo(mapId)
  843.                 if tagtype == "vehi" then
  844.                     if gravity[player] then
  845.                         gravity[player] = nil
  846.                         writebit(m_receiver + 0x10, 5, 0)
  847.                         local x_aim = readfloat(m_causer, 0x230)
  848.                         local y_aim = readfloat(m_causer, 0x234)
  849.                         local z_aim = readfloat(m_causer, 0x238)
  850.                         local vel = 1
  851.                         writefloat(m_receiver, 0x68, vel * math.sin(x_aim))
  852.                         writefloat(m_receiver, 0x6C, vel * math.sin(y_aim))
  853.                         writefloat(m_receiver, 0x70, vel * math.sin(z_aim))
  854.                         registertimer(10, "ActiveVehicle", {receiver, player})
  855.                     else
  856.                         local bool
  857.                        
  858.                         for p,r in pairs(gravity) do
  859.                             if r == receiver then
  860.                                 bool = true
  861.                             end
  862.                         end
  863.                        
  864.                         if not bool then
  865.                             gravity[player] = receiver
  866.                             vehicles[receiver] = player
  867.                             writebit(m_receiver + 0x10, 5, 0)
  868.                             local m_player = getplayer(player)
  869.                             local xy_aim = readfloat(m_player, 0x138)
  870.                             local z_aim = readfloat(m_player, 0x13C)
  871.                             local dist = 4
  872.                             local x = readfloat(m_causer, 0x5C)
  873.                             local y = readfloat(m_causer, 0x60)
  874.                             local z = readfloat(m_causer, 0x64)
  875.                             writefloat(m_receiver, 0x5C, x + dist * math.cos(xy_aim))
  876.                             writefloat(m_receiver, 0x60, y + dist * math.sin(xy_aim))
  877.                             writefloat(m_receiver, 0x64, z + dist * math.sin(z_aim) + 0.5)
  878.                             writefloat(m_receiver, 0x68, 0)
  879.                             writefloat(m_receiver, 0x6C, 0)
  880.                             writefloat(m_receiver, 0x70, 0)
  881.                             local angular_velocity_x = readfloat(m_receiver, 0x8C)
  882.                             local angular_velocity_y = readfloat(m_receiver, 0x90)
  883.                             local angular_velocity_z = readfloat(m_receiver, 0x94)
  884.                             writefloat(m_receiver, 0x8C, .2)
  885.                             writefloat(m_receiver, 0x90, .3)
  886.                             writefloat(m_receiver, 0x94, .05)
  887.                         end
  888.                     end
  889.                 end
  890.             end
  891.         end
  892.    
  893.     elseif tagname == "globals\\vehicle_collision" then
  894.    
  895.         if vehicles[causer] then
  896.             local m_player = getplayer(vehicles[causer])
  897.             if m_player then
  898.                 local objId = readdword(m_player, 0x34)
  899.                 applydmgtag(receiver, gettagid("jpt!", "weapons\\rocket launcher\\explosion"), 500, objId)
  900.                 return false
  901.             end
  902.         end
  903.     end
  904. end
  905.  
  906.  
  907. function OnVehicleEntry(player, m_vehicleId, seat, mapId, relevant)
  908.         if game_started and relevant == true then
  909.         if getplayer(player) == nil then
  910.             return nil
  911.         end
  912.                 local team = getteam(player)
  913.                 if (team == zombie_team and zombies_allowed_in_vehis) or (team ~= zombie_team and humans_allowed_in_vehis) then
  914.                         return true
  915.                 end
  916.         end
  917.         return false
  918. end
  919.  
  920. function OnClientUpdate(player)
  921.  
  922.     local m_object = getplayerobjectid(player)
  923.     local flashlight = readbyte(getobject(m_object), 0x206)
  924.    
  925.     if flashlight == 8 then
  926.         OnFlashlightToggle(player)
  927.     end
  928.         local m_player = getplayer(player)
  929.     if m_player == nil then
  930.         return
  931.     end
  932.     local m_objectId = getplayerobjectid(player)
  933.     if m_objectId == nil then
  934.         return
  935.     end
  936.         local m_object = getobject(m_objectId)
  937.         if m_object then
  938.         local hash = gethash(player)
  939.                 local team = getteam(player)
  940.                 if team == zombie_team and oddball_or_flag then
  941.                         local shooting = readbit(m_object + 0x209, 4)
  942.                         local nading2 = readbit(m_object + 0x209, 2)
  943.                         local nading = readbit(m_object + 0x209, 3)
  944.                         if shooting == true or nading == true then
  945.                                 weapID = flagball_weap[player]
  946.                                 if m_player then
  947.                                         if weapID then
  948.                                                 if getobject(weapID) then
  949.                                                         assignweapon(player, weapID)
  950.                                                 end
  951.                                         end
  952.                                 end
  953.                         end
  954.                 end
  955.                 -- this block of code sets the player's score according to what it should be.
  956.                 if tonumber(human_time[hash]) then
  957.                         if gametype == "KOTH" then
  958.                                 local time = timetoword(tonumber(human_time[hash])*30)
  959.                                 local hill_time = readword(m_player, 0xC4)
  960.                                 if tonumber(hill_time) then
  961.                                         writewordsigned(m_player, 0xC4, time)
  962.                                 end
  963.                         elseif gametype == "CTF" then
  964.                                 local player_score = readdword(m_player + 0xC8)
  965.                                 if tonumber(player_score) then
  966.                                         writedwordsigned(m_player, 0xC8, human_time[hash])
  967.                                 end
  968.                         elseif gametype == "Slayer" then
  969.                                 writedwordsigned(slayer_globals, 0x40 + player * 4, human_time[hash])
  970.                         end
  971.                 else
  972.                         human_time[hash] = 0
  973.                 end
  974.         end
  975.         --continually write 0 to these addresses
  976.         if gametype == "KOTH" then
  977.                 writedword(team_koth_score_array + 0x0, 0)
  978.                 writedword(team_koth_score_array + 0x4, 0)
  979.         elseif gametype == "CTF" then
  980.                 writedword(ctf_globals + 0x10, 0)
  981.                 writedword(ctf_globals + 0x14, 0)
  982.         elseif gametype == "Slayer" then
  983.                 writedword(slayer_globals + 0x0, 0)
  984.                 writedword(slayer_globals + 0x4, 0)
  985.         end
  986.         --this makes sure that people won't camp in unreachable places.
  987.         local x,y,z = getobjectcoords(m_objectId)
  988.         local team = getteam(player)
  989.         if map == "damnation" and team ~= zombie_team then
  990.                 if object_in_sphere(m_objectId, 1.99, 9.03, 7.82, 5) then
  991.                         kill(player)
  992.                         privatesay(player, "Do not camp in unreachable spots!")
  993.                 elseif object_in_sphere(m_objectId, 11.4, 11.21, 10.51, 5) then
  994.                         kill(player)
  995.                         privatesay(player, "Do not camp in unreachable spots!")
  996.                 end
  997.         elseif map == "icefields" and team ~= zombie_team then
  998.                 if object_in_sphere(m_objectId, -31.27, 42.44, 11.48, 5) then
  999.                         kill(player)
  1000.                         privatesay(player, "Do not camp in unreachable spots!")
  1001.                 elseif object_in_sphere(m_objectId, -71.29, 70.83, 6.67, 10) then
  1002.                         kill(player)
  1003.                         privatesay(player, "Do not camp in unreachable spots!")
  1004.                 elseif object_in_sphere(m_objectId, -17.28, 19.63, 11.55, 5) then
  1005.                         kill(player)
  1006.                         privatesay(player, "Do not camp in unreachable spots!")
  1007.                 end
  1008.         end
  1009.        
  1010.     local vehiId = gravity[player]
  1011.     if vehiId then
  1012.         local m_player = getplayer(player)
  1013.         local objId = readdword(m_player, 0x34)
  1014.         local m_object = getobject(objId)
  1015.         local m_vehicle = getobject(vehiId)
  1016.         local x_aim = readfloat(m_object, 0x230)
  1017.         local y_aim = readfloat(m_object, 0x234)
  1018.         local z_aim = readfloat(m_object, 0x238)
  1019.         local x = readfloat(m_object, 0x5C)
  1020.         local y = readfloat(m_object, 0x60)
  1021.         local z = readfloat(m_object, 0x64)
  1022.         local dist = 4
  1023.         writefloat(m_vehicle, 0x5C, x + dist * math.sin(x_aim))
  1024.         writefloat(m_vehicle, 0x60, y + dist * math.sin(y_aim))
  1025.         writefloat(m_vehicle, 0x64, z + dist * math.sin(z_aim) + 0.5)
  1026.         writefloat(m_vehicle, 0x68, 0)
  1027.         writefloat(m_vehicle, 0x6C, 0)
  1028.         writefloat(m_vehicle, 0x70, 0.01285)
  1029.     end
  1030. end
  1031.  
  1032. -- called when all players are zombies (no shit)
  1033. function all_players_zombies(player)
  1034.         -- if there is a last man, store their hash
  1035.         if player ~= nil and player ~= -1 and getplayer(player) then
  1036.                 last_man_hash = gethash(player)
  1037.                 -- write the hash to file
  1038.                 local file = io.open("lasthash_" .. processid .. ".tmp", "w")
  1039.                 if (file ~= nil) then
  1040.                         file:write(tostring(last_man_hash))
  1041.                         file:close()
  1042.                 end
  1043.         end
  1044.         -- move onto the next map
  1045.         svcmd("sv_map_next")
  1046. end
  1047.  
  1048. --basically this timer assigns the tertiary and quarternary weapons to zombies if specified at the top
  1049. --this is needed since onweaponassignment isn't called for tertiary and quartenary weapons
  1050. function AssignLeftoverZombieWeapons(id, count, table)
  1051.         local player = table[1]
  1052.         local clipcount = table[2]
  1053.         local ammocount = table[3]
  1054.         local batterycount = table[4]
  1055.     if getplayer(player) == nil then
  1056.         return
  1057.     end
  1058.         local m_objectId = getplayerobjectid(player)
  1059.         if m_objectId then
  1060.                 local m_object = getobject(m_objectId)
  1061.                 if m_object then
  1062.                         local m_weaponId = createobject(gettagid("weap", zombie_weapon[3]), 0, 0, false, 5, 5, 2)
  1063.                         if m_weaponId then
  1064.                                 local m_weapon = getobject(m_weaponId)
  1065.                                 if m_weapon then
  1066.                                         -- set the ammo
  1067.                                         writeword(m_weapon, 0x2B6, ammocount)
  1068.                                         writeword(m_weapon, 0x2B8, clipcount)
  1069.                                         writefloat(m_weapon, 0x240, math.abs(batterycount - 1))
  1070.                                         -- force it to sync
  1071.                                         updateammo(m_weaponId)
  1072.                                 end
  1073.                         end
  1074.                         --make sure the script user isn't retarded so we don't get errors
  1075.                         if zombie_weapon[4] and zombie_weapon[4] ~= "" then
  1076.                                 --create the quarternary weapon
  1077.                                 local m_weaponId = createobject(gettagid("weap", zombie_weapon[4]), 0, 0, false, 5, 5, 2)
  1078.                                 --make sure createobject didn't screw up
  1079.                                 if m_weaponId then
  1080.                                         --assign the weapon to the player
  1081.                                         assignweapon(player, m_weaponId)
  1082.                                         --make sure we can safely set the ammo
  1083.                                         local m_weapon = getobject(m_weaponId)
  1084.                                         if m_weapon then
  1085.                                                 -- set the ammo
  1086.                                                 writeword(m_weapon, 0x2B6, ammocount)
  1087.                                                 writeword(m_weapon, 0x2B8, clipcount)
  1088.                                                 writefloat(m_weapon, 0x240, math.abs(batterycount - 1))
  1089.                                                 -- force it to sync
  1090.                                                 updateammo(m_weaponId)
  1091.                                         end
  1092.                                 end
  1093.                         end
  1094.                 end
  1095.         end
  1096.         return false
  1097. end
  1098.  
  1099. --this function is called when a gametype is 'custom'
  1100. --this function will delete the player's weapons and reassign the weapon's specified at the top
  1101. function AssignZombieWeapons(id, count, table)
  1102.         local player = table[1]
  1103.         local clipcount = table[2]
  1104.         local ammocount = table[3]
  1105.         local batterycount = table[4]
  1106.     if getplayer(player) == nil then
  1107.         return
  1108.     end
  1109.     local m_objectId = getplayerobjectid(player)
  1110.         if m_objectId then
  1111.                 local m_object = getobject(m_objectId)
  1112.                 if m_object then
  1113.                         --count is increased everytime the timer is called
  1114.                         if count == 1 then
  1115.                                 for i = 0,3 do -- this is used to remove any weapons they already have
  1116.                                         local m_weaponId = readdword(m_object + 0x2F8 + i*4)
  1117.                                         if m_weaponId then
  1118.                                                 local m_weapon = getobject(m_weaponId)
  1119.                                                 if m_weapon then
  1120.                                                         destroyobject(m_weaponId)
  1121.                                                 end
  1122.                                         end
  1123.                                 end
  1124.                         end
  1125.                         local i = count
  1126.                         if zombie_weapon and zombie_weapon[i] and zombie_weapon[i] ~= "" then
  1127.                                 local m_weaponId = createobject(gettagid("weap", zombie_weapon[i]), 0, 0, false, 1, 1, 1)
  1128.                                 if m_weaponId ~= 0xFFFFFFFF then
  1129.                                         assignweapon(player, m_weaponId)
  1130.                                         if oddball_or_flag then
  1131.                                                 flagball_weap[player] = m_weaponId
  1132.                                         else
  1133.                                                 local m_weapon = getobject(m_weaponId)
  1134.                                                 if m_weapon then
  1135.                                                         -- set the ammo
  1136.                                                         writeword(m_weapon, 0x2B6, ammocount)
  1137.                                                         writeword(m_weapon, 0x2B8, clipcount)
  1138.                                                         writefloat(m_weapon, 0x240, 1)
  1139.                                                         -- force it to sync
  1140.                                                         updateammo(m_weaponId)
  1141.                                                 end
  1142.                                         end
  1143.                                 end
  1144.                         end
  1145.                         if count < 4 then return 1 else return 0 end
  1146.                 end
  1147.         end
  1148.         return false
  1149. end
  1150.  
  1151. function ChangeTeam(player, forcekill, team, updatecounters)
  1152.         if player and forcekill and team then
  1153.                 changeteam(player, forcekill, team)
  1154.         elseif player and forcekill then
  1155.                 changeteam(player, forcekill)
  1156.         else
  1157.                 changeteam(player, 1)
  1158.         end
  1159.         if team ~= cur_team then
  1160.                 OnFFATeamChange(player, cur_team, team, updatecounters)
  1161.         end
  1162. end
  1163.  
  1164. function checkgamestate(id, count, player)
  1165.         -- check if the game has started yet
  1166.         if game_started == true then
  1167.                 local zombie_count = getzombiesize()
  1168.                 local human_count = gethumansize()
  1169.                 -- if no humans, but there are zombies, end the game
  1170.                 if human_count == 0 and zombie_count > 0 then
  1171.                         all_players_zombies(player)
  1172.                 elseif human_count > 1 and zombie_count == 0 then
  1173.                         noZombiesLeft()
  1174.                 elseif human_count == 1 and zombie_count > 0 and not cur_last_man then
  1175.                         onlastman()
  1176.                 elseif cur_last_man and zombie_count == 0 then
  1177.                         makehuman(cur_last_man, false)
  1178.                         cur_last_man = nil
  1179.                 elseif cur_last_man and human_count > 1 then
  1180.                         if gametype == "Slayer" then takenavsaway() end
  1181.                         makehuman(cur_last_man, false)
  1182.                         cur_last_man = nil
  1183.                 end
  1184.         end
  1185.         return false
  1186. end
  1187.  
  1188. -- this function searches through current players and selects a random one
  1189. function ChooseRandomPlayer(excludeTeam)
  1190.         -- loop through all 16 possible spots and add to table
  1191.         local t = getplayertable(excludeTeam)
  1192.         if #t > 0 then
  1193.                 -- generate a random number that we will use to select a player
  1194.                 local r = getrandomnumber(1, #t+1)
  1195.                 return t[r]
  1196.         else
  1197.                 return nil
  1198.         end
  1199. end
  1200.  
  1201. --I made this function because there's a bug with destroyobject in phasor version 058X
  1202. --basically all it does is move the objects under the map lol
  1203. function destroyweaps(id, count, m_weaponId)
  1204.         if m_weaponId then
  1205.                 local m_weapon = getobject(m_weaponId)
  1206.                 if m_weapon then
  1207.                         writefloat(m_weapon + 0x5C, readfloat(m_weapon + 0x5C) - 1000)
  1208.                 end
  1209.         end
  1210.         return false
  1211. end
  1212.  
  1213. function DelayWriteCoords(id, count)
  1214.         writefloat(readdword(ctf_globals + 0x0), 0x8, readfloat(readdword(ctf_globals + 0x0), 0x8) - 100)
  1215.         writefloat(readdword(ctf_globals + 0x4), 0x8, readfloat(readdword(ctf_globals + 0x4), 0x8) - 100)
  1216.         return false
  1217. end
  1218.  
  1219. function endian(address, offset, length)
  1220.         local data_table = {}
  1221.         local data = ""
  1222.         for i=0,length do
  1223.                 local hex = string.format("%X", readbyte(address + offset + i))
  1224.                 if tonumber(hex, 16) < 16 then
  1225.                         hex = 0 .. hex
  1226.                 end
  1227.                 table.insert(data_table, hex)
  1228.         end
  1229.         for k,v in pairs(data_table) do
  1230.                    data = v .. data
  1231.         end
  1232.         return data
  1233. end
  1234.  
  1235. --gets the number of alpha zombies
  1236. function getalphacount()
  1237.         -- recalculate how many "alpha" zombies there are
  1238.         if zombie_count < 1 then
  1239.                 alpha_zombie_count = round((cur_players * zombie_count) + 0.5)
  1240.         else
  1241.                 alpha_zombie_count = zombie_count
  1242.         end
  1243.         if alpha_zombie_count > max_zombie_count then
  1244.                 alpha_zombie_count = max_zombie_count
  1245.         end
  1246.         return alpha_zombie_count
  1247. end
  1248.  
  1249. function GetGameAddresses(game)
  1250.         if game == "PC" then
  1251.                 map_pointer = 0x63525c
  1252.                 ctf_globals = 0x639B98
  1253.                 slayer_globals = 0x63A0E8
  1254.                 oddball_globals = 0x639E58
  1255.                 gametype_base = 0x671340
  1256.                 ctf_flag_stolen = 0x639BB4
  1257.                 ball_holder_addr = 0x639F1C
  1258.                 team_oddball_score_array = 0x639E9C
  1259.                 oddball_score_array = 0x639E5C
  1260.                 koth_move_timer = 0x639D78
  1261.                 team_koth_score_array = 0x639BD0
  1262.                 team_race_score_array = 0x63A028
  1263.                 machine_pointer = 0x745BA0
  1264.                 flag_respawn_addr = 0x488A7E
  1265.                 inhill_addr = 0x639C50
  1266.         else
  1267.                 map_pointer = 0x5B927C
  1268.                 ctf_globals = 0x5BDBB8
  1269.                 slayer_globals = 0x5BE108
  1270.                 oddball_globals = 0x5BDEB8
  1271.                 gametype_base = 0x5F5498
  1272.                 ctf_flag_stolen = 0x5BD8B4
  1273.                 ball_holder_addr = 0x5BDF3C
  1274.                 team_oddball_score_array = 0x5BDE9C
  1275.                 oddball_score_array = 0x5BDE5C
  1276.                 koth_move_timer = 0x5BDD78
  1277.                 team_koth_score_array = 0x5BDBF0
  1278.                 team_race_score_array = 0x5BD028
  1279.                 machine_pointer = 0x6C7980
  1280.                 flag_respawn_addr = 0x4638EE
  1281.                 inhill_addr = 0x5BDC70
  1282.         end
  1283. end
  1284.  
  1285. function gethumansize()
  1286.         local size = 0
  1287.         for i = 0,15 do
  1288.                 if getplayer(i) then
  1289.                         local team = getteam(i)
  1290.                         if team ~= zombie_team then
  1291.                                 size = size + 1
  1292.                         end
  1293.                 end
  1294.         end
  1295.         return size
  1296. end
  1297.  
  1298. function getplayertable(excludeTeam)
  1299.         local players = ""
  1300.         for i=0,15 do
  1301.                 if getplayer(i) and getteam(i) ~= excludeTeam then
  1302.                         if players == nil then
  1303.                                 players = i .. ","
  1304.                         else
  1305.                                 players = players .. i .. ","
  1306.                         end
  1307.                 end
  1308.         end
  1309.         return tokenizestring(players, ",")
  1310. end
  1311.  
  1312. function getzombiesize()
  1313.         local size = 0
  1314.         for i = 0,15 do
  1315.                 if getplayer(i) then
  1316.                         local team = getteam(i)
  1317.                         if team == zombie_team then
  1318.                                 size = size + 1
  1319.                         end
  1320.                 end
  1321.         end
  1322.         return size
  1323. end
  1324.  
  1325. function HumanTimer(id, count)
  1326.         if map_reset_boolean == true then
  1327.                 map_reset_boolean = false
  1328.         end
  1329.         if game_started == true then
  1330.                 for i = 0,15 do
  1331.                         if getplayer(i) then
  1332.                                 local m_player = getplayer(i)
  1333.                                 local hash = gethash(i)
  1334.                                 local team = readbyte(m_player + 0x20)
  1335.                                 local m_objectId = getplayerobjectid(i)
  1336.                                 if m_objectId then
  1337.                                         local m_object = getobject(m_objectId)
  1338.                                         if team ~= zombie_team then
  1339.                                                 if m_object then
  1340.                                                         if tonumber(human_time[hash]) then
  1341.                                                                 human_time[hash] = tonumber(human_time[hash]) + 1
  1342.                                                         else
  1343.                                                                 human_time[hash] = 1
  1344.                                                         end
  1345.                                                 end
  1346.                                         end
  1347.                                 end
  1348.                                 if gametype == "KOTH" then
  1349.                                         local m_objectId = getplayerobjectid(i)
  1350.                                         if m_objectId then
  1351.                                                 local m_object = getobject(m_objectId)
  1352.                                                 if PlayerInHill(i) == true and m_object then
  1353.                                                         if inhill_time[hash] == nil then
  1354.                                                                 inhill_time[hash] = 0
  1355.                                                                 writebit(m_object, 0x10, 7, 1)
  1356.                                                                 if team ~= zombie_team then
  1357.                                                                         say(getname(i) .. " must leave the hill in 10 seconds or they will be infected!")
  1358.                                                                 else
  1359.                                                                         say(getname(i) .. " must leave the hill in 10 seconds or they will be killed!")
  1360.                                                                 end
  1361.                                                         elseif inhill_time[hash] >= 10 then
  1362.                                                                 if team ~= zombie_team then
  1363.                                                                         makezombie(i, true)
  1364.                                                                         say(getname(i) .. in_hill_too_long_msg)
  1365.                                                                 else
  1366.                                                                         kill(i)
  1367.                                                                         say(getname(i) .. " has been killed because they were in the hill too long!")
  1368.                                                                 end
  1369.                                                                 inhill_time[hash] = nil
  1370.                                                         elseif team ~= zombie_team then
  1371.                                                                 privatesay(i, "You have " .. math.abs(inhill_time[hash] - 10) .. " seconds to leave the hill!")
  1372.                                                                 inhill_time[hash] = inhill_time[hash] + 1
  1373.                                                         end
  1374.                                                 elseif m_object then
  1375.                                                         inhill_time[hash] = nil
  1376.                                                         writebit(m_object, 0x10, 7, 0)
  1377.                                                 end
  1378.                                         end
  1379.                                 end
  1380.                         end
  1381.                 end
  1382.         end
  1383.         return true
  1384. end
  1385.  
  1386. function invisCrouch(id, count)
  1387.         if not zombies_invisible_on_crouch and not humans_invisible_on_crouch then crouch_timer = nil return false end
  1388.         for i = 0,15 do
  1389.                 if getplayer(i) then
  1390.                         local m_objectId = getplayerobjectid(i)
  1391.                         if m_objectId then
  1392.                                 local m_object = getobject(m_objectId)
  1393.                                 if m_object then
  1394.                                         local obj_crouch = readbyte(m_object + 0x2A0)
  1395.                                         if obj_crouch == 3 then
  1396.                                                 local team = readbyte(getplayer(i) + 0x20)
  1397.                                                 if (team == zombie_team and zombies_invisible_on_crouch) or (team ~= zombie_team and humans_invisible_on_crouch) then
  1398.                                                         applycamo(i, time_invis)
  1399.                                                 end
  1400.                                         end
  1401.                                 end
  1402.                         end
  1403.                 end
  1404.         end
  1405.         return true
  1406. end
  1407.  
  1408. --called when a player needs to be a human
  1409. function makehuman(player, forcekill, updatecounters)
  1410.     if getplayer(player) then
  1411.         -- change the player's speed
  1412.         setspeed(player, human_speed)
  1413.         local team = getteam(player)
  1414.         if team == zombie_team then
  1415.                 if team_play then
  1416.                         ChangeTeam(player, forcekill)
  1417.                 else
  1418.                         ChangeTeam(player, forcekill, nil, updatecounters)
  1419.                 end
  1420.         end
  1421.     end
  1422. end
  1423.  
  1424. --called when a player needs to be made a zombie
  1425. function makezombie(player, forcekill, updatecounters)
  1426.     if getplayer(player) then
  1427.         -- change the player's speed
  1428.         setspeed(player, zombie_speed)
  1429.         local team = getteam(player)
  1430.         if team ~= zombie_team then
  1431.                 if team_play then
  1432.                         ChangeTeam(player, forcekill)
  1433.                 else
  1434.                         ChangeTeam(player, forcekill, nil, updatecounters)
  1435.                 end
  1436.             end
  1437.     end
  1438. end
  1439.  
  1440. function makezombiedelay(id, count, arg)
  1441.         makezombie(arg[1], arg[2])
  1442. end
  1443.  
  1444. function NewGameTimer(id, count)
  1445.         if count == 10 then
  1446.                 say("The game is starting...")
  1447.                 if cur_players ~= 0 then
  1448.                         local newgame_zombie_count = 0
  1449.                         -- by default make all players human
  1450.                         for x=0,15 do
  1451.                                 if getplayer(x) then
  1452.                                         local thisTeam = getteam(x)
  1453.                                         local hash = gethash(x)
  1454.                                         if thisTeam then
  1455.                                                 if thisTeam == zombie_team then
  1456.                                                         ChangeTeam(x, 0)
  1457.                                                 end
  1458.                                                 human_time[hash] = 0
  1459.                                         end
  1460.                                 end
  1461.                         end
  1462.                         local possible_count = cur_players
  1463.                         -- make players zombie until the count has been met
  1464.                         local finalZombies = 0
  1465.                         if zombie_count >= 1 then
  1466.                                 finalZombies = zombie_count
  1467.                         else
  1468.                                 finalZombies = round((possible_count * zombie_count) + 0.5)
  1469.                         end
  1470.                         -- make last man zombie
  1471.                         local last_man_index = -1
  1472.                         -- check if the last man is to be made a zombie
  1473.                         -- if so find who was last man
  1474.                         if last_man_next_zombie == true and cur_players > 1 then
  1475.                                 -- loop through all hashes and check if any match the last man
  1476.                                 for i=0,15 do
  1477.                                         if getplayer(i) then
  1478.                                                 local hash = gethash(i)
  1479.                                                 if last_man_hash == hash then
  1480.                                                         -- make them a zombie and save their info
  1481.                                                         makezombie(i, true)
  1482.                                                         newgame_zombie_count = 1
  1483.                                                         last_man_index = i
  1484.  
  1485.                                                         break
  1486.                                                 end
  1487.                                         end
  1488.                                 end
  1489.                         end
  1490.                         -- reset last man
  1491.                         last_man_hash = 0
  1492.                         if finalZombies == cur_players then -- if 0 players they will be human
  1493.                                 finalZombies = finalZombies - 1
  1494.                         elseif finalZombies > possible_count then -- fix the count
  1495.                                 finalZombies = possible_count
  1496.                         elseif max_zombie_count and finalZombies > max_zombie_count then -- cap the zombie count
  1497.                                 finalZombies = max_zombie_count
  1498.                         elseif finalZombies < 0 then
  1499.                                 finalZombies = 0
  1500.                         end
  1501.                         -- set counters such that ChangeTeam wont end the game
  1502.                         cur_zombie_count = 16
  1503.                         cur_human_count = 16
  1504.                         -- loop through the players, randomly selecting ones to become
  1505.                         -- zombies
  1506.                         while (newgame_zombie_count < finalZombies) do
  1507.                                 -- randomly choose a player
  1508.                                 local newzomb = ChooseRandomPlayer(zombie_team)
  1509.                                 if newzomb == nil then
  1510.                                         break
  1511.                                 elseif newzomb ~= last_man_index then
  1512.                                         makezombie(newzomb, true)
  1513.                                         newgame_zombie_count = newgame_zombie_count + 1
  1514.                                 end
  1515.                         end
  1516.                         -- fix the team counters
  1517.                         cur_zombie_count = newgame_zombie_count
  1518.                         cur_human_count = cur_players - finalZombies
  1519.                         -- reset the map
  1520.                         svcmd("sv_map_reset")
  1521.                         -- loop through and tell players which team they're on
  1522.                         for i=0,15 do
  1523.                                 if getplayer(i) then
  1524.                                         local pteam = getteam(i)
  1525.                                         if pteam then
  1526.                                                 -- check if they're a zombie
  1527.                                                 if pteam == zombie_team then
  1528.                                                         privatesay(i, zombie_message)
  1529.                                                 else
  1530.                                                         if not team_play then makehuman(i) end
  1531.                                                         privatesay(i, human_message)
  1532.                                                 end
  1533.                                         end
  1534.                                 end
  1535.                         end
  1536.                 end
  1537.                 game_started = true
  1538.                 new_game_timer = nil
  1539.                 return false -- remove timer
  1540.         else
  1541.                 say("The game will start in " .. 10 - count .. " second(s).")
  1542.                 return true -- keep timer
  1543.         end
  1544. end
  1545.  
  1546. -- there are no zombies left
  1547. function noZombiesLeft()
  1548.     if team_play then
  1549.         if player_change_timer == nil then
  1550.                 allow_change = true
  1551.                 say(nozombiesleftmessage)
  1552.             player_change_timer = registertimer(1000, "PlayerChangeTimer")
  1553.         end
  1554.     else
  1555.                 -- pick a human and make them zombie.
  1556.                 local newZomb = ChooseRandomPlayer(zombie_team)
  1557.                 if newZomb then
  1558.                         makezombie(newZomb, true)
  1559.                         privatesay(newZomb, zombie_message)
  1560.                 end
  1561.     end
  1562. end
  1563.  
  1564. --called to check if an object is in a virtual sphere
  1565. --i use this to check if a person is in a unreachable spot.
  1566. function object_in_sphere(m_objectId, X, Y, Z, R)
  1567.         local Pass = false
  1568.         if getobject(m_objectId) then
  1569.                 local x,y,z = getobjectcoords(m_objectId)
  1570.                 if (X - x)^2 + (Y - y)^2 + (Z - z)^2 <= R then
  1571.             Pass = true
  1572.         end
  1573.     end
  1574.     return Pass
  1575. end
  1576.  
  1577. function OnFFATeamChange(player, cur_team, dest_team, updatecounters)
  1578.         -- update team counts
  1579.         if not updatecounters then
  1580.                 if dest_team == zombie_team then
  1581.                         cur_human_count = cur_human_count - 1
  1582.                         cur_zombie_count = cur_zombie_count + 1
  1583.                 elseif dest_team ~= zombie_team then
  1584.                         cur_human_count = cur_human_count + 1
  1585.                         cur_zombie_count = cur_zombie_count - 1
  1586.                 end
  1587.         end
  1588.         -- check if the game has started yet
  1589.         if game_started == true then
  1590.                 registertimer(0,"checkgamestate",player)
  1591.         end
  1592.         -- update team with
  1593.         local thisHash = gethash(player)
  1594.         hash_table[thisHash] = dest_team
  1595. end
  1596.  
  1597. -- called when a last man exists
  1598. function onlastman()
  1599.         -- lookup the last man
  1600.         for x=0,15 do
  1601.                 if getplayer(x) then
  1602.                         local team = getteam(x)
  1603.                         if team ~= zombie_team and team then
  1604.                                 cur_last_man = x
  1605.                                 if gametype == "Slayer" then WriteNavsToZombies(x) end
  1606.                                 -- give the last man speed and extra ammo
  1607.                                 setspeed(x, lastman_speed)
  1608.                                 -- find the last man's weapons
  1609.                                 local m_player = getplayer(x)
  1610.                                 if m_player then
  1611.                                         local m_ObjId = readdword(m_player + 0x34)
  1612.                     if m_ObjId then
  1613.                                         -- find the player's object
  1614.                                         local m_object = getobject(m_ObjId)
  1615.                                         if m_object then
  1616.                                                 if lastman_invulnerable and lastman_invulnerable > 0 then
  1617.                                                         -- setup the invulnerable timer
  1618.                                                         writebit(m_object + 0x10, 7, 1)
  1619.                                                         registertimer(lastman_invulnerable * 1000, "RemoveLastmanProtection", m_object)
  1620.                                                 end
  1621.                                                 -- give all weapons 600 ammo
  1622.                                                 for i=0,3 do
  1623.                                                         local m_weaponId = readdword(m_object + 0x2F8 + (i*4))
  1624.                                                         if m_weaponId ~= 0xffffffff then
  1625.                                                                 -- get the weapons memory address
  1626.                                                                 local m_weapon = getobject(m_weaponId)
  1627.                                                                 if m_weapon then
  1628.                                                                         -- set the ammo
  1629.                                                                         writeword(m_weapon, 0x2B6, 600)
  1630.                                                                 end
  1631.                                                         end
  1632.                                                 end
  1633.                                         end
  1634.                                     end
  1635.                 end
  1636.                         end
  1637.                 end
  1638.         end
  1639.         if cur_last_man then
  1640.                 local lastman_name = getname(cur_last_man)
  1641.                 local msg = string.format(lastman_message, tostring(lastman_name), lastman_invistime)
  1642.                 say(msg)
  1643.                 applycamo(cur_last_man, lastman_invistime)
  1644.         end
  1645. end
  1646.  
  1647. function PlayerChangeTimer(id, count)
  1648.         if count ~= 10 then
  1649.                 local zombsize = cur_zombie_count
  1650.                 if allow_change == false or zombsize > 0 then
  1651.                         allow_change = false
  1652.                         if team_play then say("Thank you, the game can continue.") end
  1653.             player_change_timer = nil
  1654.                         return false
  1655.                 end
  1656.                 say("In " .. 10 - count .. " seconds a player will be forced to become a zombie.")
  1657.                 return true
  1658.         else -- timer up, force team change
  1659.                 allow_change = false
  1660.                 -- pick a human and make them zombie.
  1661.                 local newZomb = ChooseRandomPlayer(zombie_team)
  1662.                 if newZomb then
  1663.                         makezombie(newZomb, true)
  1664.                         privatesay(newZomb, zombie_message)
  1665.                 end
  1666.         player_change_timer = nil
  1667.                 return false
  1668.         end
  1669. end
  1670.  
  1671. function PlayerInHill(player)
  1672.         player = tonumber(player)
  1673.         local bool = false
  1674.         local m_player = getplayer(player)
  1675.         if m_player then
  1676.                 local InHill = readbyte(team_koth_score_array + player + 0x80)
  1677.                 if InHill == 1 then
  1678.                         bool = true
  1679.                 end
  1680.         end
  1681.         return bool
  1682. end
  1683.  
  1684. function PutUnderMap(id, count, m_objectId)
  1685.         local m_object = getobject(m_objectId)
  1686.         if m_object then
  1687.                 local x,y,z = getobjectcoords(m_objectId)
  1688.                 movobjectcoords(m_objectId, x, y, z - 20)
  1689.         end
  1690.         return false
  1691. end
  1692.  
  1693. function sendresponse(message, player)
  1694.         if message == "" then
  1695.                 return
  1696.         end
  1697.         player = tonumber(player)
  1698.         if tonumber(player) and player ~= nil and player ~= -1 and player >= 0 and player < 16 then
  1699.                 sendconsoletext(player, message)
  1700.         else
  1701.                 hprintf(message)
  1702.         end
  1703. end
  1704.  
  1705. function ScriptLoad()
  1706.         if Persistent then
  1707.                 cur_zombie_count = 0
  1708.                 cur_human_count = 0
  1709.                 alpha_zombie_count = 0
  1710.                 human_time = {}
  1711.                 cur_players = 0
  1712.                 cur_last_man = nil
  1713.                 last_man_hash = 0
  1714.                 processid = 0
  1715.                 game_started = false
  1716.                 allow_change = false
  1717.                 flagball_weap = {}
  1718.                 last_hill_time = {}
  1719.                 hash_table = {}
  1720.                 inhill_time = {}
  1721.         end
  1722.         for i = 1,4 do
  1723.                 if zombie_weapon[i] == "weapons\\ball\\ball" or zombie_weapon[i] == "weapons\\flag\\flag" then
  1724.                         oddball_or_flag = zombie_weapon[i]
  1725.                 end
  1726.         end
  1727.         gametype = readbyte(gametype_base + 0x30)
  1728.         if gametype == 1 then
  1729.                 gametype = "CTF"
  1730.                 writedword(flag_respawn_addr + 0x0, 0xFFFFFFFF)
  1731.                 registertimer(0, "DelayWriteCoords")
  1732.         elseif gametype == 2 then
  1733.                 gametype = "Slayer"
  1734.                 writebyte(gametype_base + 0x58, 3)
  1735.         if speedtimer == nil then
  1736.                     speedtimer = registertimer(1000, "SpeedTimer")
  1737.         end
  1738.         elseif gametype == 4 then
  1739.                 gametype = "KOTH"
  1740.         end
  1741.         -- assume a game is running
  1742.         game_started = true
  1743.         team_play = readbyte(gametype_base + 0x34) -- Confirmed. (Off = 0) (On = 1)
  1744.         if team_play == 1 then
  1745.                 team_play = true
  1746.         else
  1747.                 team_play = false
  1748.                 zombie_team = 0
  1749.         end
  1750.         starting_equipment = readbit(gametype_base + 0x38, 2) -- Generic = 0, Custom = 1
  1751.         if starting_equipment == 1 then
  1752.                 starting_equipment = "Generic"
  1753.         else
  1754.                 starting_equipment = "Custom"
  1755.         end
  1756.     if humantimer == nil then
  1757.             humantimer = registertimer(1000, "HumanTimer")
  1758.     end
  1759.     if crouch_timer == nil then
  1760.             crouch_timer = registertimer(200, "invisCrouch")
  1761.     end
  1762.        
  1763.         -- recalculate team counters
  1764.         cur_zombie_count = getzombiesize()
  1765.         cur_human_count = gethumansize()
  1766.         cur_players = cur_zombie_count + cur_human_count
  1767.  
  1768.         -- recalculate how many "alpha" zombies there are
  1769.         alpha_zombie_count = getalphacount()
  1770.  
  1771.         -- load the last man hash (if there is one)
  1772.         local file = io.open("lasthash_" .. processid .. ".tmp", "r")
  1773.         if file then
  1774.                 -- read the ip
  1775.                 last_man_hash = file:read("*line")
  1776.                 file:close()
  1777.                 -- delete the file
  1778.                 os.remove("lasthash_" .. processid .. ".tmp")
  1779.         end
  1780.         registertimer(0,"checkgamestate")
  1781. end
  1782.  
  1783. function SpeedTimer(id, count)
  1784.     for i = 0,15 do
  1785.                 if getplayer(i) then
  1786.                         local team = getteam(i)
  1787.                         if team == zombie_team then
  1788.                                 setspeed(i, zombie_speed)
  1789.                         elseif cur_last_man == i then
  1790.                                 setspeed(i, lastman_speed)
  1791.             else
  1792.                 setspeed(i, human_speed)    
  1793.                         end
  1794.                 end
  1795.         end
  1796.         return true
  1797. end
  1798.  
  1799. function RemoveLastmanProtection(id, count, m_object)
  1800.         writebit(m_object, 0x10, 7, 0)
  1801.         return false
  1802. end
  1803.  
  1804. --rounds the number
  1805. function round(num)
  1806.     under = math.floor(num)
  1807.     upper = math.floor(num) + 1
  1808.     underV = -(under - num)
  1809.     upperV = upper - num
  1810.     if (upperV > underV) then
  1811.         return under
  1812.     else
  1813.         return upper
  1814.     end
  1815. end
  1816.  
  1817. --called when the lastman no longer exists
  1818. function takenavsaway()
  1819.         for i = 0,15 do
  1820.                 local m_player = getplayer(i)
  1821.                 if m_player then
  1822.                         writeword(m_player + 0x88, i)
  1823.                 end
  1824.         end
  1825. end
  1826.  
  1827. function timetoword(time)
  1828.         if time == -1 or time == "-1" then
  1829.                 return -1
  1830.         elseif tonumber(time) then
  1831.                 local returntime = ""
  1832.                 local seconds = tonumber(time)
  1833.                 local days = math.floor(seconds/86400)
  1834.                 seconds = seconds - days*86400
  1835.                 local hours = math.floor(seconds/3600)
  1836.                 seconds = seconds - hours*3600
  1837.                 local minutes = math.floor(seconds/60)
  1838.                 seconds = seconds - minutes*60
  1839.                 if seconds ~= 0 then
  1840.                         returntime = seconds .. "s"
  1841.                 end
  1842.                 if minutes ~= 0 then
  1843.                         if returntime == "" then
  1844.                                 returntime = minutes .. "m"
  1845.                         else
  1846.                                 returntime = minutes .. "m " .. returntime
  1847.                         end
  1848.                 end
  1849.                 if hours ~= 0 then
  1850.                         if returntime == "" then
  1851.                                 returntime = hours .. "h"
  1852.                         else
  1853.                                 returntime = hours .. "h " .. returntime
  1854.                         end
  1855.                 end
  1856.                 if days ~= 0 then
  1857.                         if returntime == "" then
  1858.                                 returntime = days .. "d"
  1859.                         else
  1860.                                 returntime = days .. "d " .. returntime
  1861.                         end
  1862.                 end
  1863.                 if returntime == "" then
  1864.                         returntime = "0s"
  1865.                 end
  1866.                 return returntime
  1867.         end
  1868. end
  1869.  
  1870. function todec(number)
  1871.         return tonumber(number, 16)
  1872. end
  1873.  
  1874. --this function writes navpoints to zombies which will point to the last man
  1875. function WriteNavsToZombies(cur_last_man)
  1876.         for i = 0,15 do
  1877.                 if getplayer(i) then
  1878.                         local team = getteam(i)
  1879.                         if team == zombie_team then
  1880.                                 local m_player = getplayer(i)
  1881.                                 if m_player then
  1882.                                         local slayer_target = readword(m_player, 0x88)
  1883.                                         if slayer_target < 16 and slayer_target > -1 then
  1884.                                                 writeword(m_player, 0x88, cur_last_man)
  1885.                                         end
  1886.                                 end
  1887.                         end
  1888.                 end
  1889.         end
  1890. end
  1891.  
  1892. function writewordsigned(address, offset, value)
  1893.         if value and value > 0x7FFF then
  1894.                 local max = 0xFFFF
  1895.                 local difference = max - value
  1896.                 value = -1 - difference
  1897.         end
  1898.         writeword(address + offset, value)
  1899. end
  1900.  
  1901. function writedwordsigned(address, offset, value)
  1902.         if value and value > 0x7FFFFFFF then
  1903.                 local max = 0xFFFFFFFF
  1904.                 local difference = max - value
  1905.                 value = -1 - difference
  1906.         end
  1907.         writedword(address + offset, value)
  1908. end
  1909.  
  1910. function OnFlashlightToggle(player)
  1911.     if getplayer(player) then
  1912.         if speed_count[player] == 0 then
  1913.             registertimer(10, "speedtimerstart", player)
  1914.         end
  1915.     end
  1916. end
  1917.  
  1918. function speedtimerstart(id, count, player)
  1919.  
  1920.     if getplayer(player) then
  1921.         if getteam(player) == zombie_team then
  1922.             setspeed(player, zombie_speed + 1)
  1923.         elseif getteam(player) == human_team then
  1924.             setspeed(player, human_speed + 1)
  1925.         end
  1926.         speed_count[player] = speed_count[player] + 1
  1927.         registertimer(3000, "speedtimerstop", player)
  1928.     end
  1929.     return false
  1930. end
  1931.  
  1932. function speedtimerstop(id, count, player)
  1933.    
  1934.     if getplayer(player) then
  1935.         if getteam(player) == zombie_team then
  1936.             setspeed(player, zombie_speed)
  1937.         elseif getteam(player) == human_team then
  1938.             setspeed(player, human_speed)
  1939.         end
  1940.     end
  1941.     return false
  1942. end
  1943.  
  1944. function ActiveVehicle(id, count, info)
  1945.  
  1946.     local vehiId = info[1]
  1947.     local player = info[2]
  1948.     local m_vehicle = getobject(vehiId)
  1949.     if m_vehicle then
  1950.         if vehicles[vehiId] == player then
  1951.             if getplayer(player) then
  1952.                 local vx = readfloat(m_vehicle, 0x68)
  1953.                 local vy = readfloat(m_vehicle, 0x6C)
  1954.                 local vz = readfloat(m_vehicle, 0x70)
  1955.                 local velocity = math.sqrt(vx ^ 2 + vy ^ 2 + vz ^ 2)
  1956.                 if velocity == 0 then
  1957.                     activetime[vehiId] = activetime[vehiId] or 100 - 1
  1958.                     if activetime[vehiId] <= 0 then
  1959.                         vehicles[vehiId] = nil
  1960.                         return false
  1961.                     end
  1962.                 end
  1963.             end
  1964.         else
  1965.             return false
  1966.         end
  1967.     end
  1968.    
  1969.     return true
  1970. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement