Advertisement
th3w1zard1

ArmsRace

Jun 6th, 2014
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.87 KB | None | 0 0
  1. -- Arms Race
  2. -- Created by Wizard in 2012/2013.
  3. -- I found a cool gametype in Counter-strike: Global Offensive called Arms Race and thought
  4. -- it would make a cool gametype in Halo.
  5. --
  6. -- Objective is to get to the last weapon, and get a kill with it.
  7. --
  8.  
  9. -- Number of kills required to next level
  10. -- Number must be an integer, 1 or greater
  11. kills_to_next_lvl = 2
  12.  
  13. -- Penalty for committing suicide. If you suicide, you will either lose a whole level, or your last kill
  14. -- must be set to "level" or "kill"
  15. suicide_penalty = "kill"
  16.  
  17. --Don't touch this stuff
  18. WeaponCycle = {}
  19. player_level = {}
  20. kills_with_weap = {}
  21. teamscore = {}
  22. playerIsMeleeing = {}
  23.  
  24. function GetRequiredVersion()
  25.     return 200
  26. end
  27.  
  28. function OnScriptLoad(processId, game, persistent)
  29.     getTagIds()
  30.     registertimer(0, "cmdDelay")
  31.     GetGameAddresses(game)
  32.     writebyte(slayer_score_patch, 0xEB)
  33.     writebyte(slayer_score_patch2, 0xEB)
  34.     teamplay = readbyte(gametype_base + 0x34)
  35.     teamscore[0] = 0
  36.     teamscore[1] = 0
  37.     if teamplay then
  38.         setTeamScore(0, 0)
  39.         setTeamScore(1, 0)
  40.     end
  41.     for i = 0,15 do
  42.         local m_player = getplayer(i)
  43.         if m_player then
  44.             local name = getname(i)
  45.             if name then
  46.                 player_level[name] = 1
  47.                 kills_with_weap[name] = 0
  48.                 setScore(i, 1)
  49.             end
  50.         end
  51.     end
  52.    
  53.     starting_equipment = readbit(gametype_base + 0x38, 2) -- Generic = 0, Custom = 1
  54.     if starting_equipment == 1 then
  55.         starting_equipment = "Generic"
  56.     else
  57.         starting_equipment = "Custom"
  58.     end
  59. end
  60.  
  61. function GetGameAddresses(game)
  62.     if game == "PC" then
  63.         slayer_globals = 0x63A0E8
  64.         gametype_base = 0x671340
  65.         slayer_score_patch = 0x48F428
  66.         slayer_score_patch2 = 0x48F23E
  67.     else
  68.         slayer_globals = 0x5BE108
  69.         gametype_base = 0x5F5498
  70.         slayer_score_patch = 0x469CF8
  71.         slayer_score_patch2 = 0x4691CE
  72.     end
  73. end
  74.  
  75. function cmdDelay(id, count)
  76.     --svcmd("cheat_infinite_ammo 1")
  77.     return false
  78. end
  79.    
  80.  
  81. function getTagIds()
  82.     WeaponCycle = {
  83.                     gettagid("weap", "weapons\\rocket launcher\\rocket launcher"),
  84.                     gettagid("weap", "weapons\\plasma_cannon\\plasma_cannon"),
  85.                     gettagid("weap", "weapons\\flamethrower\\flamethrower"),
  86.                     --gettagid("weap", "weapons\\gravity rifle\\gravity rifle"),
  87.                     gettagid("weap", "weapons\\pistol\\pistol"),
  88.                     gettagid("weap", "weapons\\shotgun\\shotgun"),
  89.                     gettagid("weap", "weapons\\sniper rifle\\sniper rifle"),
  90.                     gettagid("weap", "weapons\\assault rifle\\assault rifle"),
  91.                     gettagid("weap", "weapons\\plasma rifle\\plasma rifle"),
  92.                     gettagid("weap", "weapons\\needler\\mp_needler"),
  93.                     --gettagid("weap", "weapons\\gravity rifle\\gravity rifle"),
  94.                     gettagid("weap", "weapons\\plasma pistol\\plasma pistol")
  95.                   }
  96.     rocketlauncher_tag_id = gettagid("weap", "weapons\\rocket launcher\\rocket launcher")
  97.     fuelrod_tag_id = gettagid("weap", "weapons\\plasma_cannon\\plasma_cannon")
  98.     flamethrower_tag_id = gettagid("weap", "weapons\\flamethrower\\flamethrower")
  99.     gravitygun_tag_id = gettagid("weap", "weapons\\gravity rifle\\gravity rifle")
  100.     pistol_tag_id = gettagid("weap", "weapons\\pistol\\pistol")
  101.     shotgun_tag_id = gettagid("weap", "weapons\\shotgun\\shotgun")
  102.     sniper_tag_id = gettagid("weap", "weapons\\sniper rifle\\sniper rifle")
  103.     rifle_tag_id = gettagid("weap", "weapons\\assault rifle\\assault rifle")
  104.     plasmarifle_tag_id = gettagid("weap", "weapons\\plasma rifle\\plasma rifle")
  105.     needler_tag_id = gettagid("weap", "weapons\\needler\\mp_needler")
  106.     plasmapistol_tag_id = gettagid("weap", "weapons\\plasma pistol\\plasma pistol")
  107.     camouflage_tag_id = gettagid("eqip", "powerups\\active camouflage")
  108.     healthpack_tag_id = gettagid("eqip", "powerups\\health pack")
  109.     overshield_tag_id = gettagid("eqip", "powerups\\over shield")
  110. end
  111.  
  112. function DelayGetIds(id, count)
  113.     say("FAIL")
  114.     getTagIds()
  115.     return false
  116. end
  117.  
  118. function OnScriptUnload()
  119.     writebyte(slayer_score_patch, 0x74)
  120.     writebyte(slayer_score_patch2, 0x75)
  121. end
  122.  
  123. function OnNewGame(map)
  124.     getTagIds()
  125.     writebyte(slayer_score_patch, 0xEB)
  126.     writebyte(slayer_score_patch2, 0xEB)
  127. end
  128.  
  129. --[[
  130. function OnGameEnd(stage)
  131.  
  132.  
  133. end
  134. --]]
  135.  
  136. --[[
  137. function OnServerChat(player, type, message)
  138.  
  139.     --return true
  140. end
  141. --]]
  142.  
  143. --[[
  144. function OnServerCommandAttempt(player, command, password)
  145.  
  146.     --return true
  147. end
  148. --]]
  149.  
  150. --[[
  151. function OnServerCommand(admin, command)
  152.  
  153.     --return true
  154. end
  155. --]]
  156.  
  157. --[[
  158. function OnNameRequest(hash, name)
  159.  
  160.     --return true, name
  161. end
  162. --]]
  163.  
  164. --[[
  165. function OnBanCheck(hash, ip)
  166.    
  167.     --return true
  168. end
  169. --]]
  170.  
  171. function OnPlayerJoin(player)
  172.     if player then
  173.         local name = getname(player)
  174.         if name then
  175.             if not player_level[name] then
  176.                 player_level[name] = 1
  177.                 kills_with_weap[name] = 0
  178.                 setScore(player, 1)
  179.             else
  180.                 setScore(player, player_level[name])
  181.             end
  182.         end
  183.     end
  184. end
  185.  
  186. --[[
  187. function OnPlayerLeave(player)
  188.    
  189.    
  190. end
  191. --]]
  192.  
  193. function OnPlayerKill(killer, victim, mode)
  194.  
  195.     -- mode 0: Killed by server
  196.     -- mode 1: Killed by fall damage
  197.     -- mode 2: Killed by guardians
  198.     -- mode 3: Killed by vehicle
  199.     -- mode 4: Killed by killer
  200.     -- mode 5: Betrayed by killer
  201.     -- mode 6: Suicide
  202.     if mode == 6 or mode == 2 then
  203.         if victim then
  204.             local m_player = getplayer(victim)
  205.             if m_player then
  206.                 local name = getname(victim)
  207.                 if name then
  208.                     privatesay(victim, "You lost one level for suiciding!")
  209.                     if kills_with_weap[name] ~= 0 and suicide_penalty == "kill" then
  210.                         kills_with_weap[name] = kills_with_weap[name] - 1
  211.                     elseif player_level[name] ~= 1 then
  212.                         player_level[name] = player_level[name] - 1
  213.                         setScore(victim, player_level[name] - 1)
  214.                         if teamplay then
  215.                             local team = getteam(victim)
  216.                             if not teamscore[team] then teamscore[team] = 0 end
  217.                             --fuck signed addresses in phasor 2.0
  218.                             if teamscore[team] >= 1 then
  219.                                 teamscore[team] = teamscore[team] - 1
  220.                                 setTeamScore(team, teamscore[team])
  221.                             end
  222.                         end
  223.                     end
  224.                     local level = tostring(player_level[name])
  225.                     local weapon = tostring(getWeaponLevel(player_level[name]))
  226.                     local kills
  227.                     if kills_with_weap[name] then
  228.                         kills = " (" .. tostring(kills_with_weap[name]) .. "/" .. tostring(kills_to_next_lvl) .. ")"
  229.                     end
  230.                     sendconsoletext(victim, "Level " .. level .. ": " .. weapon .. kills .. " kills")
  231.                 end
  232.             end
  233.         end
  234.     elseif mode == 4 then
  235.         if killer then
  236.             local m_player = getplayer(killer)
  237.             if m_player then
  238.                 local name = getname(killer)
  239.                 if name then
  240.                     if not tonumber(player_level[name]) then player_level[name] = 1 end
  241.                     if not tonumber(kills_with_weap[name]) then kills_with_weap[name] = 0 end
  242.                     kills_with_weap[name] = kills_with_weap[name] + 1
  243.                     if kills_with_weap[name] == kills_to_next_lvl then
  244.                         player_level[name] = player_level[name] + 1
  245.                         setScore(killer, player_level[name])
  246.                         if teamplay then
  247.                             local team = getteam(killer)
  248.                             if not teamscore[team] then teamscore[team] = 0 end
  249.                             teamscore[team] = teamscore[team] + 1
  250.                             setTeamScore(team, teamscore[team])
  251.                         end
  252.                         kills_with_weap[name] = 0
  253.                         if player_level[name] == #WeaponCycle+1 then
  254.                             say(name .. " has won the game!")
  255.                             svcmd("sv_map_next")
  256.                             return
  257.                         else
  258.                             if player_level[name] == #WeaponCycle then
  259.                                 say(name .. " is on the final weapon!")
  260.                             end
  261.                         end
  262.                         local m_objectId = getplayerobjectid(killer)
  263.                         if tonumber(m_objectId) and m_objectId ~= 0xFFFFFFFF then
  264.                             local m_object = getobject(m_objectId)
  265.                             if m_object then
  266.                                 for i = 0,3 do
  267.                                     local weapId = readdword(m_object + 0x2F8 + i*4)
  268.                                     local m_weapon = getobject(weapId)
  269.                                     if m_weapon then
  270.                                         destroyobject(weapId)
  271.                                     end
  272.                                 end
  273.                                 local x,y,z = getobjectcoords(m_objectId)
  274.                                 local newweapId = createobject(WeaponCycle[player_level[name]], 0, 60, false, x, y, z+0.5)
  275.                                 assignweapon(killer, newweapId)
  276.                                 local m_weapon = getobject(newweapId)
  277.                                 if m_weapon then
  278.                                     writeword(m_weapon + 0x2B6, 600)
  279.                                 end
  280.                             end
  281.                         end
  282.                         sendconsoletext(killer, "**LEVEL UP**")
  283.                     end
  284.                     local level = tostring(player_level[name])
  285.                     local weapon = tostring(getWeaponLevel(player_level[name]))
  286.                     local kills
  287.                     if kills_with_weap[name] then
  288.                         kills = " (" .. tostring(kills_with_weap[name]) .. "/" .. tostring(kills_to_next_lvl) .. ")"
  289.                     end
  290.                     sendconsoletext(killer, "Level " .. level .. ": " .. weapon .. kills .. " kills")
  291.                 end
  292.             end
  293.         end
  294.     end
  295. end
  296.  
  297.  
  298. --[[
  299. function OnKillMultiplier(player, multiplier)
  300.  
  301.     -- Multipliers:
  302.     -- 7: Double Kill
  303.     -- 9: Triple Kill
  304.     -- 10: Killtacular
  305.     -- 11: Killing Spree
  306.     -- 12: Running Riot
  307.     -- 16: Double Kill w/ Score
  308.     -- 17: Triple Kill w/ Score
  309.     -- 14: Killtacular w/ Score
  310.     -- 18: Killing Spree w/ Score
  311.     -- 17: Running Riot w/ Score
  312. end
  313. --]]
  314.  
  315.  
  316. function OnPlayerSpawn(player)
  317.     if starting_equipment == "Custom" then
  318.         registertimer(0, "replaceWeaps", player)
  319.     end
  320.     local m_objectId = getplayerobjectid(player)
  321.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  322.         local m_object = getobject(m_objectId)
  323.         if m_object then
  324.             writebyte(m_object + 0x31E, 0)
  325.             writebyte(m_object + 0x31F, 0)
  326.         end
  327.     end
  328.     local m_player = getplayer(player)
  329.     if m_player then
  330.         local name = getname(player)
  331.         if name then
  332.             local level = tostring(player_level[name])
  333.             local weapon = tostring(getWeaponLevel(player_level[name]))
  334.             local kills
  335.             if kills_with_weap[name] then
  336.                 kills = " (" .. tostring(kills_with_weap[name]) .. "/" .. tostring(kills_to_next_lvl) .. ")"
  337.             end
  338.             sendconsoletext(player, "Level " .. level .. ": " .. weapon .. kills .. " kills")
  339.         end
  340.     end
  341. end
  342.  
  343. function getWeaponLevel(level)
  344.     local mapId = WeaponCycle[level]
  345.     if mapId == rocketlauncher_tag_id then
  346.         level = "Rocket Launcher"
  347.     elseif mapId == fuelrod_tag_id then
  348.         level = "FuelRod"
  349.     elseif mapId == flamethrower_tag_id then
  350.         level = "Flamethrower"
  351.     elseif mapId == pistol_tag_id then
  352.         level = "Pistols"
  353.     elseif mapId == shotgun_tag_id then
  354.         level = "Shotgun"
  355.     elseif mapId == sniper_tag_id then
  356.         level = "Sniper Rifle"
  357.     elseif mapId == rifle_tag_id then
  358.         level = "Assault Rifle"
  359.     elseif mapId == plasmarifle_tag_id then
  360.         level = "Plasma Rifle"
  361.     elseif mapId == needler_tag_id then
  362.         level = "Needler"
  363.     elseif mapId == plasmapistol_tag_id then
  364.         level = "Plasma Pistol - FINAL WEAPON!"
  365.     else
  366.         level = "UNKNOWN WEAPON!"
  367.     end
  368.     return level
  369. end
  370.  
  371. function replaceWeaps(id, count, player)
  372.     if getplayer(player) then
  373.         local name = getname(player)
  374.         local m_objectId = getplayerobjectid(player)
  375.         if m_objectId then
  376.             local m_object = getobject(m_objectId)
  377.             if m_object then
  378.                 for i = 0,3 do
  379.                     local weapID = readdword(m_object + 0x2F8 + i*4)
  380.                     local weap = getobject(weapID)
  381.                     if weap then
  382.                         destroyobject(weapID)
  383.                     end
  384.                 end
  385.                 if WeaponCycle[player_level[name]] then
  386.                     local x,y,z = getobjectcoords(m_objectId)
  387.                     local newweap = createobject(WeaponCycle[player_level[name]], 0, 60, false, x, y, z+0.5)
  388.                     assignweapon(player, newweap)
  389.                     --[[if math.floor(player_level[name]) == 4 then
  390.                         writebyte(m_object + 0x31E, 7)
  391.                         writebyte(m_object + 0x31F, 0)
  392.                     elseif math.floor(player_level[name]) == 11 then
  393.                         writebyte(m_object + 0x31E, 0)
  394.                         writebyte(m_object + 0x31F, 7)
  395.                     else--]]
  396.                         writebyte(m_object + 0x31E, 0)
  397.                         writebyte(m_object + 0x31F, 0)
  398.                     --end
  399.                     local m_weapon = getobject(newweap)
  400.                     if m_weapon then
  401.                         writeword(m_weapon + 0x2B6, 600)
  402.                     end
  403.                 end
  404.             end
  405.         end
  406.     end
  407.     return false
  408. end
  409.  
  410. function setScore(player, score)
  411.     writedword(slayer_globals + 0x40 + player*4, score)
  412. end
  413.  
  414. function setTeamScore(team, score)
  415.     writedword(slayer_globals + team*4, score)
  416. end
  417.  
  418. function writewordsigned(address, value)
  419.     if value and value > 0x7FFF then
  420.         local max = 0xFFFF
  421.         local difference = max - value
  422.         value = -1 - difference
  423.     end
  424.     writeword(address, value)
  425. end
  426.  
  427. function writedwordsigned(address, value)
  428.     if value < -1 then
  429.         value = 0xFFFFFFFF + value
  430.     elseif value == -1 then
  431.         value = 0xFFFFFFFF
  432.     end
  433.     writedword(address, value)
  434. end
  435.  
  436. --[[
  437. function OnPlayerSpawnEnd(player)
  438.    
  439. end
  440. --]]
  441.  
  442. function OnWeaponAssignment(player, objId, slot, weapId)
  443.     if player then
  444.         local m_player = getplayer(player)
  445.         if m_player then
  446.             local name = getname(player)
  447.             if name then
  448.                 if slot == 0 then
  449.                     return WeaponCycle[player_level[name]]
  450.                 end
  451.             end
  452.         end
  453.     end
  454.     return -1
  455. end
  456.  
  457. --[[
  458. function OnWeaponReload(player, weapId)
  459.  
  460.     --return true
  461. end
  462. --]]
  463.  
  464. --[[
  465. function OnObjectCreationAttempt(mapId, parentId, player)
  466.     return nil
  467. end
  468. --]]
  469.  
  470. --[[
  471. function OnObjectCreation(m_objId)
  472.     local m_object = getobject(m_objId)
  473.     if m_object then
  474.     end
  475. end
  476. --]]
  477.  
  478. function OnObjectInteraction(player, objId, mapId)
  479.     if player then
  480.         local name = getname(player)
  481.         if name then
  482.             if WeaponCycle[player_level[name]] == mapId or mapId == overshield_tag_id or mapId == healthpack_tag_id or mapId == camouflage_tag_id then
  483.                 return true
  484.             else
  485.                 return false
  486.             end
  487.         end
  488.     end
  489. end
  490.  
  491.  
  492. --[[
  493. function OnTeamDecision(team)
  494.    
  495.     --return team
  496. end
  497. --]]
  498.  
  499. --[[
  500. function OnTeamChange(player, old_team, new_team, voluntary)
  501.    
  502.     --return true
  503. end
  504. --]]
  505.  
  506. function OnDamageLookup(receiving_obj, causing_obj, mapId, tagdata)
  507.     if tonumber(receiving_obj) and tonumber(causing_obj) then
  508.         local causer = objectidtoplayer(causing_obj)
  509.         local receiver = objectidtoplayer(receiving_obj)
  510.         if causer and receiver and getplayer(causer) and getplayer(receiver) then
  511.             --say("Causer: " .. tostring(getname(causer)))
  512.             --say("Receiver: " .. tostring(getname(receiver)))
  513.             if playerIsMeleeing[causer] then
  514.                 --say("PLAYER APPLYING MELEE DAMAGE")
  515.                 odl_multiplier(0.65)
  516.             end
  517.         end
  518.     end
  519.     --return true
  520. end
  521.  
  522. function OnDamageApplication(receiver, causer, mapId, location, backtap)
  523.  
  524. end
  525.  
  526. function OnVehicleEntry(player, vehiId, seat, mapId, voluntary)
  527.    
  528.     return false
  529. end
  530.  
  531. --[[
  532. function OnVehicleEject(player, voluntary)
  533.  
  534.     --return true
  535. end
  536. --]]
  537.  
  538. function OnClientUpdate(player)
  539.     local m_object = getplayerobject(player)
  540.     if m_object then
  541.         local melee_key = readbyte(m_object, 0x2A4)
  542.         if melee_key == 7 and not playerIsMeleeing[player] then
  543.             playerIsMeleeing[player] = true
  544.             --say("MELEEING")
  545.         elseif melee_key ~= 7 and playerIsMeleeing[player] then
  546.             --say("NOT MELEEING")
  547.             playerIsMeleeing[player] = nil
  548.         end
  549.     end
  550. end
  551.  
  552. function getplayerobject(player)
  553.     local m_player = getplayer(player)
  554.     if m_player then
  555.         local m_objectId = readdword(m_player + 0x34)
  556.         if m_objectId and m_objectId ~= 0xFFFFFFFF then
  557.             local m_object = getobject(m_objectId)
  558.             if m_object then
  559.                 return m_object
  560.             end
  561.         end
  562.     end
  563. end
  564.  
  565. function getplayerobjectid(player)
  566.     local m_player = getplayer(player)
  567.     if m_player then
  568.         local m_objectId = readdword(m_player + 0x34)
  569.         if m_objectId and m_objectId ~= 0xFFFFFFFF then
  570.             return m_objectId
  571.         end
  572.     end
  573. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement