Advertisement
rockbandcheeseman

Wizard Infection Edit

Nov 27th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 33.91 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 = 1.5 -- zombie speed
  5. lastman_speed = 1.4 -- last man speed
  6. lastman_dmgmodifier = 1.5 -- damage modifier for the last man (on top of human damage)
  7. lastman_invistime = 10 -- in seconds
  8. human_speed = 1.0 -- speed when not infected
  9. zombie_count = 1 -- if value is less than 1 is it used as a percentage, more than or equal to one is absolute count
  10. last_man_next_zombie = true -- if this value is true the last man standing becomes the next zombie, if not it's random
  11. max_zombie_count = 2 -- this caps what the zombie count would be w/ ratio (nil is disable)
  12. lastman_invulnerable = 5 -- time (in seconds) the last man is invulnerable for: replace with nil to disable
  13. alphazombie_frag_count = 0 -- number of frag nades they spawn with
  14. alphazombie_plasma_count = 0 -- number of plasma nades they spawn with
  15. zombie_frag_count = 0 -- number of frag nades they spawn with
  16. zombie_plasma_count = 0 -- number of plasma nades they spawn with
  17. alphazombie_clip_count = 0 -- number of shots in clip
  18. alphazombie_ammo_count = 0 -- backpack ammo they get
  19. zombie_clip_count = 0 -- number of shots in clip for zombies once there are not only alpha zombies
  20. zombie_ammo_count = 0 -- backpack ammo zombies once there are not only alpha zombies
  21.  
  22. -- Game messages
  23. zombie_message = "YOU'RE A ZOMBIE. KILL THE HUMANS!"
  24. human_message = "YOU'RE A HUMAN. SURVIVE."
  25. rejoin_message = "Please don't leave and rejoin. You've been put back onto your last team."
  26. infected_message = " has been infected!"
  27. teamkill_message = "Don't team kill..."
  28. blockteamchange_message = "You're not allowed to change team."
  29. zombieinvis_message = "The zombies are invisible for 20 seconds!"
  30. timer_team_change_msg = "Thank you. The game will now continue"
  31.  
  32. -- Don't modify below variables unless you know what you're doing
  33. cur_zombie_count = 0
  34. cur_human_count = 0
  35. alpha_zombie_count = 0
  36. human_time = {}
  37. cur_players = 0
  38. cur_last_man = nil
  39. last_man_hash = 0
  40. processid = 0
  41. game_started = false
  42. allow_change = false
  43. new_game_timer = 0
  44. player_change_timer = 0
  45. oddball_weap = {}
  46. balls = {}
  47. last_hill_time = {}
  48. hash_table = {}
  49. inhill_time = {}
  50.  
  51. -- This function is required for scripts to run on Phasor (including and after 01.00.03.104)
  52. -- You should return the minimum required version of Phasor
  53. -- Official releases:
  54. --   01.00.03.104 - 3104
  55. --   01.00.10.057 - 10057
  56. function GetRequiredVersion()
  57.     return 10057
  58. end
  59.  
  60. -- called when the script is loaded
  61. function OnScriptLoad(process)
  62.  
  63.     processid = process
  64.  
  65.     -- assume a game is running
  66.     game_started = true
  67.  
  68.     humantimer = registertimer(1000, "HumanTimer")
  69.  
  70.     for i = 0,15 do
  71.         if getplayer(i) ~= nil then
  72.             local m_object = getobject(getplayerobjectid(i))
  73.             if m_object ~= nil then
  74.                 local weapID = readdword(m_object, 0x118)
  75.                 local weap = getobject(weapID)
  76.                 local tagName = getobjecttag(weapID)
  77.                 if tagName == "weapons\\ball\\ball" then
  78.                     oddball_weap[i] = weapID
  79.                 end
  80.             end
  81.         end
  82.     end
  83.  
  84.     -- recalculate team counters
  85.     cur_zombie_count = getteamsize(zombie_team)
  86.     cur_human_count = getteamsize(human_team)
  87.     cur_players = cur_zombie_count + cur_human_count
  88.  
  89.     -- recalculate how many "alpha" zombies there are
  90.     alpha_zombie_count = getalphacount()
  91.  
  92.     -- load the last man hash (if there is one)
  93.     local file = io.open("lasthash_" .. processid .. ".tmp", "r")
  94.  
  95.     if (file ~= nil) then
  96.  
  97.         -- read the ip
  98.         last_man_hash = file:read("*line")
  99.  
  100.         file:close()
  101.  
  102.         -- delete the file
  103.         os.remove("lasthash_" .. processid .. ".tmp")
  104.     end
  105. end
  106.  
  107. -- called when the script is unloaded
  108. -- Do not return a value
  109. function OnScriptUnload()
  110.  
  111. end
  112.  
  113. function getobjecttag(object)
  114.     local m_object = getobject(object)
  115.     local object_map_id = readdword(m_object, 0x0)
  116.  
  117.     local map_base = readdword(0x63525c, 0x0)
  118.     local map_tag_count = todec(endian(map_base, 0xC, 0x3))
  119.     local tag_table_base = map_base + 0x28
  120.     local tag_table_size = 0x20
  121.  
  122.     for i=0,(map_tag_count - 1) do
  123.         local tag_id = todec(endian(tag_table_base, 0xC + (tag_table_size * i), 0x3))
  124.  
  125.         if tag_id == object_map_id then
  126.             tag_name_address = endian(tag_table_base, 0x10 + (tag_table_size * i), 0x3)
  127.             tag_name = readtagname("0x" .. tag_name_address)
  128.  
  129.             return tag_name
  130.         end
  131.     end
  132. end
  133.  
  134. function endian(address, offset, length)
  135.  
  136.         local data_table = {}
  137.         local data = ""
  138.  
  139.         for i=0,length do
  140.  
  141.                 local hex = string.format("%X", readbyte(address, offset + i))
  142.  
  143.                 if tonumber(hex, 16) < 16 then
  144.                         hex = 0 .. hex
  145.                 end
  146.  
  147.                 table.insert(data_table, hex)
  148.  
  149.         end
  150.  
  151.         for k,v in pairs(data_table) do
  152.                 data = v .. data
  153.         end
  154.  
  155.         return data
  156.  
  157. end
  158.  
  159. function todec(number)
  160.     return tonumber(number, 16)
  161. end
  162.  
  163. -- called when a game is starting (before any players join)
  164. -- Do not return a value.
  165. function OnNewGame(map)
  166.  
  167.     -- reset our variables
  168.     cur_zombie_count = 0
  169.     cur_human_count = 0
  170.     cur_players = 0
  171.  
  172.     -- the game hasn't started yet, will once timer runs down
  173.     game_started = false
  174.     new_game_timer = registertimer(2000, "NewGameTimer")
  175.    
  176.         if map == "putput" or map == "longest" or map == "beavercreek" or map == "chillout" then
  177.         zombie_speed = 1.35
  178.         lastman_speed = 1.2
  179.     if map == "dangercanyon" or map == "gephyrophobia" or map == "timberland" or map == "deathisland" or map == "bloodgulch" then
  180.                 zombie_speed = 1.8
  181.                 lastman_speed = 1.6
  182.        
  183. end            
  184. end
  185. end
  186.  
  187.  
  188. -- called when a game is ending
  189. -- Do not return a value.
  190. function OnGameEnd(mode)
  191.     -- mode 1 = score menu (F1) is being displayed to clients, they are still ingame
  192.     -- mode 2 = post game menu appeared
  193.     -- mode 3 = players can quit via the post game score card
  194.  
  195.     -- remove the new game timer (if still active)
  196.     if mode == 1 then
  197.         removetimer(new_game_timer)
  198.         removetimer(humantimer)
  199.     end
  200. end
  201.  
  202. -- Called when there is chat within the server
  203. -- It must return a value which indicates whether or not the chat is sent.
  204. function OnServerChat(player, chattype, message)
  205.     return 1
  206. end
  207.  
  208. -- Called when a server command is being executed
  209. -- It must return a value which indicates whether or not the command should be processed
  210. -- Note: It is only called when an authenticated (and allowed) player attempts to use the command.
  211. --       player is -1 when being executed via the server console.
  212. function OnServerCommand(player, command)
  213.     local allow = 1
  214.     local tokencount = getcmdtokencount(command)
  215.     if tokencount > 0 then
  216.         local cmd = getcmdtoken(command, 0)
  217.         if cmd == "sv_changeteam" and tokencount == 2 then
  218.             local player = getcmdtoken(command, 1)
  219.             player = rresolveplayer(player)
  220.             if getplayer(player) ~= nil then
  221.                 local cur_team = getteam(player)
  222.                 if cur_team == zombie_team then
  223.                     makehuman(player, true)
  224.                     privatesay(player, human_message)
  225.                 elseif cur_team == human_team then
  226.                     makezombie(player, true)
  227.                     privatesay(player, zombie_message)
  228.                 end
  229.                 hprintf("The player's team has been changed.")
  230.             else
  231.                 hprintf("The specified player is invalid")
  232.             end
  233.  
  234.             allow = 0
  235.         elseif cmd == "sv_map_reset" then
  236.             for i = 0,15 do
  237.                 local m_player = getplayer(i)
  238.                 if m_player ~= nil then
  239.                     local m_object = getobject(getplayerobjectid(i))
  240.                     if m_object ~= nil then
  241.                         local team = getteam(i)
  242.                         if team == zombie_team then
  243.                         --  destroyweaps(i)
  244.                         end
  245.                     end
  246.                 end
  247.             end
  248.         end
  249.     end
  250.     return allow
  251. end
  252.  
  253.  
  254.  
  255. -- Called when a player's team is being chosen as the join the server.
  256. -- It must return a value which indicates the team the player is to be put on.
  257. -- Note: this function being called doesn't guarantee that the player will be able to successfully join.
  258. function OnTeamDecision(cur_team)
  259.     local dest_team = zombie_team
  260.  
  261.     if game_started then
  262.         if cur_players == 0  then -- if no zombies make them human
  263.             dest_team = human_team
  264.         elseif cur_zombie_count > 0 and cur_human_count == 0 then
  265.             dest_team = human_team
  266.         end
  267.     end
  268.  
  269.     return dest_team
  270. end
  271.  
  272. -- Called when a player joins the server.
  273. -- Do not return a value.
  274. function OnPlayerJoin(player, team)
  275.  
  276.     -- update the player counts
  277.     cur_players = cur_players + 1
  278.  
  279.     local thisTeamSize = 0 -- used so we don't create empty teams for rejoining players
  280.     if team == zombie_team then
  281.         cur_zombie_count = cur_zombie_count + 1
  282.         thisTeamSize = cur_zombie_count
  283.     else
  284.         cur_human_count = cur_human_count + 1
  285.         thisTeamSize = cur_human_count
  286.     end
  287.  
  288.     alpha_zombie_count = getalphacount()
  289.  
  290.     local thisHash = gethash(player)
  291.     local alreadyExists = false
  292.  
  293.     -- check if the player has joined this game previously
  294.     for k,v in pairs(hash_table) do
  295.         if thisHash == k then
  296.  
  297.             if thisTeamSize > 1 then
  298.                 if v ~= team then changeteam(player, 0) end
  299.  
  300.                 --privatesay(player, rejoin_message)
  301.                 team = v
  302.             end
  303.             alreadyExists = true
  304.  
  305.             break
  306.         end
  307.     end
  308.  
  309.     -- add team entry for this hash
  310.     if alreadyExists == false then
  311.         hash_table[thisHash] = team
  312.     end
  313.  
  314.     if game_started == true then
  315.  
  316.         -- check if the player is a zombie
  317.         if team == zombie_team then
  318.             makezombie(player, false)
  319.             privatesay(player, zombie_message)
  320.         else
  321.             -- if we're at last man, make this player a zombie
  322.             if cur_last_man ~= nil then
  323.                 makezombie(player, true)
  324.                 privatesay(player, zombie_message)
  325.             else
  326.                 makehuman(player, false)
  327.                 privatesay(player, human_message)
  328.             end
  329.         end
  330.         privatesay(i, "Welcome to Wizard's Zombie Server!")
  331.         privatesay(i, "The hill is a safe-zone! Use it for quick getaways!")
  332.         checkgamestate(-1)
  333.     else
  334.         registertimer(10000, "MsgTimer", player)
  335.     end
  336. end
  337.  
  338. function MsgTimer(id, count, player)
  339.     privatesay(player, "Welcome to SPN zombies!")
  340.     privatesay(player, "Have fun!")
  341.     return 0
  342. end
  343.  
  344. -- Called when a player the server.
  345. -- Do not return a value.
  346. function OnPlayerLeave(player, team)
  347.     if team == zombie_team then
  348.         local m_object = getobject(getplayerobjectid(player))
  349.         if m_object ~= nil then
  350.             for i = 0,3 do
  351.                 local weapID = readdword(m_object, 0x2F8 + i*4)
  352.                 local weap = getobject(weapID)
  353.                 if weap ~= nil then
  354.                     registertimer(0, "destroyweaps", weapID)
  355.                 end
  356.             end
  357.         end
  358.         cur_zombie_count = cur_zombie_count - 1
  359.     elseif team == human_team then
  360.         cur_human_count = cur_human_count - 1
  361.     end
  362.  
  363.     -- if last man is leaving, reset it
  364.     if cur_last_man == player then
  365.         cur_last_man = nil
  366.     end
  367.  
  368.     cur_players = cur_players - 1
  369.  
  370.     checkgamestate(-1)
  371.  
  372.     -- update team within table
  373.     local thisHash = gethash(player)
  374.     hash_table[thisHash] = team
  375. end
  376.  
  377. -- called when a player kills another, 'killer' is the index of the killing player, 'victim' is the index of the dead player
  378. -- Do not return a value.
  379. function OnPlayerKill(killer, victim, mode)
  380.  
  381.     local v_team = getteam(victim)
  382.    
  383.     if v_team == zombie_team then
  384.         local m_victim = getplayer(victim)
  385.         local v_objId = readdword(m_victim, 0x34)
  386.         local v_object = getobject(v_objId)
  387.         for i = 0,3 do
  388.             local m_weapId = readdword(v_object, 0x2F8 + i * 4)
  389.             local m_weapon = getobject(m_weapId)
  390.             defaultammo(m_weapId)
  391.         end
  392.     end
  393.  
  394.     if game_started then
  395.  
  396.         local team = getteam(victim)
  397.         if mode == 0 then -- server kill
  398.         elseif mode == 1 then -- fall damage
  399.             if team ~= zombie_team then
  400.                 local name = getname(victim)
  401.                 say(name .. infected_message)
  402.                 makezombie(victim, false)
  403.             end
  404.         elseif mode == 2 then -- killed by guardians
  405.         elseif mode == 3 then -- killed by vehicle
  406.         elseif mode == 4 then -- killed by another player
  407.  
  408.             local killer_team = getteam(killer)
  409.             -- check to see if a zombie killed them
  410.             if killer_team == zombie_team and team == human_team then
  411.                 name = getname(victim)
  412.                 say(name .. infected_message)
  413.                 makezombie(victim, false)
  414.                 --privatesay(victim, zombie_message)
  415.             end
  416.         elseif mode == 5 then -- betrayed
  417.         elseif mode == 6 then -- suicide
  418.             -- if they're human, make them zombies
  419.             if team == human_team then
  420.                 name = getname(victim)
  421.                 say(name .. infected_message)
  422.                 makezombie(victim, false)
  423.             end
  424.         end
  425.     end
  426. end
  427.  
  428. function defaultammo(m_weapId)
  429.  
  430.     local tagType, tagName = getobjecttag(m_weapId)
  431.     local m_weapon = getobject(m_weapId)
  432.     say(tagName)
  433.     if tagName == "weapons\\assault rifle\\assault rifle" then
  434.         writeword(m_weapon, 0x2B6, 180)
  435.         writeword(m_weapon, 0x2B8, 60)
  436.     elseif tagName == "weapons\\pistol\\pistol" then
  437.         writeword(m_weapon, 0x2B6, 48)
  438.         writeword(m_weapon, 0x2B8, 12)
  439.     elseif tagName == "weapons\\shotgun\\shotgun" then
  440.         writeword(m_weapon, 0x2B6, 12)
  441.         writeword(m_weapon, 0x2B8, 12)
  442.     elseif tagName == "weapons\\sniper rifle\\sniper rifle" then
  443.         writeword(m_weapon, 0x2B6, 8)
  444.         writeword(m_weapon, 0x2B8, 4)
  445.     end
  446.    
  447.     updateammo(m_weapId)
  448. end
  449.  
  450. -- called when a player gets a double kill, killing spree etc
  451. -- see Phasor documentation for multiplier values
  452. function OnKillMultiplier(player, multiplier)
  453. end
  454.  
  455. -- Called when a player s (after object is created, before players are notified)
  456. -- Do not return a value
  457. function OnPlayerSpawn(player, m_objectId)
  458.  
  459.     local team = getteam(player)
  460.  
  461.     if team == zombie_team then
  462.  
  463.         local m_objectId = getplayerobjectid(player)
  464.         local m_object = getobject(m_objectId)
  465.         if m_object ~= nil then
  466.             -- set nade counts
  467.             writebyte(m_object, 0x31E, zombie_frag_count)
  468.             writebyte(m_object, 0x31F, zombie_plasma_count)
  469.  
  470.             -- set the ammo
  471.             local clipcount = alphazombie_clip_count
  472.             local ammocount = alphazombie_ammo_count
  473.  
  474.             -- set ammo counts for zombies when others have been infected
  475.             if cur_zombie_count > alpha_zombie_count then
  476.                 clipcount = zombie_clip_count
  477.                 ammocount = zombie_ammo_count
  478.             else -- set alpha nades
  479.                 writebyte(m_object, 0x31E, alphazombie_frag_count)
  480.                 writebyte(m_object, 0x31F, alphazombie_plasma_count)
  481.             end
  482.  
  483.             local bool = false
  484.             for i=0,3 do
  485.                 local m_weaponId = readdword(m_object, 0x2F8 + (i*4))
  486.                 if bool == false and getobject(m_weaponId) ~= nil then
  487.                     local tagName = getobjecttag(m_weaponId)
  488.                     if tagName == "weapons\\ball\\ball" then
  489.                         oddball_weap[player] = m_weaponId
  490.                         bool = true
  491.                     end
  492.                 end
  493.                 if m_weaponId ~= 0xffffffff then
  494.                     local m_weapon = getobject(m_weaponId)
  495.                     if m_weapon ~= nil then
  496.                         -- set the ammo
  497.                         writeword(m_weapon, 0x2B6, ammocount)
  498.                         writeword(m_weapon, 0x2B8, clipcount)
  499.                         writefloat(m_weapon, 0x240, 1)
  500.                         -- force it to sync
  501.                         updateammo(m_weaponId)
  502.                     end
  503.                 end
  504.             end
  505.         end
  506.     end
  507. end
  508.  
  509. -- Called after clients have been notified of a player spawn
  510. -- Do not return a value
  511. function OnPlayerSpawnEnd(player, m_objectId)
  512.  
  513. end
  514.  
  515. -- Called when a player is attempting to .
  516. -- A value must be returned. The return value indicates whether or not the player is allowed the change team.
  517. -- Notes: If relevant is 1 the return value is considered, if it's 0 then the return value is ignored.
  518. function OnTeamChange(relevant, player, team, dest_team)
  519.     if relevant == 1 then
  520.  
  521.         if allow_change == false then
  522.             privatesay(player, blockteamchange_message)
  523.         elseif dest_team == zombie_team then
  524.             -- this is so memory is updated for processing
  525.             -- when relevant is 0 OnTeamChange is called once the changes
  526.             -- have been committed
  527.             changeteam(player, 1)
  528.         end
  529.  
  530.         -- we don't let people change team
  531.         return 0
  532.  
  533.  
  534.     elseif dest_team ~= team then -- we can't stop the person changing teams, bein done by an admin
  535.  
  536.         -- update team counts
  537.         if dest_team == zombie_team then
  538.             cur_human_count = cur_human_count - 1
  539.             cur_zombie_count = cur_zombie_count + 1
  540.         elseif dest_team == human_team then
  541.             cur_human_count = cur_human_count + 1
  542.             cur_zombie_count = cur_zombie_count - 1
  543.         end
  544.  
  545.         -- they're allowed to change if the timer is active, if it is disable it
  546.         if allow_change == true and dest_team == zombie_team then
  547.  
  548.             allow_change = false
  549.             -- remove change timer
  550.             removetimer(player_change_timer)
  551.             player_change_timer = 0
  552.  
  553.             say(timer_team_change_msg)
  554.         end
  555.  
  556.         -- check if the game has started yet
  557.         if game_started == true then
  558.  
  559.             -- set attributes
  560.             if dest_team == zombie_team then
  561.                 makezombie(player, false)
  562.             elseif dest_team == human_team then
  563.                 makehuman(player, false)
  564.             end
  565.  
  566.             checkgamestate(player)
  567.         end
  568.  
  569.         -- update team withf
  570.         local thisHash = gethash(player)
  571.         hash_table[thisHash] = dest_team
  572.     end
  573.  
  574.     return 1
  575. end
  576.  
  577. function OnClientUpdate(player, m_objectId)
  578.     local m_player = getplayer(player)
  579.     local m_object = getobject(m_objectId)
  580.     local hash = gethash(player)
  581.     if m_object ~= nil then
  582.         local team = readbyte(m_player, 0x20)
  583.         if team == zombie_team then
  584.             local obj_crouch = readbyte(m_object, 0x2A0)
  585.             if obj_crouch == 3 then
  586.                 applycamo(player, 5)
  587.             end
  588.             --[[local shooting = readbit(m_object, 0x209, 4)
  589.             local nading2 = readbit(m_object, 0x209, 2)
  590.             local nading = readbit(m_object, 0x209, 3)
  591.             if shooting == 1 or nading == 1 then
  592.                 local weapID = readdword(m_object, 0x2FC)
  593.                 local weap = getobject(weapID)
  594.                 if weap ~= nil then
  595.                     weapID = oddball_weap[player]
  596.                     local m_player = getplayer(player)
  597.                     if m_player ~= nil then
  598.                         if weapID == nil then
  599.                             oddball_weap[player] = createobject("weap", "weapons\\ball\\ball", 0, 0, false, 5, 5, 2)
  600.                             assignweapon(player, oddball_weap[player])
  601.                         else
  602.                             if getobject(weapID) ~= nil then
  603.                                 if IsBall(weapID) then
  604.                                     assignweapon(player, weapID)
  605.                                 else
  606.                                     oddball_weap[player] = createobject("weap", "weapons\\ball\\ball", 0, 0, false, 5, 5, 2)
  607.                                     assignweapon(player, oddball_weap[player])
  608.                                 end
  609.                             else
  610.                                 oddball_weap[player] = createobject("weap", "weapons\\ball\\ball", 0, 0, false, 5, 5, 2)
  611.                                 assignweapon(player, oddball_weap[player])
  612.                             end
  613.                         end
  614.                     end
  615.                 end
  616.             end--]]
  617.         end
  618.         if tonumber(human_time[hash]) ~= nil then
  619.             local hill_time = readword(m_player, 0xC4)
  620.             if tonumber(hill_time) ~= nil then
  621.                 writeword(m_player, 0xC4, tonumber(human_time[hash])*30)
  622.             end
  623.         else
  624.             human_time[hash] = 0
  625.         end
  626.     end
  627.     writedword(0x639BD0, 0x0, 0)
  628.     writedword(0x639BD0, 0x1, 0)
  629. end
  630.  
  631. function IsBall(weapID)
  632.     for i = 1,#balls do
  633.         if balls[i] == weapID then
  634.             return true
  635.         end
  636.     end
  637. end
  638.  
  639. --[[function GiveOddball(id, count, player, weapID)
  640.     local m_player = getplayer(player)
  641.     if m_player ~= nil then
  642.         if weapID == nil then
  643.             oddball_weap[player] = createobject("weap", "weapons\\ball\\ball", 0, 0, false, 5, 5, 2)
  644.             assignweapon(player, oddball_weap[player])
  645.             return 0
  646.         else
  647.             local m_object = getobject(getplayerobjectid(player))
  648.             if m_object ~= nil then
  649.                 if getobject(weapID) ~= nil then
  650.                     local tagName = getobjecttag(weapID)
  651.                     if tagName == "weapons\\ball\\ball" then
  652.                         assignweapon(player, weapID)
  653.                     else
  654.                         oddball_weap[player] = createobject("weap", "weapons\\ball\\ball", 0, 0, false, 5, 5, 2)
  655.                         assignweapon(player, oddball_weap[player])
  656.                     end
  657.                 else
  658.                     oddball_weap[player] = createobject("weap", "weapons\\ball\\ball", 0, 0, false, 5, 5, 2)
  659.                     assignweapon(player, oddball_weap[player])
  660.                 end
  661.             end
  662.             return 0
  663.         end
  664.     end
  665.     return 0
  666. end--]]
  667.  
  668.  
  669.  
  670. -- Called when a player interacts with an object
  671. -- It can be called while attempting to pick the object up
  672. -- It is also called when standing above an object so can be called various times quickly
  673. function OnObjectInteraction(player, m_ObjectId, tagType, tagName)
  674.  
  675.     local response = 1
  676.  
  677.     if game_started == true then
  678.  
  679.         -- regardless of the team, stop people taking the flag
  680.         if tagType == "weap" then
  681.             if tagName == "weapons\\flag\\flag" then
  682.                 response = 0
  683.             elseif tagName == "weapons\\ball\\ball" then
  684.                 local team = getteam(player)
  685.                 if team == zombie_team then
  686.                     return 1
  687.                 else
  688.                     return 0
  689.                 end
  690.             end
  691.         end
  692.  
  693.         if response == 1 then
  694.  
  695.             local team = getteam(player)
  696.  
  697.             if team == zombie_team then
  698.  
  699.                 -- we want to stop zombies picking up weapons
  700.                 if tagType == "weap" then
  701.                     response = 0
  702.                 elseif tagType == "eqip" then
  703.  
  704.                     if tagName == "weapons\\frag grenade\\frag grenade" or tagName == "weapons\\plasma grenade\\plasma grenade" then
  705.                         response = 0 -- don't let them pick the nades
  706.                     elseif tagName == "powerups\\active camouflage" then
  707.  
  708.                         -- check if the picking player is already invisible
  709.                         local m_player = getplayer(player)
  710.                         if m_player ~= nil then
  711.  
  712.                             local m_playerObjId = readdword(m_player, 0x34)
  713.                             local m_object = getobject(m_playerObjId)
  714.                             if m_object ~= nil then
  715.  
  716.                                 local camoFlag = readdword(m_object, 0x204)
  717.                                 if camoFlag ~= 0x51 then
  718.  
  719.                                     -- check if zombies are to be made invisible
  720.                                     local doInvis = getrandomnumber(1, 10)
  721.  
  722.                                     if doInvis > 5 then
  723.  
  724.                                         -- make the whole zombie team invis for 20 seconds
  725.                                         for x = 0,15 do
  726.  
  727.                                             local team = getteam(x)
  728.  
  729.                                             if team == zombie_team and x ~= player then
  730.                                                 --hprintf("applying camo to player " .. x)
  731.                                                 applycamo(x, 30.00)
  732.                                             end
  733.                                         end
  734.  
  735.                                         say(zombieinvis_message)
  736.                                     end
  737.                                 end
  738.                             end
  739.                         end
  740.                     end
  741.                 end
  742.             end
  743.         end
  744.     end
  745.     return response
  746. end
  747.  
  748. -- Called when a player attempts to reload their weapon.
  749. -- A value must be returned. The return value indicates whether or not the player is allowed to reload.
  750. -- Notes: If player is -1 then the weapon being reload wasn't located (it could be a vehicle's weapon)
  751. function OnWeaponReload(player, weapon)
  752.     return 1
  753. end
  754.  
  755. -- Called when a player attempts to enter a vehicle.
  756. -- A value must be returned. The return value indicates whether or not the player is allowed to enter.
  757. function OnVehicleEntry(relevant, player, vehicleId, vehicle_tag, seat)
  758.  
  759.     local response = 1
  760.     if game_started and relevant == 1 then
  761.  
  762.         local team = getteam(player)
  763.         if team == zombie_team then
  764.             response = 0
  765.         end
  766.     end
  767.  
  768.     return response
  769. end
  770.  
  771. function OnVehicleEject(player, forceEject)
  772.     return 1
  773. end
  774.  
  775. -- Called when damage is being done to an object.
  776. -- This doesn't always need to be a player.
  777. -- Do not return a value
  778. function OnDamageLookup(receiving_obj, causing_obj, tagdata, tagname)
  779.  
  780.     -- Resolve the object ids into player ids
  781.     -- Remember, the damage doesn't always need to be done by a player.
  782.     local receiver = objecttoplayer(receiving_obj)
  783.     local causer = objecttoplayer(causing_obj)
  784.  
  785.     -- We want to amplify human damage, so make sure the causer is human
  786.     if causer ~= nil then
  787.  
  788.         local c_team = getteam(causer)
  789.         -- Make sure the team was found
  790.         if c_team ~= nil then
  791.  
  792.             -- Check if it's a human causing the damage
  793.             if c_team == human_team then
  794.  
  795.                 -- It's human damage, read the current damage the weapon has
  796.                 local min_dmg = readfloat(tagdata, 0x1D0)
  797.                 local max_dmg_min = readfloat(tagdata, 0x1D4)
  798.                 local max_dmg_max = readfloat(tagdata, 0x1D8)
  799.  
  800.                 -- This is used to increase human damage (for last man)
  801.                 local modifier = 1.0
  802.  
  803.                 -- Check if we're up to last man
  804.                 if cur_last_man ~= nil then
  805.                     -- Change the damage modifier to the last man's
  806.                     modifier = lastman_dmgmodifier
  807.                 end
  808.  
  809.                 -- Change the damage that will be done
  810.                 writefloat(tagdata, 0x1D0, min_dmg * 2 * modifier)
  811.                 writefloat(tagdata, 0x1D4, max_dmg_min * 2 * modifier)
  812.                 writefloat(tagdata, 0x1D8, max_dmg_max * 2 * modifier)
  813.  
  814.             -- It's a zombie causing the damage
  815.             elseif c_team == zombie_team then
  816.  
  817.                 -- check if it is melee damage, if so increase it to instant kill
  818.                 local found = string.find(tagname, "melee", -5)
  819.  
  820.                 -- We only want to increase zombie's melee damage
  821.                 if found ~= nil then
  822.  
  823.                     -- make melee instant kill
  824.                     writefloat(tagdata, 0x1D0, 500)
  825.                     writefloat(tagdata, 0x1D4, 500)
  826.                     writefloat(tagdata, 0x1D8, 500)
  827.  
  828.                 end
  829.             end
  830.         end
  831.     end
  832. end
  833.  
  834. -- Called when a player is being assigned a weapon (usually when they spawn)
  835. -- 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.
  836. -- Notes:   This is called for all weapon spawns the player has
  837. --          This is also called with player 255 when vehicles are being assigned weapons.
  838. --          This is only considered if in gametype, the weapon set is 'generic' if not this has no effect.
  839. function OnWeaponAssignment(player, object, count, tag)
  840.  
  841.     local actualWeapon = 0
  842.     local team = getteam(player)
  843.     local weapons = {"weapons\\assault rifle\\assault rifle", "weapons\\shotgun\\shotgun", "weapons\\pistol\\pistol", "weapons\\sniper rifle\\sniper rifle"}
  844.  
  845.     if team == zombie_team then
  846.         local rand = getrandomnumber(1, #weapons + 1)
  847.         actualWeapon = lookuptag("weap", weapons[rand])
  848.     end
  849.  
  850.     return actualWeapon
  851. end
  852.  
  853. function readtagname(address)
  854.  
  855.         local char_table = {}
  856.         local i = 0
  857.         local string = ""
  858.  
  859.         while readbyte(address, i) ~= 0 do
  860.                 table.insert(char_table, string.char(readbyte(address, i)))
  861.                 i = i + 1
  862.         end
  863.  
  864.         for k,v in pairs(char_table) do
  865.                 string = string .. v
  866.         end
  867.  
  868.         return string
  869.  
  870. end
  871.  
  872. -- Called when an object is created
  873. -- Do not return a value.
  874. function OnObjectCreation(m_objectId, player_owner, tag)
  875.     if tag == "weapons\\ball\\ball" then
  876.         table.insert(balls, m_objectId)
  877.     elseif tag == "weapons\\rocket launcher\\rocket launcher" or tag == "weapons\\plasma_cannon\\plasma_cannon" or tag == "weapons\\flamethrower\\flamethrower" then
  878.         registertimer(10, "DeleteHeavies", m_objectId)
  879.     end
  880. end
  881.  
  882. function DeleteHeavies(id, count, m_objId)
  883.  
  884.     destroyobject(m_objId)
  885.     return 0
  886. end
  887.  
  888. -- The below functions are used internally within the Lua script
  889. function NewGameTimer(id, count)
  890.  
  891.     if count == 5 then
  892.  
  893.         say("The game is starting...")
  894.  
  895.         if cur_players ~= 0 then
  896.  
  897.             local newgame_zombie_count = 0
  898.  
  899.             -- by default make all players human
  900.             for x=0,15 do
  901.                 local thisTeam = getteam(x)
  902.                 local hash = gethash(x)
  903.                 if thisTeam ~= nil then
  904.                     if thisTeam == zombie_team then
  905.                         changeteam(x, 0)
  906.                     end
  907.                     human_time[hash] = 0
  908.                 end
  909.             end
  910.  
  911.             local possible_count = cur_players
  912.  
  913.             -- make players zombie until the count has been met
  914.             local finalZombies = 0
  915.  
  916.             if zombie_count >= 1 then
  917.                 finalZombies = zombie_count
  918.             else
  919.                 finalZombies = round((possible_count * zombie_count) + 0.5)
  920.             end
  921.  
  922.             -- make last man zombie
  923.             local last_man_index = -1
  924.  
  925.             -- check if the last man is to be made a zombie
  926.             -- if so find who was last man
  927.             if last_man_next_zombie == true and cur_players > 1 then
  928.  
  929.                 -- loop through all hashes and check if any match the last man
  930.                 for i=0,15 do
  931.                     local hash = gethash(i)
  932.  
  933.                     if getplayer(i) ~= nil then
  934.                         if last_man_hash == hash then
  935.  
  936.                             -- make them a zombie and save their info
  937.                             makezombie(i, true)
  938.                             newgame_zombie_count = 1
  939.                             last_man_index = i
  940.  
  941.                             break
  942.                         end
  943.                     end
  944.                 end
  945.             end
  946.  
  947.             -- reset last man
  948.             last_man_hash = 0
  949.  
  950.             --hprintf("Expecting " .. finalZombies .. " zombies. Cur players " .. cur_players .. " possibles " .. possible_count)
  951.  
  952.             if finalZombies == cur_players then -- if 0 players they will be human
  953.                 finalZombies = finalZombies - 1
  954.             elseif finalZombies > possible_count then -- fix the count
  955.                 finalZombies = possible_count
  956.             elseif max_zombie_count ~= nil and finalZombies > max_zombie_count then -- cap the zombie count
  957.                 finalZombies = max_zombie_count
  958.             elseif finalZombies < 0 then
  959.                 finalZombies = 0
  960.             end
  961.  
  962.             -- set counters such that changeteam wont end the game
  963.             cur_zombie_count = 16
  964.             cur_human_count = 16
  965.  
  966.             --hprintf("Expecting " .. finalZombies .. " zombies. Cur players " .. cur_players .. " possibles " .. possible_count)
  967.  
  968.             -- loop through the players, randomly selecting ones to become
  969.             -- zombies
  970.             while (newgame_zombie_count < finalZombies) do
  971.  
  972.                 -- randomly choose a player
  973.                 local newzomb = ChooseRandomPlayer(zombie_team)
  974.  
  975.                 if newzomb == nil then
  976.                     break
  977.                 elseif newzomb ~= last_man_index then
  978.  
  979.                     makezombie(newzomb, true)
  980.                     newgame_zombie_count = newgame_zombie_count + 1
  981.                 end
  982.             end
  983.  
  984.             -- fix the team counters
  985.             cur_zombie_count = newgame_zombie_count
  986.             cur_human_count = cur_players - finalZombies
  987.  
  988.             -- reset the map
  989.             svcmd("sv_map_reset")
  990.  
  991.             -- loop through and tell players which team they're on
  992.             for i=0,15 do
  993.  
  994.                 local pteam = getteam(i)
  995.                 if pteam ~= nil then
  996.                     -- check if they're a zombie
  997.                     if pteam == zombie_team then
  998.                         privatesay(i, zombie_message)
  999.                     else
  1000.                         privatesay(i, human_message)
  1001.                     end
  1002.                 end
  1003.             end
  1004.  
  1005.         end
  1006.  
  1007.         game_started = true
  1008.  
  1009.         return 0 -- remove timer
  1010.     else
  1011.         say("The game will start in " .. 10 - 2*count .. " seconds.")
  1012.  
  1013.         return 1 -- keep timer
  1014.     end
  1015. end
  1016.  
  1017. function PlayerChangeTimer(id, count)
  1018.     if count ~= 10 then
  1019.  
  1020.         local zombsize = cur_zombie_count
  1021.  
  1022.         if allow_change == false or zombsize > 0 then
  1023.  
  1024.             allow_change = false
  1025.  
  1026.             say("Thank you, the game can continue.")
  1027.  
  1028.             return 0
  1029.         end
  1030.  
  1031.         say("In " .. 10 - count .. " seconds a player will be forced to become a zombie.")
  1032.  
  1033.         return 1
  1034.     else -- timer up, force team change
  1035.  
  1036.         allow_change = false
  1037.  
  1038.         -- pick a human and make them zombie.
  1039.         local newZomb = ChooseRandomPlayer(zombie_team)
  1040.  
  1041.         if newZomb ~= nil then
  1042.             makezombie(newZomb, true)
  1043.             privatesay(player, zombie_message)
  1044.         end
  1045.  
  1046.         return 0
  1047.     end
  1048. end
  1049.  
  1050. -- this function searches through current players and selects a random one
  1051. function ChooseRandomPlayer(excludeTeam)
  1052.  
  1053.     local t = {}
  1054.  
  1055.     -- loop through all 16 possible spots and add to table
  1056.     for i=0,15 do
  1057.  
  1058.         -- check if the player exists
  1059.         local team = getteam(i)
  1060.  
  1061.         if team ~= nil and team ~= excludeTeam then
  1062.             table.insert(t, i)
  1063.         end
  1064.  
  1065.     end
  1066.  
  1067.     if #t > 0 then
  1068.         -- generate a random number that we will use to select a player
  1069.         local tableCount =  table.getn(t)
  1070.         local r = getrandomnumber(1, tableCount+1)
  1071.         return t[r]
  1072.     else
  1073.         return nil
  1074.     end
  1075. end
  1076.  
  1077. function RemoveLastmanProtection(id, count, m_object)
  1078.     writebit(m_object, 0x10, 7, 0)
  1079.     return 0
  1080. end
  1081.  
  1082. -- there are no zombies left
  1083. function noZombiesLeft()
  1084.  
  1085.     allow_change = true
  1086.     say("There are no zombies left. Someone needs to change team, otherwise a random player will be forced to.")
  1087.     player_change_timer = registertimer(1000, "PlayerChangeTimer")
  1088.  
  1089. end
  1090.  
  1091. -- called when its the last man
  1092. function onlastman()
  1093.  
  1094.     -- lookup the last man
  1095.     for x=0,15 do
  1096.         local team = getteam(x)
  1097.  
  1098.         if team == human_team then
  1099.  
  1100.             cur_last_man = x
  1101.             -- give the last man speed and extra ammo
  1102.             setspeed(x, lastman_speed)
  1103.  
  1104.             -- find the last man's weapons
  1105.             local m_player = getplayer(x)
  1106.  
  1107.             if m_player ~= nil then
  1108.                 local m_ObjId = readdword(m_player, 0x34)
  1109.  
  1110.                 -- find the player's object
  1111.                 local m_object = getobject(m_ObjId)
  1112.  
  1113.                 if m_object ~= nil then
  1114.  
  1115.                     if lastman_invulnerable ~= nil and lastman_invulnerable > 0 then
  1116.                         -- setup the invulnerable timer
  1117.                         writebit(m_object, 0x10, 7, 1)
  1118.                         registertimer(lastman_invulnerable * 1000, "RemoveLastmanProtection", m_object)
  1119.                     end
  1120.  
  1121.                     -- give all weapons 600 ammo
  1122.                     for i=0,3 do
  1123.                         local m_weaponId = readdword(m_object, 0x2F8 + (i*4))
  1124.  
  1125.                         if m_weaponId ~= 0xffffffff then
  1126.  
  1127.                             -- get the weapons memory address
  1128.                             local m_weapon = getobject(m_weaponId)
  1129.  
  1130.                             if m_weapon ~= nil then
  1131.                                 -- set the ammo
  1132.                                 writeword(m_weapon, 0x2B6, 600)
  1133.                             end
  1134.                         end
  1135.                     end
  1136.                 end
  1137.             end
  1138.         end
  1139.     end
  1140.  
  1141.     if cur_last_man ~= nil then
  1142.  
  1143.         local lastman_name = getname(cur_last_man)
  1144.         local msg = string.format("%s is the last man alive and is invisible for %.0f seconds!", lastman_name, lastman_invistime)
  1145.         say(msg)
  1146.         applycamo(cur_last_man, lastman_invistime)
  1147.     end
  1148.  
  1149.  
  1150. end
  1151.  
  1152. -- checks the game state, for last man, all zombies etc
  1153. -- called onteamchange, player join and leave
  1154. function checkgamestate(player)
  1155.  
  1156.     -- check if the game has started yet
  1157.     if game_started == true then
  1158.  
  1159.         local zombie_count = cur_zombie_count
  1160.         local human_count = cur_human_count
  1161.         --hprintf("zombie count " .. zombie_count)
  1162.         --hprintf("human count " .. human_count)
  1163.  
  1164.         -- if no humans, but there are zombies, end the game
  1165.         if human_count == 0 and zombie_count > 0 then
  1166.             all_players_zombies(player)
  1167.         elseif human_count > 1 and zombie_count == 0 then
  1168.             noZombiesLeft()
  1169.         elseif human_count == 1 and zombie_count > 0 and cur_last_man == nil then
  1170.             onlastman()
  1171.         elseif cur_last_man ~= nil and zombie_count == 0 then
  1172.             makehuman(cur_last_man, false)
  1173.             cur_last_man = nil
  1174.         end
  1175.     end
  1176. end
  1177.  
  1178. -- called when all players are zombies (no shit)
  1179. function all_players_zombies(player)
  1180.  
  1181.     -- if there is a last man, store their hash
  1182.     if player ~= -1 then
  1183.         last_man_hash = gethash(player)
  1184.         -- write the hash to file
  1185.         local file = io.open("lasthash_" .. processid .. ".tmp", "w")
  1186.  
  1187.         if (file ~= nil) then
  1188.             file:write(last_man_hash)
  1189.             file:close()
  1190.         end
  1191.     end
  1192.  
  1193.     -- move onto the next map
  1194.     svcmd("sv_map_next")
  1195. end
  1196.  
  1197. function makezombie(player, forcekill)
  1198.  
  1199.     -- change the player's speed
  1200.     setspeed(player, zombie_speed)
  1201.  
  1202.     local team = getteam(player)
  1203.     if team == human_team then
  1204.         changeteam(player, forcekill)
  1205.     end
  1206. end
  1207.  
  1208. function makehuman(player, forcekill)
  1209.     -- change the player's speed
  1210.     setspeed(player, human_speed)
  1211.  
  1212.     local team = getteam(player)
  1213.     if team == zombie_team then
  1214.         changeteam(player, forcekill)
  1215.     end
  1216. end
  1217.  
  1218. function getalphacount()
  1219.     -- recalculate how many "alpha" zombies there are
  1220.     if zombie_count < 1 then
  1221.         alpha_zombie_count = round((cur_players * zombie_count) + 0.5)
  1222.     else
  1223.         alpha_zombie_count = zombie_count
  1224.     end
  1225.  
  1226.     if alpha_zombie_count > max_zombie_count then
  1227.         alpha_zombie_count = max_zombie_count
  1228.     end
  1229.     return alpha_zombie_count
  1230. end
  1231.  
  1232.  
  1233. function round(num)
  1234.     under = math.floor(num)
  1235.     upper = math.floor(num) + 1
  1236.     underV = -(under - num)
  1237.     upperV = upper - num
  1238.     if (upperV > underV) then
  1239.         return under
  1240.     else
  1241.         return upper
  1242.     end
  1243. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement