General > Developers Corner

Undercover mod Command

<< < (3/4) > >>

Zmaster:
Thank you, Decicus! It works perfectly now!

Valgoid:

--- Quote from: Decicus on April 20, 2014, 06:57:31 PM ---You're trying to check if "ply" is set to a group, yet "ply" is never defined.
You're only defining target_ply, never calling_ply, which you have used in the logging.
As stated by JamminR as well, SetUserGroup also requires the player (same way you're using IsUserGroup).
Also, if you're making a command that can only be used on yourself and no one else. You wouldn't really need target_ply, calling_ply would work fine just as-is.

I might have forgotten to mention something, it's sort of late at night here, but this should work:

--- Code: ---function ulx.undercover( calling_ply )
 
if calling_ply:IsUserGroup("owner") then
calling_ply:SetUserGroup("ucowner")
 
elseif calling_ply:IsUserGroup("ucowner") then
calling_ply:SetUserGroup("owner")
end
 
ulx.fancyLogAdmin( calling_ply, true, "#A went undercover" )
end

local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercov", true )
undercover:defaultAccess( ULib.ACCESS_ADMIN )
undercover:help( "Makes Mods undercover (no mod tag)" )

--- End code ---

--- End quote ---

If I wanted to add more how would I do that?

Decicus:

--- Quote from: Valgoid on June 09, 2014, 08:53:53 PM ---If I wanted to add more how would I do that?

--- End quote ---
What do you mean?
If you want to have support for multiple groups, let's say: 'mod', 'u_mod', 'admin', 'u_admin', then you'd just add more elseif's to check for what group they're in and set them to the corresponding undercover group.

Like this:

--- Code: ---function ulx.undercover( calling_ply )
 
if calling_ply:IsUserGroup("admin") then
calling_ply:SetUserGroup("u_admin")
 
elseif calling_ply:IsUserGroup("mod") then
calling_ply:SetUserGroup("u_mod")
end
 
ulx.fancyLogAdmin( calling_ply, true, "#A went undercover" )
end
local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercov", true )
undercover:defaultAccess( ULib.ACCESS_ADMIN )
undercover:help( "Makes Mods undercover (no mod tag)" )

--- End code ---
Of course, this isn't really an ideal command, since it doesn't have any way of putting you back into the original group (this could be done with checking for "setOpposite" and such).

Valgoid:
So this only works with 2 ranks i want owner to go undercover to u_owner, admin to go to u_admin and mod to go to u_mod. is that possible?

Decicus:

--- Quote from: Valgoid on June 10, 2014, 10:12:55 AM ---So this only works with 2 ranks i want owner to go undercover to u_owner, admin to go to u_admin and mod to go to u_mod. is that possible?

--- End quote ---
No, I just mistyped and replaced the previous if/elseif's I had from before. owner -> u_owner, admin -> u_admin and mod -> u_mod would look something like this:

--- Code: ---function ulx.undercover( calling_ply )
 
if calling_ply:IsUserGroup("admin") then
calling_ply:SetUserGroup("u_admin")
 
elseif calling_ply:IsUserGroup("mod") then
calling_ply:SetUserGroup("u_mod")

elseif calling_ply:IsUserGroup("owner") then
calling_ply:SetUserGroup("u_owner")

end
 
ulx.fancyLogAdmin( calling_ply, true, "#A went undercover" )
end
local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercov", true )
undercover:defaultAccess( ULib.ACCESS_ADMIN )
undercover:help( "Makes Mods undercover (no mod tag)" )

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version