• Print

Author Topic: Undercover mod Command  (Read 14833 times)

0 Members and 1 Guest are viewing this topic.

Mr582

  • Guest
Undercover mod Command
« on: August 22, 2013, 07:04:03 pm »
Ok so I need a command that makes it so that if a player is a mod, He can use the command like !undercov and it switches his group. I need it to be like

If Ply:IsUserGroup("moderator") then switch group to undercover

elseif Ply:IsUserGroup("undercover") then switch group to moderator

That is all i know that the command needs to do. It needs to be silent too. Thank you and if you help I will give you credit.

EDIT: Also is there a way to make it so when the undercover group preforms commands you see (Someone) instead of <NAMEHERE>
« Last Edit: August 22, 2013, 07:30:40 pm by Mr582 »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Undercover mod Command
« Reply #1 on: August 22, 2013, 07:37:27 pm »
You're almost there. The other function you'll need for this is SetUserGroup(). Anonymous echoes are a product of the echo mode configuration, it can't be set on a per-command basis.
Experiencing God's grace one day at a time.

Mr582

  • Guest
Re: Undercover mod Command
« Reply #2 on: August 22, 2013, 07:47:08 pm »
You're almost there. The other function you'll need for this is SetUserGroup(). Anonymous echoes are a product of the echo mode configuration, it can't be set on a per-command basis.

What you are basically saying is that I would need to make a plugin of my own to sort the echoes out if I understand you correctly. I think in can get the commands working but if you could help me with the echoes. For the echoes I want it to be like if Ply:IsUserGroup("undercover") then make all command echoes 1 or make all commands silent.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Undercover mod Command
« Reply #3 on: August 22, 2013, 08:13:07 pm »
You can do that by simply putting the logic for echoing (the fancy log function) in the appropriate branches.
Experiencing God's grace one day at a time.

Mr582

  • Guest
Re: Undercover mod Command
« Reply #4 on: August 22, 2013, 08:16:48 pm »
You can do that by simply putting the logic for echoing (the fancy log function) in the appropriate branches.

Thank you. I will make a script in the morning and post it here if it dosent work to see if any of you lua experts will help me. I think I have a good understanding of what I am going to do but the thing is I don't understand the hooks thing. Not sure if hooks are needed but I will see when I am done.

PS I am new to lua. 2 weeks of being exposed to the language

Mr582

  • Guest
Re: Undercover mod Command
« Reply #5 on: August 23, 2013, 10:23:56 am »
I did this at school and I know need some command syntax in there but I will do that once i get home. I have done this so far

Code: Lua
  1. function ulx.UnderCover()
  2.  
  3. (
  4.         If Ply:IsUserGroup("moderator") then -- Checks for if user is in this group
  5.                 SetUserGroup("undercover") -- the group you want to switch too
  6.  
  7.         ElseIf Ply:IsUserGroup("undercover") then --Checks for the group before
  8.                 SetUserGroup("moderator") -- switches back to moderator
  9.  
  10. -- This repeats it self. the reason for this is so different groups with different Cmds can be added such as admin or owner
  11.  
  12.         ElseIf Ply:IsUserGroup("seniormod") then
  13.                 SetUserGroup("snrcover")
  14.  
  15.         ElseIf Ply:IsUserGroup("snrcover") then
  16.                 SetUserGroup("seniormod")
  17.        
  18.         ElseIf Ply:IsUserGroup("admin") then
  19.                 SetUserGroup("admincover")
  20.        
  21.         ElseIf Ply:IsUserGroup("admincover") then
  22.                 SetUserGroup("admin")
  23. )
  24. end
  25.  
  26.  
thats all any help would be appreciated

EDIT: I came home and did some final things to the script and I got errors when I ran it. This is the script

