Ulysses

General => Developers Corner => Topic started by: Doomed on January 23, 2021, 12:57:52 PM

Title: Allow server console to run admin command
Post by: Doomed on January 23, 2021, 12:57:52 PM
Hey guys, im trying to make it so the following console command can be executed from the server console:

Code: [Select]
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])

target:Kick(reason)

end

end
concommand.Add("a_kick", Kick)

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?)
Title: Re: Allow server console to run admin command
Post by: MrPresident on January 25, 2021, 07:47:52 AM
simply check to see if ply is valid

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