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

HaloNet.Net is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.