Kill command enabled only for certain jobs / ulx ranks
4 replies, posted
Hello all of you wonderful people!
I've recently been messing around with some DarkRP lua, and i've came to a conclusion that a lot of people use the "kill" console command as a way to just be annoying or getting away from wherever that might be (an admin sit, during rp etc.). So i've found this piece of code on another forum, which disables the kill command alltogether and gives the player a message in chat. This is the code: (i've put the code into quotes because if i put it under code it seems much messier for me)
local function BlockSuicide(ply)
ply:ChatPrint("[UV] If you're stuck, call a Staff member by using @")
return false
end
hook.Add( "CanPlayerSuicide", "BlockSuicide", BlockSuicide )
So i've tried making it so only certain jobs / ulx usergroups would be able to use it but sadly with no success. The main point of this is so people can't just randomly kill themselves and for the certain groups to be able to if it's needed to test anything etc. This is the one i tried, but it just disabled the whole thing so everyone could use the kill command again.
local function BlockSuicide(ply)
ply:ChatPrint("[UV] If you're stuck, call a Staff member by using @")
return false
end
hook.Add( "CanPlayerSuicide", "BlockSuicide", BlockSuicide, function(ply)
return ply:Team() == TEAM_STAFFONDUTY or ply:Team() == TEAM_EVENT or ply:SteamID() == "STEAM_0:1:10000001" or ply:IsUserGroup( "superadmin" )
end)
I would higly appreciate any kind of help, as you can see i'm kind of a begginer at coding in general, just trying my best. Also i've put the lua file under garrysmod/lua/autorun/server if that helps in any way.
Sorry for the long post, hopefully someone can lend a helping hand.
Thank you for reading and have a wonderful day!
You can't have multiple callbacks for hook.Add
This should work
hook.Add("CanPlayerSuicide", "BlockSuicide", function(ply)
if ply:Team() == TEAM_STAFFONDUTY or ply:Team() == TEAM_EVENT or ply:SteamID() == "STEAM_0:1:10000001" or ply:IsUserGroup( "superadmin" ) then
return true
end
ply:ChatPrint("[UV] If you're stuck, call a Staff member by using @")
return false
end)
Well he can, but not like that, specially when he already has a hook returning false, which also breaks all the others.
Thank you all very much for reading through and helping me out! Tried the code @Donkie wrote and it works like a charm! Thank you all again for taking your time and have a wonderful day!
Sorry, you need to Log In to post a reply to this thread.