Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Spectators by 002 v1.0
- -- Converted to Phasor v2 by H® Shaft
- -- Script allows admins to spectate without taking or giving damage, and not visible to other players, type '/spectate' to start/stop
- -- Addition: show constant message to spectating players "You are spectating. Use /spectate to stop. Use /respawn to respawn. "
- -- Can be run as a persistent or non-persistent script
- -- don't edit --
- spectators = {}
- timer_id = {}
- map_reset = false
- game_started = false
- function GetRequiredVersion()
- return 200
- end
- function OnScriptLoad(process, game, persistent)
- Persistent = persistent
- ScriptLoad()
- end
- function OnNewGame(map)
- game_started = false
- ScriptLoad()
- if not new_game_timer then
- new_game_timer = registertimer(0, "NewGameTimer")
- end
- end
- function ScriptLoad()
- if Persistent then
- spectators = {}
- timer_id = {}
- console = {}
- game_started = false
- if not new_game_timer then
- new_game_timer = registertimer(0, "NewGameTimer")
- end
- end
- spectators = {}
- timer_id = {}
- spectator = registertimer(20, "Spectator")
- game_started = false
- console = {}
- consoletimer = registertimer(100, "ConsoleTimer")
- end
- function NewGameTimer(id, count)
- game_started = true
- if map_reset == true then
- map_reset = false
- end
- new_game_timer = nil
- return false
- end
- function OnGameEnd(stage)
- if stage == 1 then
- game_started = false
- if spectator then
- spectator = nil
- end
- for i = 0,15 do
- if getplayer(i) then
- spectators[gethash(i)] = nil
- timer_id[i] = nil
- end
- end
- end
- end
- function OnPlayerLeave(player)
- if getplayer(player) then
- if spectators[gethash(player)] then
- spectators[gethash(player)] = nil
- timer_id[player] = nil
- end
- end
- end
- function Spectator(id, count)
- for i = 0,15 do
- if getplayer(i) then
- if spectators[gethash(i)] and game_started then
- local m_player = getplayer(i)
- local z = readfloat(m_player + 0x100)
- writefloat(m_player + 0x100, z - 1000)
- end
- end
- end
- return true
- end
- function OnServerChat(player, type, message)
- local response = nil
- if player then
- if string.lower(message) == "/spectate" then
- Spectate(player)
- response = false
- elseif string.lower(message) == "/respawn" then
- Respawn(player)
- response = false
- end
- end
- return response
- end
- function OnPlayerSpawn(player, m_objectId)
- if getplayer(player) and game_started then
- if spectators[gethash(player)] then
- local m_player = getplayer(player)
- local m_objectId = getplayerobjectid(player)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- writedword(m_player + 0x2C, 0) -- respawn time 0
- writebit(m_object + 0x10, 0, 1) -- uncollideable/invulnerable
- writebit(m_object + 0x106, 11, 1) -- undamageable except for shields w explosions
- writebit(m_object + 0x204, 20, 1) -- doesn't drop weapons/grenades on death
- end
- end
- end
- end
- end
- function OnVehicleEntry(player, m_vehicleId, seat, mapId, relevant)
- -- blocks spectating players from entering vehicles
- if getplayer(player) and spectators[gethash(player)] then
- return false
- else
- return true
- end
- return nil
- end
- function OnObjectInteraction(player, objId, mapId)
- -- blocks spectating players from picking up weapons and equipment
- local Pass = nil
- local name, type = gettaginfo(mapId)
- if type == "weap" then
- if spectators[gethash(player)] then
- Pass = false
- else
- Pass = true
- end
- elseif type == "eqip" then
- if spectators[gethash(player)] then
- Pass = false
- else
- Pass = true
- end
- end
- return Pass
- end
- function OnDamageLookup(receiving, causing, tagid)
- if receiving and causing and receiving ~= causing then
- local c_player = objectidtoplayer(causing)
- if c_player and spectators[gethash(c_player)] then
- return false
- end
- end
- end
- function Spectate(player)
- if getplayer(player) then
- if isadmin(player) then
- if spectators[gethash(player)] ~= nil then
- KillPlayerSilently(player)
- say(getname(player) .. " is no longer spectating.")
- timer_id[player] = nil
- else
- local m_objectId = getplayerobjectid(player)
- if m_objectId then
- local m_object = getobject(m_objectId)
- local m_player = getplayer(player)
- if m_object then
- say(getname(player) .. " is now spectating.")
- privatesay(player, "Use /spectate to stop. Use /respawn to respawn.")
- timer_id[player] = registertimer(1000, "TellEm", player)
- writedword(m_player + 0x2C, 0)
- KillPlayerSilently(player)
- end
- end
- end
- if spectators[gethash(player)] then
- spectators[gethash(player)] = nil
- else
- spectators[gethash(player)] = true
- end
- else
- privatesay(player, "You are not allowed to spectate.")
- end
- end
- end
- function TellEm(id, count, player)
- if getplayer(player) and game_started then
- if spectators[gethash(player)] then
- local m_objectId = getplayerobjectid(player)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- sendconsoletext(player, "You are spectating. Use /spectate to stop. Use /respawn to respawn. ", 0.11, 1)
- end
- end
- return true
- else
- return false
- end
- end
- end
- function Respawn(player)
- if getplayer(player) then
- if (spectators[gethash(player)] == nil) then
- privatesay(player, "You are not spectating.")
- return
- end
- privatesay(player, "Now respawning...")
- KillPlayerSilently(player)
- end
- end
- function KillPlayerSilently(player)
- if getplayer(player) then
- local m_player = getplayer(player)
- local old_value = readword(m_player + 0xD4)
- writeword(m_player + 0xD4, 0xFFFF)
- kill(player)
- writeword(m_player + 0xD4, old_value)
- writedword(m_player + 0x2C, 0)
- end
- end
- function OnServerCommand(player, command)
- local allow = nil
- local cmd = tokenizecmdstring(command)
- local tokencount = #cmd
- if tokencount > 0 then
- if cmd[1] == "sv_map_reset" then
- map_reset = true
- ScriptLoad()
- privatesay(player, "**RESET** The game has been reset and scripts reloaded. ")
- for i=0,15 do
- if getplayer(i) then
- spectators[gethash(i)] = {}
- timer_id[i] = nil
- kill(i)
- privatesay(i, "**RESET** The game has been reset. ")
- end
- end
- allow = true
- elseif cmd[1] == "sv_script_reload" then
- map_reset = true
- ScriptLoad()
- privatesay(player, "**RELOAD** The game has been reset and scripts reloaded. ")
- for i=0,15 do
- if getplayer(i) then
- spectators[gethash(i)] = {}
- timer_id[i] = nil
- kill(i)
- privatesay(i, "**RELOAD** The game has been reset because scripts were reloaded, your score remains.")
- end
- end
- allow = true
- end
- end
- return allow
- end
- -- Nuggets Sendconsoletext
- console = {}
- console.__index = console
- consoletimer = registertimer(100, "ConsoleTimer")
- phasor_sendconsoletext = sendconsoletext
- function sendconsoletext(player, message, time, order, align, func)
- console[player] = console[player] or {}
- local temp = {}
- temp.player = player
- temp.id = nextid(player, order)
- temp.message = message or ""
- temp.time = time or 5
- temp.remain = temp.time
- temp.align = align or "left"
- temp.func = func
- console[player][temp.id] = temp
- setmetatable(console[player][temp.id], console)
- return console[player][temp.id]
- end
- function nextid(player, order)
- if not order then
- local x = 0
- for k,v in pairs(console[player]) do
- if k > x + 1 then
- return x + 1
- end
- x = x + 1
- end
- return x + 1
- else
- local original = order
- while console[player][order] do
- order = order + 0.001
- if order == original + 0.999 then break end
- end
- return order
- end
- end
- function getmessage(player, order)
- if console[player] then
- if order then
- return console[player][order]
- end
- end
- end
- function getmessages(player)
- return console[player]
- end
- function getmessageblock(player, order)
- local temp = {}
- for k,v in pairs(console[player]) do
- if k >= order and k < order + 1 then
- table.insert(temp, console[player][k])
- end
- end
- return temp
- end
- function console:getmessage()
- return self.message
- end
- function console:append(message, reset)
- if console[self.player] then
- if console[self.player][self.id] then
- if getplayer(self.player) then
- if reset then
- if reset == true then
- console[self.player][self.id].remain = console[self.player][self.id].time
- elseif tonumber(reset) then
- console[self.player][self.id].time = tonumber(reset)
- console[self.player][self.id].remain = tonumber(reset)
- end
- end
- console[self.player][self.id].message = message or ""
- return true
- end
- end
- end
- end
- function console:shift(order)
- local temp = console[self.player][self.id]
- console[self.player][self.id] = console[self.player][order]
- console[self.player][order] = temp
- end
- function console:pause(time)
- console[self.player][self.id].pausetime = time or 5
- end
- function console:delete()
- console[self.player][self.id] = nil
- end
- function ConsoleTimer(id, count)
- for i,_ in opairs(console) do
- if tonumber(i) then
- if getplayer(i) then
- for k,v in opairs(console[i]) do
- if console[i][k].pausetime then
- console[i][k].pausetime = console[i][k].pausetime - 0.1
- if console[i][k].pausetime <= 0 then
- console[i][k].pausetime = nil
- end
- else
- if console[i][k].func then
- if not console[i][k].func(i) then
- console[i][k] = nil
- end
- else
- console[i][k].remain = console[i][k].remain - 0.1
- if console[i][k].remain <= 0 then
- console[i][k] = nil
- end
- end
- end
- end
- if table.len(console[i]) > 0 then
- local paused = 0
- for k,v in pairs(console[i]) do
- if console[i][k].pausetime then
- paused = paused + 1
- end
- end
- if paused < table.len(console[i]) then
- local str = ""
- for i = 0,30 do
- str = str .. " \n"
- end
- phasor_sendconsoletext(i, str)
- for k,v in opairs(console[i]) do
- if not console[i][k].pausetime then
- if console[i][k].align == "right" or console[i][k].align == "center" then
- phasor_sendconsoletext(i, consolecenter(console[i][k].message))
- else
- phasor_sendconsoletext(i, console[i][k].message)
- end
- end
- end
- end
- end
- else
- console[i] = nil
- end
- end
- end
- return true
- end
- function consolecenter(text)
- if text then
- local len = string.len(text)
- for i = len + 1, 78 do
- text = " " .. text
- end
- return text
- end
- end
- function opairs(t)
- local keys = {}
- for k,v in pairs(t) do
- table.insert(keys, k)
- end
- table.sort(keys,
- function(a,b)
- if type(a) == "number" and type(b) == "number" then
- return a < b
- end
- an = string.lower(tostring(a))
- bn = string.lower(tostring(b))
- if an ~= bn then
- return an < bn
- else
- return tostring(a) < tostring(b)
- end
- end)
- local count = 1
- return function()
- if table.unpack(keys) then
- local key = keys[count]
- local value = t[key]
- count = count + 1
- return key,value
- end
- end
- end
- function table.len(t)
- local count = 0
- for k,v in pairs(t) do
- count = count + 1
- end
- return count
- end
- -- Created by H® Shaft.
- -- Thanks to Oxide, AelitePrime, Nugget & Wizard - and 002!
- -- Visit http://halorace.org/forum/index.php?topic=514.0 or
- -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement