ULX

Author Topic: Allow server console to run admin command  (Read 4903 times)

0 Members and 1 Guest are viewing this topic.

Offline Doomed

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Allow server console to run admin command
« 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?)
« Last Edit: January 23, 2021, 12:59:49 PM by Doomed »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Allow server console to run admin command
« Reply #1 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.