this goes directly into the shared.lua file. Please note it respawns you as innocent.
function FindPlayer(target)
local players = player.GetAll()
target = target:lower()
for _, player in ipairs( players ) do
if target == player:Nick():lower() then
return player
end
end
local plyMatch
for _, player in ipairs( players ) do
if player:Nick():lower():find( target, 1, true ) then
if plyMatch then
return nil
end
plyMatch = player
return plyMatch
end
end
if not plyMatch then
return nil
end
end
ChatCommands = {}
function AddChatCommand(cmd, callback)
for k,v in pairs(ChatCommands) do
if cmd == v.cmd then return end
end
table.insert(ChatCommands, {cmd = cmd, callback = callback})
end
function ChatCommandSay(ply, text)
for k, v in pairs(ChatCommands) do
if string.lower(v.cmd) == string.Explode(" ", string.lower(text))[1] then
return v.callback(ply, "" .. string.sub(text, string.len(v.cmd) + 2, string.len(text)))
end
end
end
hook.Add("PlayerSay", "ChatCommandSay", ChatCommandSay)
local function SendPlayerRoles()
for k, v in pairs(player.GetAll()) do
umsg.Start("ttt_role", v)
umsg.Char(v:GetRole())
umsg.End()
end
end
local function SendRoleListMessage(role, role_ids, ply_or_rf)
umsg.Start("role_list", ply_or_rf)
-- send what kind of list this is
umsg.Char(role)
-- list contents
local num_ids = #role_ids
umsg.Char(num_ids)
for i=1, num_ids do
umsg.Short(role_ids[i])
end
umsg.End()
end
local function SendRoleList(role, ply_or_rf, pred)
local role_ids = {}
for k, v in pairs(player.GetAll()) do
if v:IsRole(role) then
if not pred or (pred and pred(v)) then
table.insert(role_ids, v:EntIndex())
end
end
end
SendRoleListMessage(role, role_ids, ply_or_rf)
end
function SendInnocentList(ply_or_rf)
-- Send innocent and detectives a list of actual innocents + traitors, while
-- sending traitors only a list of actual innocents.
local inno_ids = {}
local traitor_ids = {}
for k, v in pairs(player.GetAll()) do
if v:IsRole(ROLE_INNOCENT) then
table.insert(inno_ids, v:EntIndex())
elseif v:IsRole(ROLE_TRAITOR) then
table.insert(traitor_ids, v:EntIndex())
end
end
-- traitors get actual innocent, so they do not reset their traitor mates to
-- innocence
SendRoleListMessage(ROLE_INNOCENT, inno_ids, GetTraitorFilter())
-- detectives and innocents get an expanded version of the truth so that they
-- reset everyone who is not detective
table.Add(inno_ids, traitor_ids)
table.Shuffle(inno_ids)
SendRoleListMessage(ROLE_INNOCENT, inno_ids, GetInnocentFilter())
end
function SendRespawnToAll()
SendPlayerRoles()
SendInnocentList()
end
function RespPlay(ply, args)
if args != nil then
playerz = FindPlayer(args)
end
if playerz == nil then
ply:PrintMessage(HUD_PRINTTALK, "User Not Found")
else
if not ValidEntity(ply) or ply:IsSuperAdmin() or ply:IsAdmin() then
playerz:SetRole(ROLE_INNOCENT)
playerz:UnSpectate()
playerz:SetTeam(TEAM_TERROR)
playerz:StripAll()
playerz:Spawn()
ply:PrintMessage(HUD_PRINTTALK, "You Have Respawned A User.")
playerz:PrintMessage(HUD_PRINTTALK, "You have been respawned.")
SendRespawnToAll()
else
ply:PrintMessage(HUD_PRINTTALK, "Failed To Resapwn Player. Check That You Are Admin.")
end
end
end
AddChatCommand("!respawn", RespPlay)