Advertisement
HR_Shaft

Gun-Game/Arms Race Classic v5 for Phasor v2+

Jan 15th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 63.36 KB | None | 0 0
  1. --[[ ###  Gun-Game/Arms Race v5 'UP'  ###]]--
  2. --[[ ###  by H® Shaft for Phasor v2   ###]]--
  3.  
  4. -- GUN GAME: Based on the Counter Strike game called 'Gun Game.' Also, derivatives known as 'Global Offensive' & 'Arsenal: Arms Race' by Valve
  5. -- Compatible with CTF & Slayer gametypes only! Pre-fabricated gametypes for both PC and CE: http://www.mediafire.com/download/2jtch51nba7cmcs/gungame_gametypes.zip
  6.  
  7. -- GAME PLAY:
  8. -- Each time you kill with a weapon, you will be given a new weapon. (oddball and flag: excluded weapons)
  9. -- The first person to kill with each weapon in the game - wins!
  10. -- There are 10 weapons. You can only use the weapon you are given. All weapons have infinite ammo.
  11. -- When you kill another player, you will only advance if you survive the kill.  If you die during the kill, you don't advance.
  12. -- Melee is instant kill and will advance your level.
  13. -- If you are on level 10 (final level), and get killed by another player, betray or suicide, you are demoted one level.
  14. -- Beserk Mode: When reaching level 10, you activate 'Beserk Mode' which temporarily speeds up all other players and heals the injured.
  15. -- Your player speed is based on your weapon: With a strong weapon, you move slower than you will with a weaker weapon.
  16.  
  17. -- SERVER SETUP - USAGE: --- scroll to very bottom for additional info
  18.  
  19. -- edit --
  20. logging = false         -- | true enable full script game logging: false = disable, true = enable, see also line 92 - can be spammy to the log, best used for tournaments/scrims/debugging
  21. autobal_delay = 15      -- | Time in seconds to delay balancing teams during the game and when players join or leave, you should not go lower than 10 seconds
  22. -- don't edit --
  23. team_play = false
  24. map_reset = false
  25. beserk = false
  26. weapons = {}
  27. level = {}
  28. last_damage = {}
  29. team_change = {}
  30. mybattery = {}
  31. playerscore = {}
  32. teamscore = {}
  33. needler_clip = 40
  34. shotgun_clip = 12
  35. assault_clip = 60
  36. flame_clip = 200
  37. pistol_clip = 12
  38. rocket_clip = 2
  39. sniper_clip = 4
  40. battery = 0
  41. cur_players = 0
  42. timerCount = 0
  43. game_autobal = nil
  44. showtargets = nil
  45. roaming_targets = true
  46.  
  47. -- prefix globals
  48. default_script_prefix = "\171 GunGame \187  "
  49. phasor_privatesay = privatesay
  50. phasor_say = say
  51.  
  52. function GetRequiredVersion()
  53.     return 200
  54. end
  55.  
  56. function OnScriptLoad(process, game, persistent)
  57.     GAME = game
  58.     GetGameAddresses(game)
  59.     processid = process
  60.     Persistent = persistent
  61.     ScriptLoad()
  62. end
  63.  
  64. function OnScriptUnload()
  65.     writedword(ctf_score_patch, 0xFFFDE9E8)
  66.     writebyte(ctf_score_patch1, 0xFF)
  67.     writebyte(slayer_score_patch, 0x74)
  68.     writebyte(slayer_score_patch2, 0x75)
  69. end
  70.  
  71. function OnNewGame(map)
  72.     ScriptLoad()   
  73.     team_play = getteamplay()
  74.     gametype = readbyte(gametype_base + 0x30)
  75.     game_started = false
  76.    
  77.     if not new_game_timer then
  78.         new_game_timer = registertimer(0, "NewGameTimer")
  79.     end
  80. end
  81.  
  82. function ApplyPatches()
  83.     writedword(ctf_score_patch, 0x90909090)
  84.     writebyte(ctf_score_patch1, 0x90)
  85.     writebyte(slayer_score_patch, 0xEB)
  86.     writebyte(slayer_score_patch2, 0xEB)
  87. end    
  88.  
  89. function ScriptLoad()
  90.     if Persistent then
  91.         -- edit --
  92.         logging = false         -- | true enable full script game logging: false = disable, true = enable, see also line 22 - can be spammy to the log, best used for tournaments/scrims/debugging
  93.         autobal_delay = 15      -- | Time in seconds to delay balancing teams during the game and when players join or leave, you should not go lower than 10 seconds
  94.         -- don't edit --
  95.         game_started = false
  96.         team_play = false
  97.         beserk = false     
  98.         weapons = {}
  99.         level = {}
  100.         last_damage = {}
  101.         team_change = {}
  102.         mybattery = {}
  103.         playerscore = {}
  104.         teamscore = {}
  105.         needler_clip = 20
  106.         shotgun_clip = 12
  107.         assault_clip = 60
  108.         flame_clip = 100
  109.         pistol_clip = 12
  110.         rocket_clip = 2
  111.         sniper_clip = 4
  112.         battery = 0
  113.         cur_players = 0
  114.         timerCount = 0
  115.         game_autobal = nil
  116.         roaming_targets = false    
  117.  
  118.         if new_game_timer == nil then
  119.             new_game_timer = registertimer(0, "NewGameTimer")
  120.         end        
  121.     end
  122.    
  123.     GetGameAddresses(game)
  124.     showtargets = nil
  125.     ApplyPatches()
  126.     game_started = false
  127.     team_play = false  
  128.     team_play = getteamplay()
  129.     beserk = false
  130.     gametype = readbyte(gametype_base + 0x30)
  131.     cur_players = readword(network_base, 0x1A0)
  132.    
  133.     for i = 0,15 do
  134.         if getplayer(i) then
  135.             local hash = gethash(i)
  136.             last_damage[hash] = nil
  137.             mybattery[i] = 1
  138.             weapons[i] = "weapons\\plasma pistol\\plasma pistol"
  139.             level[i] = 1
  140.             playerscore[i] = 0
  141.             team_change[i] = false
  142.             cur_players = cur_players + 1
  143.         end
  144.     end
  145.  
  146.     if gametype ~= 5 and cur_players > 2 then
  147.         roaming_targets = true      -- | true enable roaming target/navs to appear over heads of all players. false = disable
  148.         showtargets = registertimer(250, "ShowTargets")
  149.     end    
  150.    
  151.     if team_play and game_autobal == nil then
  152.         game_autobal = registertimer(autobal_delay * 1000, "AutoBalance")
  153.     end    
  154.    
  155.     if gametype == 3 or gametype == 4 or gametype == 5 then
  156.         for i=0,15 do
  157.             if getplayer(i) then
  158.                 privatesay(i, "Koth, Oddball & Race gametypes are not compatible with Gun-Game. ", false)
  159.             end
  160.         end    
  161.         log_msg(4, "#GUN-GAME# Koth, Oddball & Race gametypes are NOT compatible with Gun-Game: try CTF or Slayer.") -- log in scripts log
  162.         log_msg(1, "#GUN-GAME# Koth, Oddball & Race gametypes are NOT compatible with Gun-Game: try CTF or Slayer.") -- log in game log
  163.     else
  164.         game_started = false
  165.         if new_game_timer == nil then
  166.             new_game_timer = registertimer(0, "NewGameTimer")
  167.         end    
  168.     end
  169.        
  170. end
  171.  
  172. function OnPlayerJoin(player)
  173.     if getplayer(player) then
  174.         local name = getname(player)
  175.         cur_players = cur_players + 1
  176.         mybattery[player] = 1
  177.         weapons[player] = "weapons\\plasma pistol\\plasma pistol"
  178.         level[player] = 1
  179.         playerscore[player] = 0
  180.         team_change[player] = false
  181.         welcome = registertimer(9000, "Welcome", player)
  182.         if game_started and team_play and cur_players > 3 then
  183.             join_autobal = registertimer(autobal_delay * 1000, "AutoBalance")
  184.         end
  185.         if game_started and cur_players > 2 and roaming_targets and not showtargets then
  186.             if gametype ~= 5 then
  187.                 showtargets = registertimer(250, "ShowTargets")
  188.             end
  189.         end        
  190.         if team_play and cur_players > 3 and not game_autobal then
  191.             game_autobal = registertimer(autobal_delay * 1000, "AutoBalance")
  192.         end
  193.         if logging then log_msg(1, name .. " given plasma pistol on spawn.") end   
  194.     end
  195. end
  196.  
  197. function Welcome(id, count, player)
  198.     if count == 1 then
  199.         if getplayer(player) then
  200.             privatesay(player, "Welcome to Gun-Game Arms Race!")
  201.             privatesay(player, "Each time you kill with a weapon, you will be given a new weapon.")
  202.             privatesay(player, "The first person to kill with every weapon in the game - wins!")
  203.             privatesay(player, "This version is 'UP': Start with Plasma Pistol, end with Plasma Cannon.")
  204.             privatesay(player, "type @help for more info.")
  205.         end
  206.     end
  207.     return false   
  208. end
  209.  
  210. function OnPlayerLeave(player)
  211.     if getplayer(player) then
  212.         cur_players = cur_players - 1
  213.         if level[player] == 10 then
  214.             beserk = false
  215.         end    
  216.         mybattery[player] = {}
  217.         team_change[player] = {}
  218.         weapons[player] = {}
  219.         level[player] = {}
  220.         playerscore[player] = 0
  221.         if game_started and team_play and cur_players > 3 then
  222.             leave_autobal = registertimer(autobal_delay * 1000, "AutoBalance")
  223.         end    
  224.         if team_play and cur_players < 4 and game_autobal then
  225.             game_autobal = nil
  226.         elseif team_play and cur_players > 3 and not game_autobal then 
  227.             game_autobal = registertimer(autobal_delay * 1000, "AutoBalance")
  228.         end
  229.         if cur_players < 3 and showtargets then
  230.             showtargets = nil
  231.         end        
  232.     end
  233. end
  234.  
  235. function OnPlayerSpawn(player, m_objectId)
  236.     if getplayer(player) then
  237.         local hash = gethash(player)
  238.         last_damage[hash] = nil
  239.         team_change[player] = false
  240.         if game_started then
  241.             gameweap = registertimer(0, "AssignGameWeapons", player)
  242.         end    
  243.     end
  244. end
  245.  
  246. function OnServerCommand(player, command)
  247.     local allow = nil
  248.     local cmd = tokenizecmdstring(command)
  249.     local tokencount = #cmd
  250.     if tokencount > 0 then
  251.    
  252.         if cmd[1] == "sv_map_reset" then
  253.             map_reset = true
  254.             showtargets = nil          
  255.             ScriptLoad()
  256.             privatesay(player, "**RESET** The game has been reset and scripts reloaded. ")
  257.             if logging then log_msg(1, getname(player) .. " used sv_map_reset command.") end           
  258.             for i=0,15 do  
  259.                 if getplayer(i) then
  260.                     privatesay(i, "The game has been reset. ")
  261.                 end
  262.             end        
  263.             allow = true
  264.            
  265.         elseif cmd[1] == "sv_script_reload" then
  266.             map_reset = true
  267.             writedword(gametime_base + 0x10, 0)
  268.             showtargets = nil
  269.             ScriptLoad()
  270.             privatesay(player, "**RELOAD** The game has been reset and scripts reloaded. ")
  271.             if logging then log_msg(1, getname(player) .. " used sv_script_reload command.") end
  272.             for i=0,15 do  
  273.                 if getplayer(i) then
  274.                     kill(i)
  275.                     privatesay(i, "The game has been reset. ")
  276.                 end
  277.             end        
  278.             allow = true
  279.         end
  280.        
  281.     end
  282.     return allow
  283. end
  284.  
  285. function NewGameTimer(id, count)
  286.     if map_reset == true then
  287.         if team_play and cur_players > 3 then Balance_Teams() end
  288.         map_reset = false
  289.     end
  290.    
  291.     game_started = true
  292.     team_play = getteamplay()
  293.    
  294.     if team_play then
  295.         teamscore[0] = 0
  296.         teamscore[1] = 0
  297.         for i=0,15 do
  298.             if getplayer(i) then
  299.                 cur_players = cur_players + 1
  300.             end
  301.         end        
  302.         if not game_autobal and game_started and cur_players > 3 then
  303.             game_autobal = registertimer(autobal_delay * 1000, "AutoBalance")
  304.         end        
  305.     end    
  306.    
  307.     if Persistent then
  308.         if logging then log_msg(1, "Gun-Game has begun on " .. map_name .. " and running as a persistent script.") end
  309.     else
  310.         if logging then log_msg(1, "Gun-Game has begun on " .. map_name .. " and running as a non-persistent script.") end
  311.     end
  312.    
  313.     for x = 0,15 do
  314.         if getplayer(x) then
  315.             local hash = gethash(x)
  316.             local name = getname(x)
  317.             local m_objectId = getplayerobjectid(x)
  318.             last_damage[hash] = nil
  319.             team_change[x] = false
  320.             beserk = false
  321.             mybattery[x] = 0   
  322.             weapons[x] = "weapons\\plasma pistol\\plasma pistol"
  323.             level[x] = 1
  324.             playerscore[x] = 0
  325.             speedtimer = registertimer(0, "SpeedTimer", x)
  326.            
  327.             if m_objectId ~= nil then
  328.                 local m_object = getobject(m_objectId)
  329.                 if m_object then
  330.                     for i = 0,3 do
  331.                         local weapID = readdword(getobject(m_objectId), 0x2F8 + i*4)
  332.                         if weapID ~= 0xFFFFFFFF then
  333.                             destroyobject(weapID)
  334.                         end
  335.                     end
  336.                     writebyte(m_object + 0x31E, 0)
  337.                     writebyte(m_object + 0x31F, 0) 
  338.                 end
  339.                
  340.                 if level[x] == 1 then
  341.                     battery = 0
  342.                     weapons[x] = "weapons\\plasma pistol\\plasma pistol"
  343.                     sendconsoletext(x, "Plasma Pistol - Level 1", 4, 0)
  344.                     if m_object then
  345.                         writebyte(m_object + 0x31E, 2)
  346.                         writebyte(m_object + 0x31F, 0) 
  347.                     end
  348.                 end
  349.                
  350.                 local m_weaponId = createobject(gettagid("weap", weapons[x]), 0, 20, false, 0, 0, 0)
  351.                
  352.                 if m_weaponId then
  353.                     local m_weapon = getobject(m_weaponId)
  354.                     if m_weapon then
  355.                         assignweapon(x, m_weaponId)
  356.                         if logging then log_msg(1, name .. " given plasma pistol on new game.") end
  357.                         if m_weapon then
  358.                             mybattery[x] = 1
  359.                         end
  360.                     end    
  361.                 end
  362.                
  363.             end
  364.         end
  365.     end
  366.    
  367.     if updatescores == nil and game_started then
  368.         updatescores = registertimer(500, "Update_Scores")
  369.     end
  370.    
  371.     if checkbattery == nil and game_started then
  372.         checkbattery = registertimer(1000, "CheckBattery") 
  373.     end
  374.    
  375.     new_game_timer = nil   
  376.     return false
  377. end
  378.  
  379. function AssignGameWeapons(id, count, player)
  380.     if map_reset == true then
  381.         map_reset = false
  382.     end
  383.    
  384.     local clip = 0
  385.     local ammo = 9999
  386.    
  387.     if game_started then   
  388.         if getplayer(player) then      
  389.             local m_objectId = getplayerobjectid(player)
  390.             local name = getname(player)
  391.             local lvl = level[player]
  392.             local team = getteam(player)
  393.            
  394.             if m_objectId ~= nil then
  395.                 if gametype == 1 or gametype == 2 then
  396.                     speedtimer = registertimer(0, "SpeedTimer", player)
  397.                 end
  398.                
  399.                 local m_object = getobject(m_objectId)
  400.                 if m_object then
  401.                     for i = 0,3 do
  402.                         local weapID = readdword(getobject(m_objectId), 0x2F8 + i*4)
  403.                         if weapID ~= 0xFFFFFFFF then
  404.                             destroyobject(weapID)
  405.                         end
  406.                     end
  407.                     writebyte(m_object + 0x31E, 0)
  408.                     writebyte(m_object + 0x31F, 0) 
  409.                 end
  410.                
  411.                 if logging then log_msg(1, name .. " weapon assignment initiated - weapons & nades removed. Is level: " .. lvl) end
  412.                
  413.                 if level[player] == nil then
  414.                     level[player] = 1
  415.                     weapons[player] = "weapons\\plasma pistol\\plasma pistol"
  416.                     sendconsoletext(player, "Level 1:   Plasma Pistol", 4, 0)  
  417.                     if m_object then
  418.                         writebyte(m_object + 0x31E, 1)
  419.                         writebyte(m_object + 0x31F, 1) 
  420.                     end
  421.                     if logging then log_msg(1, name .. " given plasma pistol, 1 frag, 1 plasma. Is level: " .. lvl) end
  422.                    
  423.                 elseif level[player] == 1 then
  424.                     weapons[player] = "weapons\\plasma pistol\\plasma pistol"
  425.                     sendconsoletext(player, "Level 1:   Plasma Pistol", 4, 0)
  426.                     if m_object then
  427.                         writebyte(m_object + 0x31E, 1)
  428.                         writebyte(m_object + 0x31F, 1) 
  429.                     end
  430.                    
  431.                     if logging then log_msg(1, name .. " given plasma pistol, 1 frag, 1 plasma. Is level: " .. lvl) end
  432.                    
  433.                 elseif level[player] == 2 then
  434.                     clip = needler_clip
  435.                     weapons[player] = "weapons\\needler\\mp_needler"
  436.                     sendconsoletext(player, "Level 2:   Needler", 4, 0)
  437.                     if m_object then
  438.                         writebyte(m_object + 0x31E, 0)
  439.                         writebyte(m_object + 0x31F, 2) 
  440.                     end
  441.                     if logging then log_msg(1, name .. " given needler, active camouflage, 2 plasmas. Is level: " .. lvl) end  
  442.                    
  443.                 elseif level[player] == 3 then
  444.                     clip = shotgun_clip
  445.                     weapons[player] = "weapons\\shotgun\\shotgun"
  446.                     sendconsoletext(player, "Level 3:   Shotgun", 4, 0)
  447.                     health = registertimer(0, "ApplyHP", player)
  448.                     if m_object then
  449.                         writebyte(m_object + 0x31E, 1)
  450.                         writebyte(m_object + 0x31F, 0)
  451.                     end                
  452.                     if logging then log_msg(1, name .. " given shotgun, 1 frag, active camouflage removed. Is level: " .. lvl) end
  453.                    
  454.                 elseif level[player] == 4 then
  455.                     weapons[player] = "weapons\\plasma rifle\\plasma rifle"
  456.                     sendconsoletext(player, "Level 4:   Plasma Rifle", 4, 0)
  457.                     if m_object then
  458.                         writebyte(m_object + 0x31E, 0)
  459.                         writebyte(m_object + 0x31F, 2)
  460.                     end
  461.                     if logging then log_msg(1, name .. " given plasma rifle, 2 plasmas. Is level: " .. lvl) end
  462.                    
  463.                 elseif level[player] == 5 then
  464.                     clip = assault_clip
  465.                     weapons[player] = "weapons\\assault rifle\\assault rifle"
  466.                     sendconsoletext(player, "Level 5:   Assault Rifle", 4, 0)
  467.                     if m_object then
  468.                         writebyte(m_object + 0x31E, 1)
  469.                         writebyte(m_object + 0x31F, 0)
  470.                     end                
  471.                     if logging then log_msg(1, name .. " given assault rifle, 1 frag. Is level: " .. lvl) end
  472.                    
  473.                 elseif level[player] == 6 then
  474.                     clip = flame_clip
  475.                     weapons[player] = "weapons\\flamethrower\\flamethrower"
  476.                     sendconsoletext(player, "Level 6: Flamethrower", 4, 0)
  477.                     health = registertimer(0, "ApplyHP", player)   
  478.                     if logging then log_msg(1, name .. " given flamethrower. Is level: " .. lvl) end   
  479.                    
  480.                 elseif level[player] == 7 then
  481.                     clip = pistol_clip
  482.                     weapons[player] = "weapons\\pistol\\pistol"
  483.                     sendconsoletext(player, "Level 7:   Pistol", 4, 0)                 
  484.                     if logging then log_msg(1, name .. " given pistol. Is level: " .. lvl) end
  485.                    
  486.                 elseif level[player] == 8 then
  487.                     clip = rocket_clip
  488.                     weapons[player] = "weapons\\rocket launcher\\rocket launcher"
  489.                     sendconsoletext(player, "Level 8:   Rocket Launcher", 4, 0)
  490.                     health = registertimer(0, "ApplyHP", player)                   
  491.                     if logging then log_msg(1, name .. " given rocket launcher. Is level: " .. lvl) end
  492.                    
  493.                 elseif level[player] == 9 then
  494.                     clip = sniper_clip
  495.                     weapons[player] = "weapons\\sniper rifle\\sniper rifle"
  496.                     sendconsoletext(player, "Level 9:   Sniper Rifle", 4, 0)   
  497.                     health = registertimer(0, "ApplyHP", player)       
  498.                     if logging then log_msg(1, name .. " given sniper rifle. Is level: " .. lvl) end   
  499.                    
  500.                 elseif level[player] == 10 then
  501.                     weapons[player] = "weapons\\plasma_cannon\\plasma_cannon"
  502.                     beserk = true
  503.                     sendconsoletext(player, "Level 10:   Plasma Cannon --- FINAL LEVEL! ---", 4, 0)
  504.                     say(name .. " has reached level 10! Beserk mode activated! Kill 'em!")             
  505.                     if logging then log_msg(1, name .. " given plasma cannon and booster function called. Is level: " .. lvl) end
  506.  
  507.                     --Health Booster call for all but level 10
  508.                     for i=0,15 do
  509.                         if getplayer(i) then
  510.                             local name = getname(i)
  511.                             local lvl = level[i]
  512.                             local p_objectId = getplayerobjectid(i)
  513.                             if p_objectId ~= nil then
  514.                                 if lvl <= 9 then
  515.                                     local p_object = getobject(p_objectId)
  516.                                     local obj_health = readfloat(p_object + 0xE0)
  517.                                     if obj_health < 1 then
  518.                                         p_objectId = registertimer(6000, "Booster", {i, m_objectId})
  519.                                     end
  520.                                 end
  521.                             end
  522.                         end
  523.                     end
  524.                    
  525.                 end
  526.                
  527.                 local m_weaponId = createobject(gettagid("weap", weapons[player]), 0, 20, false, 0, 0, 0)
  528.                
  529.                 if m_weaponId then
  530.                     local m_weapon = getobject(m_weaponId)
  531.                     assignweapon(player, m_weaponId)
  532.                     if m_weapon then
  533.                         if (level[player] == 1) or (level[player] == 4) or (level[player] == 10) then
  534.                             mybattery[player] = 1
  535.                         else
  536.                             mybattery[player] = 0
  537.                             writeword(m_weapon + 0x2B6, ammo)
  538.                             writeword(m_weapon + 0x2B8, clip)
  539.                             updateammo(m_weaponId)
  540.                         end
  541.                     end
  542.                 end
  543.                
  544.             end
  545.         end
  546.     end    
  547.     return false
  548. end
  549.  
  550. function OnWeaponReload(player, weapon)
  551.     local reload = nil
  552.         if getplayer(player) then
  553.             local m_player = getplayer(player)
  554.             local m_objectId = readdword(m_player + 0x34)
  555.             local m_object = getobject(m_objectId)
  556.             if m_object then
  557.                 local m_weaponId = readdword(m_object + 0x118)
  558.                 if m_weaponId then
  559.                     local m_weapon = getobject(m_weaponId)         
  560.                     local weapname = gettaginfo(readdword(m_weapon))
  561.                     if m_weapon then
  562.                         if weapname == "weapons\\needler\\mp_needler" then
  563.                             writeword(getobject(weapon) + 0x2B8, needler_clip)
  564.                             updateammo(weapon)
  565.                             reload = false
  566.                         elseif weapname == "weapons\\flamethrower\\flamethrower" then
  567.                             writeword(getobject(weapon) + 0x2B8, flame_clip)
  568.                             updateammo(weapon)
  569.                             reload = false 
  570.                         else
  571.                             reload = true
  572.                         end
  573.                     end    
  574.                 end
  575.             end
  576.         end
  577.     return reload
  578. end
  579.  
  580. function CheckBattery(id, count, player)
  581.     -- checks battery level for plasma weapons and assigns replacement if low battery: plasma pistol, plasma rifle and plasma cannon
  582.     for i = 0,15 do
  583.         if getplayer(i) then
  584.             if mybattery[i] == 1 then
  585.                 local name = getname(i)
  586.                 local lvl = level[i]
  587.                 local m_objectId = getplayerobjectid(i)
  588.                 if m_objectId ~= nil then
  589.                     local m_object = getobject(m_objectId)
  590.                     if m_object then
  591.                         local m_weaponId = readdword(m_object + 0x118)
  592.                         if m_weaponId then
  593.                             local m_weapon = getobject(m_weaponId)
  594.                             if m_weapon then   
  595.                                 if readfloat(m_weapon + 0x240) >= 0.84 then
  596.                                     destroyplayerweaps(i)
  597.                                     replaceplasmaweap = registertimer(0, "ReplacePlasmaWeap", i)
  598.                                     if logging then log_msg(1, name .. " has a low battery on battery check. Is level: " .. lvl) end
  599.                                 end
  600.                             end
  601.                         end
  602.                     end
  603.                 end
  604.             end
  605.         end
  606.     end
  607.     return true
  608. end
  609.  
  610. function ReplacePlasmaWeap(id, count, player)
  611.     -- replaces low battery plasma weapons
  612.     if count == 1 then 
  613.         if player ~= nil and game_started then
  614.             local name = getname(player)
  615.             local lvl = level[player]  
  616.             if mybattery[player] == 1 then
  617.                 local m_weaponId = registertimer(0, "AssignGameWeapons", player)
  618.                 if logging then log_msg(1, name .. " was given assigment to replace plasma weapon. Is level: " .. lvl) end
  619.                 privatesay(player, "Battery recharged.")
  620.                 mybattery[player] = 0  
  621.             end    
  622.         end
  623.     end
  624.     return false
  625. end
  626.  
  627. function Update_Scores(id, count)
  628.     -- continuous score updating, not conditioned to game_started, updates negative values to 0 to prevent sabotage
  629.     if not team_play then
  630.         for i = 0,15 do
  631.             if getplayer(i) then
  632.                 if playerscore[i] == nil or playerscore[i] < 0 then playerscore[i] = 0 end
  633.                 Write_Player_Score(i, playerscore[i])
  634.             end
  635.         end    
  636.     else
  637.         for i = 0,15 do
  638.             if getplayer(i) then
  639.                 if playerscore[i] == nil or playerscore[i] < 0 then playerscore[i] = 0 end
  640.                 Write_Player_Score(i, playerscore[i])
  641.             end
  642.         end
  643.         if teamscore[0] == nil or teamscore[0] < 0 then teamscore[0] = 0 end
  644.         if teamscore[1] == nil or teamscore[1] < 0 then teamscore[1] = 0 end
  645.         Write_Team_Score(0, teamscore[0])
  646.         Write_Team_Score(1, teamscore[1])
  647.     end
  648.     return true
  649. end                
  650.  
  651. function Write_Player_Score(player, score)
  652.     -- writes the players score
  653.     if gametype == 1 then
  654.         if player then
  655.             local m_player = getplayer(player)
  656.             writeword(m_player + 0xC8, score)
  657.         end
  658.     elseif gametype == 2 then
  659.         if player then
  660.             writedword(slayer_globals + 0x40 + player*4, score)
  661.         end
  662.     end
  663. end
  664.  
  665. function Write_Team_Score(team, score)
  666.     -- writes the team score
  667.     if gametype == 1 then
  668.         writedword(ctf_globals + team*4 + 0x10, score)
  669.     elseif gametype == 2 then
  670.         writedword(slayer_globals + team*4, score)
  671.     end
  672. end
  673.  
  674. function GetGameAddresses(game)
  675.     if game == "PC" or GAME == "PC" then
  676.         map_name = readstring(0x698F21)
  677.         gametype_base = 0x671340
  678.         ctf_globals = 0x639B98
  679.         ctf_score_patch = 0x488602
  680.         ctf_score_patch1 = 0x488606    
  681.         slayer_globals = 0x63A0E8
  682.         slayer_score_patch = 0x48F428
  683.         slayer_score_patch2 = 0x48F23E 
  684.         network_base = 0x745BA8
  685.         gametime_base = 0x671420       
  686.     else
  687.         map_name = readstring(0x61D151)
  688.         gametype_base = 0x5F5498
  689.         ctf_globals = 0x5BDBB8
  690.         ctf_score_patch = 0x463472
  691.         ctf_score_patch1 = 0x463476
  692.         slayer_globals = 0x5BE108
  693.         slayer_score_patch = 0x469CF8
  694.         slayer_score_patch2 = 0x4691CE
  695.         network_base = 0x6C7988
  696.         gametime_base = 0x5F55BC       
  697.     end
  698. end
  699.  
  700. function getteamplay()
  701.     if readbyte(gametype_base + 0x34) == 1 then
  702.         return true
  703.     else
  704.         return false
  705.     end
  706. end
  707.  
  708. function privatesay(player, message, script_prefix)
  709.     if GAME == "PC" then
  710.         phasor_privatesay(player, (script_prefix or default_script_prefix) .. " " .. message, false)
  711.     else
  712.         phasor_privatesay(player, message, false)
  713.     end
  714. end
  715.  
  716. function say(message, script_prefix)
  717.     if GAME == "PC" then
  718.         phasor_say((script_prefix or default_script_prefix) .. " " .. message, false)
  719.     else
  720.         phasor_say(message, false)
  721.     end
  722. end
  723.  
  724. function getweaponobjectid(player, slot)
  725.     local m_objectId = getplayerobjectid(player)
  726.     if m_objectId then return readdword(getobject(m_objectId) + 0x2F8 + slot*4) end
  727. end
  728.  
  729. function destroyplayerweaps(player)
  730.     for i=0,3 do
  731.         local weap_id = getweaponobjectid(player, i)
  732.         if weap_id ~= 0xFFFFFFFF then destroyobject(weap_id) end
  733.     end
  734. end
  735.  
  736. function Booster(id, count, arg)
  737.     -- heals all players level 9 and below when any other player reaches level 10
  738.     if count == 1 and game_started then
  739.         local player = arg[1]
  740.         if getplayer(player) then
  741.             local name = getname(player)
  742.             local lvl = level[player]      
  743.             local m_playerObjId = getplayerobjectid(player)
  744.             if m_playerObjId ~= nil and lvl <= 9 then
  745.                 local m_object = getobject(m_playerObjId)
  746.                 local obj_health = readfloat(m_object + 0xE0)
  747.                 if obj_health < 1 then
  748.                     writefloat(m_object + 0xE0, 1)
  749.                     sendconsoletext(player, "Bonus! Health restored!", 4, 0)
  750.                     if logging then log_msg(1, name .. " health restored from booster function. Is level: " .. lvl) end
  751.                 end
  752.             end
  753.         end
  754.     end
  755.     return false
  756. end
  757.  
  758. function SpeedTimer(id, count, player)
  759.     -- monitors player levels, and sets player speed accordingly. Also sets Beserk Mode speed.
  760.     if player then
  761.         local name = getname(player)
  762.         local lvl = level[player]  
  763.         if level[player] == 1 then
  764.             if beserk then
  765.                 setspeed(player, 1.5)
  766.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  767.             else   
  768.                 setspeed(player, 1.45) -- plasma pistol
  769.             end
  770.             if logging then log_msg(1, name .. " speed set at 1.45. Is level: " .. lvl) end
  771.         elseif level[player] == 2 then
  772.             if beserk then
  773.                 setspeed(player, 1.5)
  774.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  775.             else       
  776.                 setspeed(player, 1.35) -- needler
  777.             end
  778.             if logging then log_msg(1, name .. " speed set at 1.35. Is level: " .. lvl) end
  779.         elseif level[player] == 3 then
  780.             if beserk then
  781.                 setspeed(player, 1.5)
  782.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  783.             else
  784.                 setspeed(player, 1.25) -- shotgun
  785.             end
  786.             if logging then log_msg(1, name .. " speed set at 1.25. Is level: " .. lvl) end
  787.         elseif level[player] == 4 then
  788.             if beserk then
  789.                 setspeed(player, 1.5)
  790.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  791.             else       
  792.                 setspeed(player, 1.15) -- plasma rifle
  793.             end
  794.             if logging then log_msg(1, name .. " speed set at 1.15. Is level: " .. lvl) end
  795.         elseif level[player] == 5 then
  796.             if beserk then
  797.                 setspeed(player, 1.5)
  798.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  799.             else       
  800.                 setspeed(player, 1.15) -- assault rifle
  801.             end
  802.             if logging then log_msg(1, name .. " speed set at 1.15. Is level: " .. lvl) end
  803.         elseif level[player] == 6 then
  804.             if beserk then
  805.                 setspeed(player, 1.5)
  806.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  807.             else       
  808.                 setspeed(player, 1) -- flamethrower
  809.             end
  810.             if logging then log_msg(1, name .. " speed set at 1. Is level: " .. lvl) end
  811.         elseif level[player] == 7 then
  812.             if beserk then
  813.                 setspeed(player, 1.5)
  814.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  815.             else       
  816.                 setspeed(player, 0.85) -- pistol
  817.             end
  818.             if logging then log_msg(1, name .. " speed set at 0.85. Is level: " .. lvl) end
  819.         elseif level[player] == 8 then
  820.             if beserk then
  821.                 setspeed(player, 1.5)
  822.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  823.             else       
  824.                 setspeed(player, 0.65) -- rocket launcher
  825.             end
  826.             if logging then log_msg(1, name .. " speed set at 0.65. Is level: " .. lvl) end
  827.         elseif level[player] == 9 then
  828.             if beserk then
  829.                 setspeed(player, 1.5)
  830.                 sendconsoletext(player, "BESERK MODE!", 4, 1)
  831.             else       
  832.                 setspeed(player, 0.75) -- sniper rifle
  833.             end
  834.             if logging then log_msg(1, name .. " speed set at 0.75. Is level: " .. lvl) end
  835.         elseif level[player] == 10 then
  836.             setspeed(player, 0.65) -- plasma cannon
  837.             if logging then log_msg(1, name .. " speed set at 0.65. Is level: " .. lvl) end
  838.         end
  839.     end
  840.     return false
  841. end
  842.  
  843. function OnServerChat(player, type, message)
  844.     local response = nil
  845.    
  846.     if player then
  847.         local name = getname(player)
  848.        
  849.         if string.lower(message) == "help" or string.lower(message) == "@help" or string.lower(message) == "/help" then
  850.             local response = false
  851.             privatesay(player, "Each time you kill with a weapon, you will be given a new weapon.")
  852.             privatesay(player, "The first person to kill with each weapon in the game - wins!")
  853.             privatesay(player, "There are 10 weapons. Starting with plasma pistol and ending with plasma cannon.")
  854.             privatesay(player, "Other weapons, grenades & powerups are blocked. Killing with vehicles blocked.")
  855.             privatesay(player, "If you are on level 10, and get killed, suicide or betray you're demoted one level.")
  856.             say(name .. " is reading the @help menu. ")
  857.             return response            
  858.         end
  859.        
  860.         if string.lower(message) == "balance" then
  861.             Balance_Teams()
  862.             response = false           
  863.         end
  864.        
  865.     end
  866.     return response
  867. end
  868.  
  869. function OnPlayerKill(killer, victim, mode)
  870.     local response = false
  871.        
  872.     if game_started then
  873.         mybattery[victim] = 0
  874.        
  875.         if mode == 0 then -- player was killed by server
  876.             if getplayer(victim) then
  877.                 if team_change[victim] then
  878.                     response = false   
  879.                 else
  880.                     vlvl = level[victim]
  881.                     vname = getname(victim)
  882.                     privatesay(victim, vname .. " - you were killed by the server.")
  883.                     if logging then log_msg(1, vname .. " was killed by the server. Is level: " .. vlvl) end
  884.                     response = false                       
  885.                 end
  886.                 response = false
  887.             end
  888.            
  889.         elseif mode == 1 then -- player was killed by falling or team-change
  890.                 if getplayer(victim) then
  891.                     vlvl = level[victim]
  892.                     vname = getname(victim)
  893.                     vhash = gethash(victim)
  894.                     if not team_change[victim] and not map_reset then
  895.                         if last_damage[vhash] == "globals\\distance" or last_damage[vhash] == "globals\\falling" then
  896.                             say(vname .. " fell and died.")
  897.                             if logging then log_msg(1, vname .. " was killed by fall damage. Is level: " .. vlvl) end
  898.                             response = false
  899.                         end
  900.                     elseif team_change[victim] and map_reset then
  901.                         team_change[victim] = false
  902.                         if logging then log_msg(1, vname .. " was killed by team change. Is level: " .. vlvl) end
  903.                         response = false                       
  904.                     end
  905.                 end
  906.            
  907.         elseif mode == 2 then -- player was killed by the guardians
  908.             if getplayer(victim) then
  909.                 vlvl = level[victim]
  910.                 vname = getname(victim)
  911.                 say(vname .. " was killed by the guardians. ", false)
  912.                 if logging then log_msg(1, vname .. " was killed by guardians. Is level: " .. vlvl) end
  913.                 response = false
  914.             end
  915.            
  916.         elseif mode == 3 then -- player was killed by vehicle
  917.             if getplayer(victim) then
  918.                 vlvl = level[victim]
  919.                 vname = getname(victim)
  920.                 say(vname .. " was killed by a vehicle. ")
  921.                 if logging then log_msg(1, vname .. " was killed by a vehicle. Is level: " .. vlvl) end
  922.                 response = false
  923.             end
  924.            
  925.         elseif mode == 4 then -- player was killed by another player
  926.             -- killer is not always valid, setup values to prevent error
  927.             if getplayer(killer) then
  928.                 klvl = level[killer]
  929.                 kname = getname(killer)
  930.                 khash = gethash(killer)
  931.                 kteam = getteam(killer)
  932.             else   
  933.                 kname = "NULL"
  934.                 klvl = NULL
  935.                 kteam = -1
  936.                 khash = "00000"
  937.             end
  938.            
  939.             if getplayer(victim) then
  940.                 vlvl = level[victim]
  941.                 vname = getname(victim)
  942.                 vhash = gethash(victim)
  943.                 vteam = getteam(victim)
  944.                 if vlvl == 10 then
  945.                     beserk = false
  946.                     sendconsoletext(victim, "Demoted to Level 9! Ain't that a bitch?!", 4, 0)
  947.                     say(vname .. " demoted to Level 9 for getting killed.")
  948.                     weapons[victim] = "weapons\\sniper rifle\\sniper rifle"
  949.                     level[victim] = 9
  950.                     playerscore[victim] = 8
  951.                     if team_play then if (teamscore[vteam] - 1) >= 0 then teamscore[vteam] = teamscore[vteam] - 1 end end
  952.                     if logging then log_msg(1, vname .. " level 10 demoted to 9 for being killed by another player.") end
  953.                     response = false
  954.                 end
  955.  
  956.                 if last_damage[vhash] then
  957.                     if getplayer(killer) then
  958.                         klvl = level[killer]
  959.                         kname = getname(killer)
  960.                         khash = gethash(killer)
  961.                         kteam = getteam(killer)                    
  962.                         local k_objectId = getplayerobjectid(killer)
  963.                         if k_objectId ~= nil then -- sets condition that killer must be alive for the following
  964.                             if team_play then kteam = getteam(killer) teamscore[kteam] = teamscore[kteam] + 1 end
  965.                                    
  966.                             if last_damage[vhash] == "weapons\\plasma pistol\\bolt" or last_damage[vhash] == "weapons\\plasma rifle\\charged bolt" or last_damage[vhash] == "weapons\\plasma pistol\\melee" or last_damage[vhash] == "weapons\\plasma pistol\\rw charged bolt" then
  967.                                 if weapons[killer] == "weapons\\plasma pistol\\plasma pistol" then
  968.                                     level[killer] = 2
  969.                                     playerscore[killer] = 1
  970.                                     if string.find(last_damage[vhash], "melee") then
  971.                                         say(kname .. " melee'd " .. vname .. " with a plasma pistol")
  972.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  973.                                     else
  974.                                         say(kname .. " killed " .. vname .. " with a plasma pistol")
  975.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  976.                                     end                                    
  977.                                     gameweap = registertimer(0, "AssignGameWeapons", killer)
  978.                                     response = false
  979.                                 end
  980.                                
  981.                             elseif last_damage[vhash] == "weapons\\needler\\detonation damage" or last_damage[vhash] == "weapons\\needler\\explosion" or last_damage[vhash] == "weapons\\needler\\impact damage" or last_damage[vhash] == "weapons\\needler\\melee" then
  982.                                 if weapons[killer] == "weapons\\needler\\mp_needler" then
  983.                                     level[killer] = 3
  984.                                     playerscore[killer] = 2
  985.                                     if string.find(last_damage[vhash], "melee") then
  986.                                         say(kname .. " melee'd " .. vname .. " with a needler")
  987.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  988.                                     else
  989.                                         say(kname .. " killed " .. vname .. " with a needler")
  990.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  991.                                     end
  992.                                     gameweap = registertimer(0, "AssignGameWeapons", killer)
  993.                                     response = false
  994.                                 end
  995.                                
  996.                             elseif last_damage[vhash] == "weapons\\shotgun\\pellet" or last_damage[vhash] == "weapons\\shotgun\\melee" then
  997.                                 if weapons[killer] == "weapons\\shotgun\\shotgun" then
  998.                                     level[killer] = 4
  999.                                     playerscore[killer] = 3
  1000.                                     if string.find(last_damage[vhash], "melee") then
  1001.                                         say(kname .. " melee'd " .. vname .. " with a shotgun")
  1002.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  1003.                                     else
  1004.                                         say(kname .. " killed " .. vname .. " with a shotgun")
  1005.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  1006.                                     end
  1007.                                     gameweap = registertimer(0, "AssignGameWeapons", killer)
  1008.                                     response = false
  1009.                                 end
  1010.                                
  1011.                             elseif last_damage[vhash] == "weapons\\plasma rifle\\bolt" or last_damage[vhash] == "weapons\\plasma rifle\\melee" then                            
  1012.                                 if weapons[killer] == "weapons\\plasma rifle\\plasma rifle" then
  1013.                                     level[killer] = 5
  1014.                                     playerscore[killer] = 4
  1015.                                     if string.find(last_damage[vhash], "melee") then
  1016.                                         say(kname .. " melee'd " .. vname .. " with a plasma rifle")
  1017.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  1018.                                     else                                   
  1019.                                         say(kname .. " killed " .. vname .. " with a plasma rifle")
  1020.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  1021.                                     end
  1022.                                     gameweap = registertimer(0, "AssignGameWeapons", killer)
  1023.                                     response = false
  1024.                                 end
  1025.                                
  1026.                             elseif last_damage[vhash] == "weapons\\assault rifle\\bullet" or last_damage[vhash] == "weapons\\assault rifle\\melee" then
  1027.                                 if weapons[killer] == "weapons\\assault rifle\\assault rifle" then
  1028.                                     level[killer] = 6
  1029.                                     playerscore[killer] = 5
  1030.                                     if string.find(last_damage[vhash], "melee") then
  1031.                                         say(kname .. " melee'd " .. vname .. " with an assault rifle")
  1032.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  1033.                                     else                                   
  1034.                                         say(kname .. " killed " .. vname .. " with an assault rifle")
  1035.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  1036.                                     end
  1037.                                     gameweap = registertimer(0, "AssignGameWeapons", killer)
  1038.                                     response = false
  1039.                                 end
  1040.                                
  1041.                             elseif last_damage[vhash] == "weapons\\flamethrower\\burning" or last_damage[vhash] == "weapons\\flamethrower\\explosion" or last_damage[vhash] == "weapons\\flamethrower\\impact damage" or last_damage[vhash] == "weapons\\flamethrower\\melee" then
  1042.                                 if weapons[killer] == "weapons\\flamethrower\\flamethrower" then
  1043.                                     level[killer] = 7
  1044.                                     playerscore[killer] = 6
  1045.                                     if string.find(last_damage[vhash], "melee") then
  1046.                                         say(kname .. " melee'd " .. vname .. " with a flamethrower")
  1047.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  1048.                                     else                                   
  1049.                                         say(kname .. " killed " .. vname .. " with a flamethrower")
  1050.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  1051.                                     end
  1052.                                     gameweap = registertimer(0, "AssignGameWeapons", killer)
  1053.                                     response = false
  1054.                                 end
  1055.                                
  1056.                             elseif last_damage[vhash] == "weapons\\pistol\\bullet" or last_damage[vhash] == "weapons\\pistol\\melee" then
  1057.                                 if weapons[killer] == "weapons\\pistol\\pistol" then
  1058.                                     level[killer] = 8
  1059.                                     playerscore[killer] = 7
  1060.                                     if string.find(last_damage[vhash], "melee") then
  1061.                                         say(kname .. " melee'd " .. vname .. " with a pistol")
  1062.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  1063.                                     else                                   
  1064.                                         say(kname .. " killed " .. vname .. " with a pistol")
  1065.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  1066.                                     end
  1067.                                     gameweap = registertimer(0, "AssignGameWeapons", killer)
  1068.                                     response = false
  1069.                                 end
  1070.                                    
  1071.                             elseif last_damage[vhash] == "weapons\\rocket launcher\\explosion" or last_damage[vhash] == "weapons\\rocket launcher\\melee" then
  1072.                                 if weapons[killer] == "weapons\\rocket launcher\\rocket launcher" then
  1073.                                     if isinvehicle(killer) then
  1074.                                         say(kname .. " killed " .. vname .. " with a warthog rocket")
  1075.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl .. " was vehicle rocket, no advance.") end
  1076.                                     else
  1077.                                         level[killer] = 9
  1078.                                         playerscore[killer] = 8
  1079.                                         if string.find(last_damage[vhash], "melee") then
  1080.                                             say(kname .. " melee'd " .. vname .. " with a rocket launcher")
  1081.                                             if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  1082.                                         else                                       
  1083.                                             say(kname .. " killed " .. vname .. " with a rocket launcher")
  1084.                                             if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  1085.                                         end
  1086.                                         gameweap = registertimer(0, "AssignGameWeapons", killer)
  1087.                                         response = false
  1088.                                     end
  1089.                                 end
  1090.                                
  1091.                             elseif last_damage[vhash] == "weapons\\sniper rifle\\sniper bullet" or last_damage[vhash] == "weapons\\sniper rifle\\melee" then
  1092.                                 if weapons[killer] == "weapons\\sniper rifle\\sniper rifle" then
  1093.                                     level[killer] = 10
  1094.                                     playerscore[killer] = 9
  1095.                                     beserk = true
  1096.                                     for i=0,15 do
  1097.                                         if getplayer(i) then
  1098.                                             speedtimer = registertimer(0, "SpeedTimer", i)
  1099.                                         end
  1100.                                     end    
  1101.                                     if string.find(last_damage[vhash], "melee") then
  1102.                                         say(kname .. " melee'd " .. vname .. " with a sniper rifle, advanced to Level 10!")
  1103.                                     else                                   
  1104.                                         say(kname .. " killed " .. vname .. " with a sniper rifle, advanced to Level 10!")
  1105.                                     end
  1106.                                     if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  1107.                                     gameweap = registertimer(0, "AssignGameWeapons", killer)
  1108.                                     response = false                               
  1109.                                 end
  1110.                                
  1111.                             elseif last_damage[vhash] == "weapons\\plasma_cannon\\effects\\plasma_cannon_explosion" or last_damage[vhash] == "weapons\\plasma_cannon\\effects\\plasma_cannon_melee" then
  1112.                                 if weapons[killer] == "weapons\\plasma_cannon\\plasma_cannon" then
  1113.                                     level[killer] = 11
  1114.                                     playerscore[killer] = playerscore[killer] + 11
  1115.                                     if team_play then kteam = getteam(killer) teamscore[kteam] = teamscore[kteam] + 11 end
  1116.                                     beserk = false
  1117.                                     if string.find(last_damage[vhash], "melee") then
  1118.                                         say(kname .. " melee'd " .. vname .. " with a plasma cannon, advanced to WIN! +10 Points")
  1119.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s melee who is level: " .. klvl) end
  1120.                                     else                                   
  1121.                                         say(kname .. " killed " .. vname .. " with a plasma cannon, advanced to WIN! +10 Points")
  1122.                                         if logging then log_msg(1, vname .. " was killed by " .. kname .. " who is level: " .. klvl) end
  1123.                                     end
  1124.                                     response = false
  1125.                                 end
  1126.                                
  1127.                             elseif last_damage[vhash] == "weapons\\plasma grenade\\explosion" or last_damage[vhash] == "weapons\\frag grenade\\explosion" then
  1128.                                 say(kname .. " killed " .. vname .. " with a grenade.")
  1129.                                 sendconsoletext(killer, "No level advancement for grenade kills.", 4, 0)
  1130.                                 if logging then log_msg(1, vname .. " was killed by " .. kname .. "'s grenade who is level: " .. klvl) end
  1131.                                 response = false                           
  1132.                             end
  1133.                         else
  1134.                             response = false
  1135.                         end
  1136.                     end
  1137.                 end
  1138.             end
  1139.            
  1140.         elseif mode == 5 then -- player was killed/betrayed by teammate
  1141.             if getplayer(killer) then
  1142.                 klvl = level[killer]
  1143.                 kname = getname(killer)
  1144.                 khash = gethash(killer)
  1145.                 kteam = getteam(killer)                
  1146.             else   
  1147.                 kname = "NULL"
  1148.                 klvl = NULL
  1149.                 kteam = -1 
  1150.             end
  1151.            
  1152.             if getplayer(victim) then
  1153.                 vlvl = level[victim]
  1154.                 vname = getname(victim)
  1155.                 vhash = gethash(victim)
  1156.                 vteam = getteam(victim)
  1157.                 if getplayer(killer) then
  1158.                     klvl = level[killer]
  1159.                     kname = getname(killer)
  1160.                     khash = gethash(killer)
  1161.                     kteam = getteam(killer)
  1162.                     if vlvl == 10 then
  1163.                         level[killer] = 9
  1164.                         playerscore[killer] = 8
  1165.                         beserk = false
  1166.                         weapons[killer] = "weapons\\sniper rifle\\sniper rifle"
  1167.                         sendconsoletext(killer, "Demoted to Level 9! Ain't that a bitch?!", 4, 0)
  1168.                         say(vname .. " demoted to Level 9 for betrayal.")
  1169.                         beserk = false
  1170.                     else       
  1171.                         if level[killer] ~= nil and level[killer] > 1 then
  1172.                             if (level[killer] - 1) >= 1 then level[killer] = level[killer] - 1 end
  1173.                             if (playerscore[killer] - 1) >= 0 then playerscore[killer] = playerscore[killer] - 1 end
  1174.                             if team_play then if (teamscore[kteam] - 1) >= 0 then teamscore[kteam] = teamscore[kteam] - 1 end end
  1175.                             mybattery[killer] = 0
  1176.                             kill(killer)
  1177.                             say(kname .. " was demoted one level and killed for betraying " .. vname)
  1178.                             if logging then log_msg(1, kname .. " was killed by server for betrayal of " .. vname) end
  1179.                             response = false
  1180.                         else
  1181.                             kill(killer)
  1182.                             say(kname .. " was killed for betraying " .. vname)
  1183.                             if logging then log_msg(1, kname .. " was killed by server for betrayal of " .. vname) end
  1184.                             response = false
  1185.                         end
  1186.                         response = false       
  1187.                     end
  1188.                     response = false   
  1189.                 end
  1190.             end    
  1191.            
  1192.         elseif mode == 6 then --suicides - killer is self/victim
  1193.             if getplayer(victim) then
  1194.                 vlvl = level[victim]
  1195.                 vname = getname(victim)
  1196.                 vhash = gethash(victim)
  1197.                 vteam = getteam(victim)
  1198.                 if vlvl == 10 then
  1199.                     level[victim] = 9
  1200.                     playerscore[victim] = 8
  1201.                     beserk = false
  1202.                     weapons[victim] = "weapons\\sniper rifle\\sniper rifle"
  1203.                     sendconsoletext(victim, "Demoted to Level 9! Ain't that a bitch?!", 4, 0)
  1204.                     say(vname .. " demoted to Level 9 for suicide.")
  1205.                     if logging then log_msg(1, vname .. " demoted from level 10 to 9 for suicide. Is level: " .. vlvl) end
  1206.                     response = false
  1207.                 else
  1208.                     if level[victim] ~= nil and level[victim] > 1 then
  1209.                         if (level[victim] - 1) >= 1 then level[victim] = level[victim] - 1 end
  1210.                         if (playerscore[victim] - 1) >= 0 then playerscore[victim] = playerscore[victim] - 1 end
  1211.                         if team_play then if (teamscore[vteam] - 1) >= 0 then teamscore[vteam] = teamscore[vteam] - 1 end end
  1212.                         say(vname .. " committed suicide and was demoted one level.")
  1213.                         if logging then log_msg(1, vname .. " demoted one level for suicide. Is level: " .. vlvl) end
  1214.                         response = false
  1215.                     else
  1216.                         say(vname .. " committed suicide.")
  1217.                         response = false
  1218.                     end
  1219.                     response = false
  1220.                 end
  1221.             end
  1222.         end
  1223.     end
  1224.    
  1225.     return response
  1226. end
  1227.  
  1228. function OnVehicleEntry(player, veh_id, seat, mapid, relevant)
  1229.     if getplayer(player) then
  1230.         privatesay(player, getname(player) .. " NOTE: You can't kill players with vehicle or vehicle guns.")
  1231.     end
  1232.     return nil
  1233. end
  1234.  
  1235. function OnDamageApplication(receiving, causing, tagid, hit, backtap)
  1236.     -- sets the last damage value for all players, used to determine how a player was damaged and with which weapon
  1237.     if receiving then
  1238.         local r_object = getobject(receiving)
  1239.         if r_object then
  1240.             local receiver = objectaddrtoplayer(r_object)
  1241.             if receiver then
  1242.                 local hash = gethash(receiver)
  1243.                 local tagname,tagtype = gettaginfo(tagid)
  1244.                 last_damage[hash] = tagname
  1245.                 --say("Damage: " .. tagname)
  1246.             end
  1247.         end
  1248.     end
  1249.     return nil
  1250. end
  1251.  
  1252. function OnDamageLookup(receiving, causing, tagid)
  1253.     -- looks up and sets damage variables
  1254.     if receiving and causing and receiving ~= causing then
  1255.         local tagname, tagtype = gettaginfo(tagid)
  1256.         local melee = string.find(tagname, "melee")
  1257.         local ppistolc = string.find(tagname, "weapons\\plasma rifle\\charged bolt")
  1258.         local ppistolb = string.find(tagname, "weapons\\plasma pistol\\bolt")
  1259.         local needlerd = string.find(tagname, "weapons\\needler\\detonation damage")
  1260.         local plasrifle = string.find(tagname, "weapons\\plasma rifle\\bolt")
  1261.         local deltappcharge = string.find(tagname, "weapons\\plasma pistol\\rw charged bolt")
  1262.         local c_player = objectidtoplayer(causing)
  1263.         local r_player = objectidtoplayer(receiving)
  1264.         -- block vehicle and vehicle gun damage
  1265.         if c_player and isinvehicle(c_player) then
  1266.             local m_vehicleId = getplayervehicleid(c_player)
  1267.             if m_vehicleId then
  1268.                 local m_vehicle = getobject(m_vehicleId)
  1269.                 local gunner = readdword(m_vehicle + 0x328)
  1270.                 local driver = readdword(m_vehicle + 0x324)
  1271.                 if gunner == causing then
  1272.                     return false
  1273.                 elseif driver == causing then
  1274.                     return false
  1275.                 end            
  1276.             end
  1277.         end
  1278.         -- increase damage of melee to instant kill, increase plasma pistol, needler and plasma rifle to balance game play
  1279.         if c_player and r_player then
  1280.             if melee then odl_multiplier(9999) end
  1281.             if ppistolc then odl_multiplier(1.85) end
  1282.             if ppistolb then odl_multiplier(1.85) end
  1283.             if needlerd then odl_multiplier(1.75) end
  1284.             if plasrifle then odl_multiplier(1.35) end
  1285.             if map_name == "deltaruins" then
  1286.                 if deltappcharge then return ppistolb end
  1287.                 if ppistolb then odl_multiplier(1.8) end
  1288.             end
  1289.         end
  1290.     end
  1291.     return nil
  1292. end
  1293.    
  1294. function getplayervehicleid(player)
  1295.     local m_objectId = getplayerobjectid(player)
  1296.     if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
  1297. end
  1298.    
  1299. function OnObjectInteraction(player, objId, mapId)
  1300.     -- blocks players from picking up weapons and nades
  1301.     local Pass = nil
  1302.     local name, type = gettaginfo(mapId)
  1303.     if type == "weap" then
  1304.         if weapons[player] ~= nil then
  1305.             if name ~= weapons[player] then
  1306.                 Pass = false
  1307.             end
  1308.         end
  1309.     elseif type == "eqip" then
  1310.         if name == "powerups\\over shield" or name == "powerups\\health pack" then
  1311.             Pass = true
  1312.         else   
  1313.             Pass = false
  1314.         end
  1315.     end
  1316.     return Pass
  1317. end
  1318.  
  1319. function ApplyHP(id, count, player)
  1320.     -- restores players health, called when a player reaches levels 3 and 8
  1321.     if count == 1 then
  1322.         if player and game_started then
  1323.             local name = getname(player)
  1324.             local lvl = level[player]  
  1325.             local m_playerObjId = getplayerobjectid(player)
  1326.             if m_playerObjId ~= nil then
  1327.                 local m_object = getobject(m_playerObjId)
  1328.                 local obj_health = readfloat(m_object + 0xE0)
  1329.                 if obj_health < 1 then
  1330.                     writefloat(m_object + 0xE0, 1)
  1331.                     sendconsoletext(player, "Bonus: Your health has been restored.", 4, 0)
  1332.                     if logging then log_msg(1, name .. " Health Bonus applied. Is Level: " .. lvl) end
  1333.                 end
  1334.             end
  1335.         end
  1336.     end
  1337.     return false
  1338. end
  1339.  
  1340. function OnObjectCreationAttempt(mapId, parentId, player)
  1341.     local response = nil
  1342.     if game_started then
  1343.         -- blocks creation of these items when game starts, only if game_started is valid (after script load, after new game)
  1344.         if mapId == gettagid("weap", "weapons\\ball\\ball") or
  1345.             mapId == gettagid("eqip", "weapons\\frag grenade\\frag grenade") or
  1346.             mapId == gettagid("eqip", "weapons\\plasma grenade\\plasma grenade") then
  1347.             response = false
  1348.         end
  1349.         if mapId == gettagid("weap", "weapons\\flag\\flag") then
  1350.             return gettagid("weap", "weapons\\plasma pistol\\plasma pistol")
  1351.         end        
  1352.         if mapId == gettagid("eqip", "powerups\\active camouflage") then
  1353.             return gettagid("eqip", "powerups\\over shield")
  1354.         end        
  1355.     elseif not game_started then
  1356.         -- allows creation of these items when game starts or on script load
  1357.         if mapId == gettagid("eqip", "powerups\\full-spectrum vision") or
  1358.             mapId == gettagid("eqip", "powerups\\health pack") or
  1359.             mapId == gettagid("bipd", "characters\\cyborg_mp\\cyborg_mp") or
  1360.             mapId == gettagid("vehi", "vehicles\\warthog\\mp_warthog") or
  1361.             mapId == gettagid("vehi", "vehicles\\rwarthog\\rwarthog") or
  1362.             mapId == gettagid("vehi", "vehicles\\ghost\\ghost_mp") or
  1363.             mapId == gettagid("vehi", "vehicles\\c gun turret\\c gun turret_mp") or
  1364.             mapId == gettagid("vehi", "vehicles\\scorpion\\scorpion_mp") then
  1365.             response = true
  1366.         end
  1367.         -- blocks creation of these items when game starts, when game is restarted, or scripts reloaded
  1368.         if mapId == gettagid("weap", "weapons\\ball\\ball") or
  1369.             mapId == gettagid("eqip", "weapons\\frag grenade\\frag grenade") or
  1370.             mapId == gettagid("eqip", "weapons\\plasma grenade\\plasma grenade") then
  1371.             response = false
  1372.         end
  1373.         if mapId == gettagid("weap", "weapons\\flag\\flag") then
  1374.             return gettagid("weap", "weapons\\plasma pistol\\plasma pistol")
  1375.         end        
  1376.         if mapId == gettagid("eqip", "powerups\\active camouflage") then
  1377.             return gettagid("eqip", "powerups\\over shield")
  1378.         end
  1379.     else
  1380.         response = false
  1381.     end
  1382.     return response
  1383. end
  1384.  
  1385. function OnClientUpdate(player)
  1386.     if getplayer(player) then
  1387.         local lvl = level[player]
  1388.         if lvl ~= nil then
  1389.             -- monitors and initiates game win announcement
  1390.             if lvl == 11 and game_started then
  1391.                 game_started = false
  1392.                 announcewin = registertimer(0, "AnnounceWin", player)
  1393.                 if logging then log_msg(1, "Game win detected - Announcement called.") end
  1394.             end
  1395.         end
  1396.     end
  1397. end
  1398.  
  1399. function AnnounceWin(id, count, player)
  1400.     -- announces game winner
  1401.     if player and game_started == false then
  1402.         local name = getname(player)   
  1403.         svcmd("sv_map_next")
  1404.         if not team_play then
  1405.             say(name .. " WINS THE GAME! ")
  1406.         else   
  1407.             local team = getteam(player)
  1408.             if team == 0 then team = "RED TEAM" elseif team == 1 then team = "BLUE TEAM" end
  1409.             say(team .. " WINS THE GAME! ")
  1410.         end    
  1411.         log_msg(1, name .. " has won the Gun-Game on " .. map_name .. "!")
  1412.     end    
  1413.     return false
  1414. end
  1415.  
  1416. function OnTeamChange(player, old_team, new_team, relevant)
  1417.     -- prevent unbalancing teams by team change
  1418.     local response = nil
  1419.     if getplayer(player) then
  1420.         if not team_play then response = false return response end 
  1421.        
  1422.         if relevant == true or relevant == 1 then
  1423.             if getteamsize(old_team) == getteamsize(new_team) then
  1424.                 privatesay(player, "You cannot change teams.")
  1425.                 response = false
  1426.             elseif getteamsize(old_team) + 1 == getteamsize(new_team) then
  1427.                 privatesay(player, "You cannot change teams.")
  1428.                 response = false
  1429.             elseif getteamsize(old_team) == getteamsize(new_team) + 1 then
  1430.                 privatesay(player, "You cannot change teams.")
  1431.                 response = false
  1432.             elseif getteamsize(old_team) > getteamsize(new_team) then
  1433.                 team_change[player] = true
  1434.                 -- transfer player score to new team score, and deduct new player score from old team score
  1435.                 if team_play then
  1436.                     teamscore[new_team] = teamscore[new_team] + playerscore[player]
  1437.                     teamscore[old_team] = teamscore[old_team] - playerscore[player]
  1438.                 end
  1439.                 mybattery[player] = 0
  1440.                 say(getname(player) .. " switched teams.")
  1441.                 response = true
  1442.             elseif getteamsize(old_team) < getteamsize(new_team) then
  1443.                 team_change[player] = true
  1444.                 -- transfer player score to new team score, and deduct new player score from old team score
  1445.                 if team_play then
  1446.                     teamscore[new_team] = teamscore[new_team] + playerscore[player]
  1447.                     teamscore[old_team] = teamscore[old_team] - playerscore[player]
  1448.                 end                            
  1449.                 mybattery[player] = 0
  1450.                 say(getname(player) .. " switched teams.")
  1451.                 response = true
  1452.             end
  1453.         elseif relevant == false or relevant == 0 then
  1454.             team_change[player] = true
  1455.             -- transfer player score to new team score, and deduct new player score from old team score
  1456.             if team_play then
  1457.                 teamscore[new_team] = teamscore[new_team] + playerscore[player]
  1458.                 teamscore[old_team] = teamscore[old_team] - playerscore[player]
  1459.             end        
  1460.             mybattery[player] = 0
  1461.             say(getname(player) .. " was team-switched.")
  1462.             response = true
  1463.         end
  1464.        
  1465.     end
  1466.     return response
  1467. end
  1468.  
  1469. function AutoBalance(id, count)
  1470.     Balance_Teams()
  1471.     if game_started and team_play and cur_players > 3 then
  1472.         return true
  1473.     else
  1474.         return false
  1475.     end
  1476. end
  1477.  
  1478. function AutoBalance(id, count)
  1479.     if game_started and team_play and cur_players > 3 then
  1480.         Balance_Teams()
  1481.         if join_autobal then join_autobal = nil end
  1482.         if leave_autobal then leave_autobal = nil end
  1483.         return true
  1484.     elseif game_started and team_play and cur_players < 4 then 
  1485.         return false
  1486.     else
  1487.         return false
  1488.     end
  1489. end
  1490.  
  1491. -- inspired by 002's team balance for Sapp
  1492. function Balance_Teams()
  1493.     if game_started and team_play then
  1494.         local redteam = getteamsize(0)
  1495.         local blueteam = getteamsize(1)
  1496.         if redteam > blueteam then
  1497.             while TeamsAreUneven() do
  1498.                 while (getteamsize(0) > getteamsize(1)+1) do
  1499.                     local randomred = SelectPlayer(0)
  1500.                     if randomred ~= nil then
  1501.                         changeteam(randomred, true)
  1502.                     end
  1503.                 end
  1504.             end
  1505.         elseif blueteam > redteam then
  1506.             while TeamsAreUneven() do
  1507.                 while (getteamsize(1) > getteamsize(0)+1) do
  1508.                     local randomblu = SelectPlayer(1)
  1509.                     if randomblu ~= nil then                           
  1510.                         changeteam(randomblu, true)
  1511.                     end
  1512.                 end
  1513.             end    
  1514.         end
  1515.     end
  1516. end
  1517.  
  1518. -- inspired by 002's team balance for Sapp
  1519. function TeamsAreUneven()
  1520.     local red = getteamsize(0)
  1521.     local blue = getteamsize(1)
  1522.     if (red > blue + 1 or blue > red + 1) then return true end
  1523.     return false
  1524. end
  1525.  
  1526. function SelectPlayer(team)
  1527.     local t = {}
  1528.     for i=0,15 do
  1529.         if getplayer(i) and getteam(i) == team then
  1530.             table.insert(t, i)
  1531.         end
  1532.     end
  1533.     if #t > 0 then
  1534.         local r = getrandomnumber(1, #t+1)
  1535.         return t[r]
  1536.     end
  1537.     return nil
  1538. end
  1539.  
  1540. function ShowTargets(id, count)
  1541.     -- timer to repeatedly call roaming targets function while game is started and players > 0
  1542.     Roaming_Targets()
  1543.     return true
  1544. end
  1545.  
  1546. function Roaming_Targets(id, count)
  1547.     if game_started and cur_players > 2 and gametype ~= 5 then
  1548.         if team_play then
  1549.             local target = SelectRoamingPlayer(player)
  1550.             if target then
  1551.                 local team = getteam(target)
  1552.                 for i = 0,15 do
  1553.                     if getplayer(i) and getplayer(i) ~= getplayer(target) and getteam(i) ~= team then
  1554.                         writeword(getplayer(i) + 0x88, target)
  1555.                     end                
  1556.                 end
  1557.                 return true
  1558.             else
  1559.                 return false
  1560.             end
  1561.         else
  1562.             local target = SelectRoamingPlayer(player)
  1563.             if target then
  1564.                 for i = 0,15 do
  1565.                     if getplayer(i) and getplayer(i) ~= getplayer(target) then
  1566.                         writeword(getplayer(i) + 0x88, target)
  1567.                     end                
  1568.                 end
  1569.                 return true
  1570.             else
  1571.                 return false
  1572.             end
  1573.         end
  1574.     end
  1575. end
  1576.  
  1577. function SelectRoamingPlayer(player)
  1578.     local t = {}
  1579.     for i=0,15 do
  1580.         if getplayer(i) then
  1581.             table.insert(t, i)
  1582.         end
  1583.     end
  1584.     if #t > 0 then
  1585.         if (timerCount > #t) then
  1586.             timerCount = 0
  1587.         else
  1588.             timerCount = timerCount + 1
  1589.         end
  1590.         return t[timerCount]
  1591.     end
  1592. end
  1593.  
  1594. function OnGameEnd(stage)
  1595.     -- terminate or nil timers, set game values.  Some timers cannot be removed, instead they are nil'd
  1596.     if stage == 1 then
  1597.         game_started = false
  1598.         beserk = false 
  1599.         if gameweap then
  1600.             gameweap = nil
  1601.         end
  1602.         if announcewin then
  1603.             announcewin = nil
  1604.         end
  1605.         if m_weaponId then
  1606.             m_weaponId = nil
  1607.         end
  1608.         if replaceplasmaweap then
  1609.             replaceplasmaweap = nil
  1610.         end
  1611.         if p_objectId then
  1612.             p_objectId = nil
  1613.         end
  1614.         if health then
  1615.             health = nil
  1616.         end
  1617.         if welcome then
  1618.             welcome = nil
  1619.         end
  1620.         if speedtimer then
  1621.             speedtimer = nil
  1622.         end
  1623.         if checkbattery then
  1624.             checkbattery = nil
  1625.         end
  1626.         if updatescores then
  1627.             updatescores = nil
  1628.         end
  1629.         if consoletimer then
  1630.             consoletimer = nil
  1631.         end
  1632.         if game_autobal then
  1633.             game_autobal = nil
  1634.         end
  1635.         if join_autobal then
  1636.             join_autobal = nil
  1637.         end
  1638.         if leave_autobal then
  1639.             leave_autobal = nil
  1640.         end    
  1641.     elseif stage == 3 then
  1642.         for i = 0, 15 do
  1643.             if getplayer(i) then
  1644.                 privatesay(i, "Thank you for playing the Gun-Game Arms Race!")
  1645.                 privatesay(i, "This and other scripts available on HaloRace.org")
  1646.             end
  1647.         end    
  1648.     end
  1649. end
  1650.  
  1651. -- -------------------------------------------------------------------------
  1652. -- Start sendconsoletext overloaded by Nugget
  1653. console = {}
  1654. console.__index = console
  1655. consoletimer = registertimer(100, "ConsoleTimer")
  1656. phasor_sendconsoletext = sendconsoletext
  1657.  
  1658. function sendconsoletext(player, message, time, order, align, height, func)
  1659.     if player then
  1660.         console[player] = console[player] or {}
  1661.         local temp = {}
  1662.         temp.player = player
  1663.         temp.id = nextid(player, order)
  1664.         temp.message = message or ""
  1665.         temp.time = time or 0.7
  1666.         temp.remain = temp.time
  1667.         temp.align = align or "left"
  1668.         temp.height = height or 0
  1669.         if type(func) == "function" then
  1670.             temp.func = func
  1671.         elseif type(func) == "string" then
  1672.             temp.func = _G[func]
  1673.         end
  1674.         console[player][temp.id] = temp
  1675.         setmetatable(console[player][temp.id], console)
  1676.         return console[player][temp.id]
  1677.     end
  1678. end
  1679.  
  1680. function nextid(player, order)
  1681.     if not order then
  1682.         local x = 0
  1683.         for k,v in pairs(console[player]) do
  1684.             if k > x + 1 then
  1685.                 return x + 1
  1686.             end
  1687.            
  1688.             x = x + 1
  1689.         end
  1690.         return x + 1
  1691.     else
  1692.         local original = order
  1693.         while console[player][order] do
  1694.             order = order + 0.001
  1695.             if order == original + 0.999 then break end
  1696.         end
  1697.         return order
  1698.     end
  1699. end
  1700.  
  1701. function getmessage(player, order)
  1702.     if console[player] then
  1703.         if order then
  1704.             return console[player][order]
  1705.         end
  1706.     end
  1707. end
  1708.  
  1709. function getmessages(player)
  1710.     return console[player]
  1711. end
  1712.  
  1713. function getmessageblock(player, order)
  1714.     local temp = {}
  1715.     for k,v in opairs(console[player]) do
  1716.         if k >= order and k < order + 1 then
  1717.             table.insert(temp, console[player][k])
  1718.         end
  1719.     end
  1720.     return temp
  1721. end
  1722.  
  1723. function console:getmessage()
  1724.     return self.message
  1725. end
  1726.  
  1727. function console:append(message, reset)
  1728.     if console[self.player] then
  1729.         if console[self.player][self.id] then
  1730.             if getplayer(self.player) then
  1731.                 if reset then
  1732.                     if reset == true then
  1733.                         console[self.player][self.id].remain = console[self.player][self.id].time
  1734.                     elseif tonumber(reset) then
  1735.                         console[self.player][self.id].time = tonumber(reset)
  1736.                         console[self.player][self.id].remain = tonumber(reset)
  1737.                     end
  1738.                 end
  1739.                
  1740.                 console[self.player][self.id].message = message or ""
  1741.                 return true
  1742.             end
  1743.         end
  1744.     end
  1745. end
  1746.  
  1747. function console:shift(order)
  1748.     local temp = console[self.player][self.id]
  1749.     console[self.player][self.id] = console[self.player][order]
  1750.     console[self.player][order] = temp
  1751. end
  1752.  
  1753. function console:pause(time)
  1754.     console[self.player][self.id].pausetime = time or 5
  1755. end
  1756.  
  1757. function console:delete()
  1758.     console[self.player][self.id] = nil
  1759. end
  1760.  
  1761. function ConsoleTimer(id, count)
  1762.     for i,_ in opairs(console) do
  1763.         if tonumber(i) then
  1764.             if getplayer(i) then
  1765.                 for k,v in opairs(console[i]) do
  1766.                     if console[i][k].pausetime then
  1767.                         console[i][k].pausetime = console[i][k].pausetime - 0.1
  1768.                         if console[i][k].pausetime <= 0 then
  1769.                             console[i][k].pausetime = nil
  1770.                         end
  1771.                     else
  1772.                         if console[i][k].func then
  1773.                             if not console[i][k].func(i) then
  1774.                                 console[i][k] = nil
  1775.                             end
  1776.                         end
  1777.                         if console[i][k] then
  1778.                             console[i][k].remain = console[i][k].remain - 0.1
  1779.                             if console[i][k].remain <= 0 then
  1780.                                 console[i][k] = nil
  1781.                             end
  1782.                         end
  1783.                     end
  1784.                 end
  1785.                 if table.len(console[i]) > 0 then
  1786.                     local paused = 0
  1787.                     for k,v in pairs(console[i]) do
  1788.                         if console[i][k].pausetime then
  1789.                             paused = paused + 1
  1790.                         end
  1791.                     end
  1792.                     if paused < table.len(console[i]) then
  1793.                         local str = ""
  1794.                         for i = 0,30 do
  1795.                             str = str .. " \n"
  1796.                         end
  1797.                         phasor_sendconsoletext(i, str)
  1798.                         for k,v in opairs(console[i]) do
  1799.                             if not console[i][k].pausetime then
  1800.                                 if console[i][k].align == "right" or console[i][k].align == "center" then
  1801.                                     phasor_sendconsoletext(i, consolecenter(string.sub(console[i][k].message, 1, 78)))
  1802.                                 else
  1803.                                     phasor_sendconsoletext(i, string.sub(console[i][k].message, 1, 78))
  1804.                                 end
  1805.                             end
  1806.                         end
  1807.                     end
  1808.                 end
  1809.             else
  1810.                 console[i] = nil
  1811.             end
  1812.         end
  1813.     end
  1814.     return true
  1815. end
  1816.  
  1817. function consolecenter(text)
  1818.     if text then
  1819.         local len = string.len(text)
  1820.         for i = len + 1, 78 do
  1821.             text = " " .. text
  1822.         end
  1823.         return text
  1824.     end
  1825. end
  1826.  
  1827. function opairs(t)
  1828.     local keys = {}
  1829.     for k,v in pairs(t) do
  1830.         table.insert(keys, k)
  1831.     end    
  1832.     table.sort(keys,
  1833.     function(a,b)
  1834.         if type(a) == "number" and type(b) == "number" then
  1835.             return a < b
  1836.         end
  1837.         an = string.lower(tostring(a))
  1838.         bn = string.lower(tostring(b))
  1839.         if an ~= bn then
  1840.             return an < bn
  1841.         else
  1842.             return tostring(a) < tostring(b)
  1843.         end
  1844.     end)
  1845.     local count = 1
  1846.     return function()
  1847.         if table.unpack(keys) then
  1848.             local key = keys[count]
  1849.             local value = t[key]
  1850.             count = count + 1
  1851.             return key,value
  1852.         end
  1853.     end
  1854. end
  1855.  
  1856. function table.len(t)
  1857.     local count = 0
  1858.     for k,v in pairs(t) do
  1859.         count = count + 1
  1860.     end
  1861.     return count
  1862. end
  1863.  
  1864. --[[ Created by H® Shaft.
  1865. Thanks to Oxide, AelitePrime, Nugget & Wizard.
  1866. Visit http://halorace.org/forum/index.php?topic=514.0 or
  1867. Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
  1868. Special thanks to AelitePrime, as this was an attempt to script patterned after his style similar to his Zombie script 4.1, and other scripts we have mutually developed.
  1869. Note: This was written and developed by H® Shaft prior to the release of any other similar script with similar names. Any claims of duplication of concept/script are 100% bullpucky.
  1870.  
  1871. Special thanks to our beta testers, server hosts & contributors:
  1872. H® HUMMER, H® BugZ, H® Monkey, H® Wingnut, H® LoLLi, H® Stone, H® RUDE, H® Outage, H® Griff, -JR- Mumbler, -JR- RAVIN,
  1873. -JR-Hollypaw, -JR- Slayer, -JR- Falx, -JR- Spec4, -JR- Slayer, -JR-wraith, AR~Dvs_One, -JR-ÄÐhè®é,  AR~Hazy,
  1874. AR~Un¡t»Zero, AR~Hanabal, AR~DSPFlag, AR~HiroP, AR~Archon, Forseti, Mastermind, [x] fisk, ²MõD²Wrath, ²MõD²Corvair,
  1875. ²MõD²Bear, ²MõD²Buster, «§H»Kennan, Telyx, Lobo, Awesome, Nugget, Wizard, particleboy, PÕQ clan, {ØZ} clan, Skylace,
  1876. A§H» clan, Ponyboy and the Ousiders, PÕQ~Technut, smiley, Btcc22, Roger W, sehé°°, kornman00, Geomitar]]
  1877.  
  1878. --[[ SERVER SETUP - USAGE:
  1879. Compatible with CTF & Slayer gametypes only - 'Standard' PC & CE Maps and custom maps with classic weapon sets. Not compatible with race, oddball or koth gametypes, or custom named weapons CE maps.
  1880. Gametype should set weapons to normal/generic, infinite nades off.
  1881. Place in your cg/scripts/persistent folder.  Intended to be used as a persisitent script, but not required.
  1882. DO NOT combine with other death message/player kill scripts during this game.
  1883. Use of server rcon commands sv_map_reset and sv_script_reload are allowed, and function well with no errors.  Reloading will behave similar to resetting.
  1884. Extended game logging best used for tournaments/scrims/ or debugging.  If you choose to customize this script, set logging to true to help you.
  1885. This script has been rigorously tested and believed to be error free. If you get errors, try running the script by itself, it could conflict with other scripts. Set logging to true on lines 29 and 98 to help you debug then read the logs
  1886. If help is needed, message me on phasor.proboards.com, or on www.HaloRace.org, or xfire: nervebooger2012
  1887. Thank you, I hope you enjoy this as much as we have on our PC and CE servers.
  1888. Visit us at http://halorace.org/forum/index.php
  1889. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement