Advertisement
th3w1zard1

Wizard's Infection Script 3.1

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