Advertisement
Guest User

Stockpile

a guest
Jul 7th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.30 KB | None | 0 0
  1. -- Stockpile
  2.  
  3. -- Edit these values as you please
  4. balls_to_win = 25  -- Amount of Balls a player must be carrying to win
  5.  
  6. -- Don't touch these
  7. balls = {}
  8. lots_of_balls = {}
  9. multiball_message = {}
  10. GameEnd = false
  11. messages = {}
  12. command_execute = false
  13.  
  14. -- Globals
  15. gametype_base = 0x671340
  16. slayer_globals = 0x63A0E8
  17.  
  18. -- Scorelimit override
  19. writebyte(gametype_base, 0x58, balls_to_win + 1)
  20.  
  21. function GetRequiredVersion()
  22.  
  23.     return 10057
  24. end
  25.  
  26. function OnScriptLoad(process)
  27.  
  28.  
  29. end
  30.  
  31. function OnScriptUnload()
  32.  
  33.    
  34. end
  35.  
  36. function OnNewGame(map)
  37.  
  38.     scoretimer = registertimer(500, "ScoreTimer")
  39. end
  40.  
  41. function OnGameEnd(mode)
  42.  
  43.     if mode == 1 then
  44.         GameEnd = true
  45.     elseif mode == 2 then
  46.         removetimer(scoretimer)
  47.     end
  48. end
  49.  
  50. function OnServerChat(player, chattype, message)
  51.  
  52.     return 1
  53. end
  54.  
  55. function OnServerCommand(player, command)
  56.  
  57.     local hash = gethash(player)
  58.    
  59.     if hash then
  60.         if not command_execute then
  61.             command_execute = true
  62.             local str = svcmd(command, player)
  63.             messages[hash].str = str
  64.             messages[hash].time = 10
  65.            
  66.             return 0
  67.         end
  68.     end
  69.    
  70.     command_execute = false
  71.    
  72.     return 1
  73. end
  74.  
  75. function OnTeamDecision(team)
  76.  
  77.     return team
  78. end
  79.  
  80. function OnPlayerJoin(player, team)
  81.  
  82.     balls[player] = {}
  83.     local hash = gethash(player)
  84.     messages[hash] = {}
  85. end
  86.  
  87. function OnPlayerLeave(player, team)
  88.  
  89.     local hash = gethash(player)
  90.     messages[hash] = {}
  91. end
  92.  
  93. function OnPlayerKill(killer, victim, mode)
  94.  
  95.     local m_player = getplayer(victim)
  96.     local m_objId = readdword(m_player, 0x34)
  97.     local x, y, z = getobjectcoords(m_objId)
  98.     for i = 2, #balls[victim] do
  99.         local ox, oy, oz = randomFromVolume(x, y, z, 0.5)
  100.         createobject("weap", "weapons\\ball\\ball", 0, 30, false, ox, oy, oz)
  101.     end
  102.     balls[victim] = {}
  103.     writedword(slayer_globals + victim * 0x4, 0x40, 0)
  104. end
  105.  
  106. function OnKillMultiplier(player, multiplier)
  107.  
  108.  
  109. end
  110.  
  111. function OnPlayerSpawn(player, m_objId)
  112.  
  113.  
  114. end
  115.  
  116. function OnPlayerSpawnEnd(player, m_objId)
  117.  
  118.     registertimer(10, "AssignBall", player, m_objId)
  119. end
  120.  
  121. function OnTeamChange(relevant, player, cur_team, dest_team)
  122.  
  123.     return 1
  124. end
  125.  
  126. function OnObjectCreation(m_objId, player, tagName)
  127.  
  128.  
  129. end
  130.  
  131. function OnObjectInteraction(player, m_objId, tagType, tagName)
  132.    
  133.     if tagName == "weapons\\ball\\ball" then
  134.         if not GameEnd then
  135.             local bool
  136.             for k,v in ipairs(balls[player]) do
  137.                 if m_objId == v then
  138.                     bool = true
  139.                     local assigned = assignweapon(player, m_objId)
  140.                     if not assigned then
  141.                         registertimer(5, "GiveBackBall", player, m_objId)
  142.                     end
  143.                     break
  144.                 end
  145.             end
  146.             if not bool then
  147.                 table.insert(balls[player], m_objId)
  148.                 destroyobject(m_objId)
  149.                 if not lots_of_balls[player] then
  150.                     lots_of_balls[player] = 1
  151.                     registertimer(5000, "LotsOfBalls", player)
  152.                 else
  153.                     lots_of_balls[player] = lots_of_balls[player] + 1
  154.                     multiball_message[player] = true
  155.                 end
  156.             end
  157.         else
  158.             return 0
  159.         end
  160.     end
  161.    
  162.     return 1
  163. end
  164.  
  165. function GiveBackBall(id, count, player, m_objId)
  166.  
  167.     local assigned = assignweapon(player, m_objId)
  168.     if assigned then
  169.         return 0
  170.     end
  171.    
  172.     return 1
  173. end
  174.  
  175. function OnWeaponAssignment(player, m_objId, slot, tagName)
  176.    
  177.     return 0
  178. end
  179.  
  180. function OnWeaponReload(player, m_weapId)
  181.  
  182.     return 1
  183. end
  184.  
  185. function OnDamageLookup(receiver, causer, tagData, tagName)
  186.  
  187.  
  188. end
  189.  
  190. function OnVehicleEntry(relevant, player, m_vehicleId, tagName, seat)
  191.  
  192.     return 1
  193. end
  194.  
  195. function OnVehicleEject(player, forced)
  196.  
  197.     return 1
  198. end
  199.  
  200. function OnClientUpdate(player, m_objId)
  201.  
  202.     writedword(slayer_globals + player * 0x4, 0x40, #balls[player])
  203. end
  204.  
  205. function AssignBall(id, count, player, m_objId)
  206.  
  207.     local m_object = getobject(m_objId)
  208.     for i = 0, 3 do
  209.         local m_weapId = readdword(m_object, 0x2F8 + i * 4)
  210.         if getobject(m_weapId) then
  211.             destroyobject(m_weapId)
  212.         end
  213.     end
  214.     local x, y, z = getobjectcoords(m_objId)
  215.     local ball = createobject("weap", "weapons\\ball\\ball", 0, 30, false, x, y, z)
  216.     local pp = createobject("weap", "weapons\\plasma pistol\\plasma pistol", 0, 1, false, 0, 0, 0)
  217.     table.insert(balls[player], ball)
  218.     assignweapon(player, pp)
  219.    
  220.     return 0
  221. end
  222.  
  223. function LotsOfBalls(id, count, player)
  224.  
  225.     lots_of_balls[player] = nil
  226.     multiball_message[player] = nil
  227.     return 0
  228. end
  229.  
  230. function ScoreTimer(id, count)
  231.  
  232.     for i = 0,15 do
  233.         local hash = gethash(i)
  234.         if hash then
  235.             local newlines = ""
  236.             for x = 1,30 do
  237.                 newlines = newlines .. " \n"
  238.             end
  239.            
  240.             hprintf(newlines, i)
  241.            
  242.             if multiball_message[i] then
  243.                 hprintf("Picked up " .. lots_of_balls[i] .. " balls!", i)
  244.             end
  245.            
  246.             hprintf("Balls: " .. #balls[i], i)
  247.            
  248.             if messages[hash].str then
  249.                 messages[hash].time = messages[hash].time - 0.5
  250.                 if messages[hash].time > 0 then
  251.                     hprintf(messages[hash].str, i)
  252.                 else
  253.                     messages[hash].str = nil
  254.                     messages[hash].time = nil
  255.                 end
  256.             end
  257.         end
  258.     end
  259.    
  260.     return 1
  261. end
  262.  
  263. function randomFromVolume(x, y, z, d)
  264.  
  265.     local x_min = x - d
  266.     local x_max = x + d
  267.     local y_min = y - d
  268.     local y_max = y + d
  269.     local z_max = z + d
  270.     local x_rand = getrandomnumber(math.floor(x_min * 1000), math.floor(x_max * 1000))
  271.     local y_rand = getrandomnumber(math.floor(y_min * 1000), math.floor(y_max * 1000))
  272.     local z_rand = getrandomnumber(math.floor(z * 1000), math.floor(z_max * 1000))
  273.    
  274.     return x_rand / 1000, y_rand / 1000, z_rand / 1000
  275. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement