- -- Stockpile
- --The object of this game is to collect as many Oddballs as possible from other players.
- -- Edit these values as you please
- balls_to_win = 25 -- Amount of Balls a player must be carrying to win
- -- Don't touch these
- balls = {}
- lots_of_balls = {}
- multiball_message = {}
- GameEnd = false
- messages = {}
- command_execute = false
- -- Globals
- gametype_base = 0x671340
- slayer_globals = 0x63A0E8
- -- Scorelimit override
- writebyte(gametype_base, 0x58, balls_to_win + 1)
- function GetRequiredVersion()
- return 10057
- end
- function OnScriptLoad(process)
- end
- function OnScriptUnload()
- end
- function OnNewGame(map)
- scoretimer = registertimer(500, "ScoreTimer")
- end
- function OnGameEnd(mode)
- if mode == 1 then
- GameEnd = true
- elseif mode == 2 then
- removetimer(scoretimer)
- end
- end
- function OnServerChat(player, chattype, message)
- return 1
- end
- function OnServerCommand(player, command)
- local hash = gethash(player)
- if hash then
- if not command_execute then
- command_execute = true
- local str = svcmd(command, player)
- messages[hash].str = str
- messages[hash].time = 10
- return 0
- end
- end
- command_execute = false
- return 1
- end
- function OnTeamDecision(team)
- return team
- end
- function OnPlayerJoin(player, team)
- balls[player] = {}
- local hash = gethash(player)
- messages[hash] = {}
- end
- function OnPlayerLeave(player, team)
- local hash = gethash(player)
- messages[hash] = {}
- end
- function OnPlayerKill(killer, victim, mode)
- local m_player = getplayer(victim)
- local m_objId = readdword(m_player, 0x34)
- local x, y, z = getobjectcoords(m_objId)
- for i = 2, #balls[victim] do
- local ox, oy, oz = randomFromVolume(x, y, z, 0.5)
- createobject("weap", "weapons\\ball\\ball", 0, 30, false, ox, oy, oz)
- end
- balls[victim] = {}
- writedword(slayer_globals + victim * 0x4, 0x40, 0)
- end
- function OnKillMultiplier(player, multiplier)
- end
- function OnPlayerSpawn(player, m_objId)
- end
- function OnPlayerSpawnEnd(player, m_objId)
- registertimer(10, "AssignBall", player, m_objId)
- end
- function OnTeamChange(relevant, player, cur_team, dest_team)
- return 1
- end
- function OnObjectCreation(m_objId, player, tagName)
- end
- function OnObjectInteraction(player, m_objId, tagType, tagName)
- if tagName == "weapons\\ball\\ball" then
- if not GameEnd then
- local bool
- for k,v in ipairs(balls[player]) do
- if m_objId == v then
- bool = true
- local assigned = assignweapon(player, m_objId)
- if not assigned then
- registertimer(5, "GiveBackBall", player, m_objId)
- end
- break
- end
- end
- if not bool then
- table.insert(balls[player], m_objId)
- destroyobject(m_objId)
- if not lots_of_balls[player] then
- lots_of_balls[player] = 1
- registertimer(5000, "LotsOfBalls", player)
- else
- lots_of_balls[player] = lots_of_balls[player] + 1
- multiball_message[player] = true
- end
- end
- else
- return 0
- end
- end
- return 1
- end
- function GiveBackBall(id, count, player, m_objId)
- local assigned = assignweapon(player, m_objId)
- if assigned then
- return 0
- end
- return 1
- end
- function OnWeaponAssignment(player, m_objId, slot, tagName)
- return 0
- end
- function OnWeaponReload(player, m_weapId)
- return 1
- end
- function OnDamageLookup(receiver, causer, tagData, tagName)
- end
- function OnVehicleEntry(relevant, player, m_vehicleId, tagName, seat)
- return 1
- end
- function OnVehicleEject(player, forced)
- return 1
- end
- function OnClientUpdate(player, m_objId)
- writedword(slayer_globals + player * 0x4, 0x40, #balls[player])
- end
- function AssignBall(id, count, player, m_objId)
- local m_object = getobject(m_objId)
- for i = 0, 3 do
- local m_weapId = readdword(m_object, 0x2F8 + i * 4)
- if getobject(m_weapId) then
- destroyobject(m_weapId)
- end
- end
- local x, y, z = getobjectcoords(m_objId)
- local ball = createobject("weap", "weapons\\ball\\ball", 0, 30, false, x, y, z)
- local pp = createobject("weap", "weapons\\plasma pistol\\plasma pistol", 0, 1, false, 0, 0, 0)
- table.insert(balls[player], ball)
- assignweapon(player, pp)
- return 0
- end
- function LotsOfBalls(id, count, player)
- lots_of_balls[player] = nil
- multiball_message[player] = nil
- return 0
- end
- function ScoreTimer(id, count)
- for i = 0,15 do
- local hash = gethash(i)
- if hash then
- local newlines = ""
- for x = 1,30 do
- newlines = newlines .. " \n"
- end
- hprintf(newlines, i)
- if multiball_message[i] then
- hprintf("Picked up " .. lots_of_balls[i] .. " balls!", i)
- end
- hprintf("Balls: " .. #balls[i], i)
- if messages[hash].str then
- messages[hash].time = messages[hash].time - 0.5
- if messages[hash].time > 0 then
- hprintf(messages[hash].str, i)
- else
- messages[hash].str = nil
- messages[hash].time = nil
- end
- end
- end
- end
- return 1
- end
- function randomFromVolume(x, y, z, d)
- local x_min = x - d
- local x_max = x + d
- local y_min = y - d
- local y_max = y + d
- local z_max = z + d
- local x_rand = getrandomnumber(math.floor(x_min * 1000), math.floor(x_max * 1000))
- local y_rand = getrandomnumber(math.floor(y_min * 1000), math.floor(y_max * 1000))
- local z_rand = getrandomnumber(math.floor(z * 1000), math.floor(z_max * 1000))
- return x_rand / 1000, y_rand / 1000, z_rand / 1000
- end
Recent Pastes