• Command Permission
    4 replies, posted
So I've tried to add a command to mapvote addon that allows mods and higher to cancel a rock the vote. I have added: [code] function AdminCancelrtv( ply, text, teamonly ) for k, v in pairs(player.GetAll()) do if v:IsUserGroup("mod+") or v:IsUserGroup("moderator") or v:IsUserGroup("trialmod") then if (text == "!rtvcancel") then setState( "STATE_NOVOTE" ) v:PrintMessage( HUD_PRINTTALK, ply:Nick() .. " has cancelled the rock the vote." ) end end end end hook.Add( "PlayerSay", "AdminCancelrtv", AdminCancelrtv ) [/code] But this allows everybody to use the command !rtvcancel (everybody outside the usergroups listed in the if statement) I'm a newb at lua so please excuse any obvious dumbness If anyone could help me resolve this that would be great! :)
Use the ply argument. Example: [lua] if (!ply:IsUserGroup("moderator") and !ply:IsAdmin()) then return end [/lua] This will stop the function execution if the player isn't admin nor moderator.
[QUOTE=ms333;41814269]Use the ply argument. Example: [lua] if (!ply:IsUserGroup("moderator") and !ply:IsAdmin()) then return end [/lua] This will stop the function execution if the player isn't admin nor moderator.[/QUOTE] I tried this but I had no luck, wouldn't execute the command at all. Maybe I placed it wrong so an example using the code above would be super :)
you need an else statement. [lua] if v:IsUserGroup("mod+") or v:IsUserGroup("moderator") or v:IsUserGroup("trialmod") then if (text == "!rtvcancel") then setState( "STATE_NOVOTE" ) v:PrintMessage( HUD_PRINTTALK, ply:Nick() .. " has cancelled the rock the vote." ) end end else return end [/lua]
[QUOTE=ms333;41814269]Use the ply argument. Example: [lua] if (!ply:IsUserGroup("moderator") and !ply:IsAdmin()) then return end [/lua] This will stop the function execution if the player isn't admin nor moderator.[/QUOTE] After playing around with what you posted I managed to get it working :D Here is the code if anyone wants to reference/search for a thread like this in the future [code] function AdminCancelrtv( ply, text, teamonly ) if (text == "!rtvcancel") then if ply:IsUserGroup("moderator") or ply:IsUserGroup("admin") or ply:IsUserGroup("mod+") or ply:IsUserGroup("owner")then setState( "STATE_NOVOTE" ) ply:PrintMessage( HUD_PRINTTALK, ply:Nick() .. " has cancelled the rock the vote." ) else ply:PrintMessage(HUD_PRINTTALK, ply:Nick().." You do not have access to this command.") end end end hook.Add( "PlayerSay", "AdminCancelrtv", AdminCancelrtv ) [/code]
Sorry, you need to Log In to post a reply to this thread.