General > Developers Corner

Allow server console to run admin command


Hey guys, im trying to make it so the following console command can be executed from the server console:

--- Code: ---if (SERVER) then

function Kick( ply, cmd, args )

if !ply:IsUserGroup("moderator") and !ply:IsAdmin() and !ply:IsSuperAdmin() then return false end

local target = findplayer(args[1])
local reason = tostring(args[2])



concommand.Add("a_kick", Kick)

--- End code ---

Now i made it so it checks to make sure the player is at least a moderator to run the command, but how would i go about making it so the command can be executed from the server console, since there wouldnt be a valid player sending the command in that case. I thought about using IsValid, but would that pose any security risks? (as in, is there a situation where someone could make their player entity invalid in order to run this command?)

simply check to see if ply is valid

if ply:IsValid() is nil.. then it's the server console.


[0] Message Index

Go to full version