Advertisement
HR_Shaft

Gun-Game v2 for The_Cage_Un for Phasor v2+

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