Code: Lua
  1. local CATEGORY_NAME = "Utility"
  2.  
  3.  
  4. function ulx.undercover( target_ply )
  5.  
  6.  
  7.         If Ply:IsUserGroup("moderator") then
  8.                 SetUserGroup("undercover")
  9.  
  10.         ElseIf Ply:IsUserGroup("undercover") then
  11.                 SetUserGroup("moderator")
  12.  
  13.         ElseIf Ply:IsUserGroup("seniormod") then
  14.                 SetUserGroup("snrcover")
  15.  
  16.         ElseIf Ply:IsUserGroup("snrcover") then
  17.                 SetUserGroup("seniormod")
  18.  
  19.         ElseIf Ply:IsUserGroup("admin") then
  20.                 SetUserGroup("admincover")
  21.  
  22.         ElseIf Ply:IsUserGroup("admincover") then
  23.                 SetUserGroup("admin")
  24.         end
  25.  
  26. ulx.fancyLogAdmin( calling_ply, true, "#A went undercover", target_ply )
  27. end
  28. local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercov", true )
  29. spectate:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
  30. spectate:defaultAccess( ULib.ACCESS_ADMIN )
  31. spectate:help( "Makes Mods undercover (no mod tag)" )
  32.  

These are the errors when I joined

Code: [Select]
[ERROR] addons/ulx undercover/lua/ulx/modules/sh/undercover.lua:7: '=' expected
near 'Ply'
  1. unknown - addons/ulx undercover/lua/ulx/modules/sh/undercover.lua:0

Any help please
« Last Edit: August 23, 2013, 02:21:48 pm by Mr582 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Undercover mod Command
« Reply #6 on: August 23, 2013, 03:18:19 pm »
I'm going to only give hints/tips, as most of my team would.
1) Lua is Case Sensitive. Lua has no If or ElseIf, only if and elseif
2) Though you could use Ply if you want, you're not telling that part of code what Ply is. (you're passing your code target_ply, not Ply or ply, and not assigning Ply = target_ply )
3) Just as 'IsUserGroup' requires the player object to test, SetUserGroup has to know what object you're setting too.

EDIT - (and give at least 24 hours before asking for help twice....we're busy here...4 hours isn't really much time to bump a post. I'd go so far as asking you give several days between bumps, else you'll annoy, pretty much true on any forum, but especially one as 'slow' as the Ulysses forums)
« Last Edit: August 23, 2013, 03:20:05 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Mr582

  • Guest
Re: Undercover mod Command
« Reply #7 on: August 23, 2013, 05:35:57 pm »
Thank you for the tips. I am sorry if I came of as annoying and I will try and stay away from that. Ill see what will happen if I change it. Thank you once again.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Undercover mod Command
« Reply #8 on: April 20, 2014, 05:51:54 pm »
I know I wasn't the one who started this thread, but I've been wanting to do this too, and I've been having some trouble.

This is the code for the function/command in my util.lua file:
Code: [Select]
function ulx.undercover( target_ply )
 
if ply:IsUserGroup("owner") then
SetUserGroup("ucowner")
 
elseif ply:IsUserGroup("ucowner") then
SetUserGroup("owner")
end
 
ulx.fancyLogAdmin( calling_ply, true, "#A went undercover", target_ply )
end

local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercov", true )
undercover:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
undercover:defaultAccess( ULib.ACCESS_ADMIN )
undercover:help( "Makes Mods undercover (no mod tag)" )

There are no LUA errors being shown in the console when I type the command, yet it shows the following when I try to type "!undercov Zmaster" (Zmaster is my IGN)



Anyone know how to fix this?

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Undercover mod Command
« Reply #9 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: [Select]
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)" )
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Undercover mod Command
« Reply #10 on: April 20, 2014, 08:37:08 pm »
Thank you, Decicus! It works perfectly now!

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Re: Undercover mod Command
« Reply #11 on: June 09, 2014, 08:53:53 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: [Select]
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)" )

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

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Undercover mod Command
« Reply #12 on: June 10, 2014, 01:31:37 am »
If I wanted to add more how would I do that?
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: [Select]
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)" )
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).
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Re: Undercover mod Command
« Reply #13 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?

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Undercover mod Command
« Reply #14 on: June 10, 2014, 11:35:47 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?
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: [Select]
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)" )
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

  • Print