ULX

Author Topic: ply:isUserGroup advice  (Read 5937 times)

0 Members and 1 Guest are viewing this topic.

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
ply:isUserGroup advice
« on: May 13, 2015, 07:58:05 PM »
Hello, instead of using a password for my "ServerMode" (thanks to JamminR for the reminder), I would be using ply:isUserGroup, but I was wondering wether you could use a code like this for example:

Code: [Select]
RANKS = {"admin","owner"}
if not ply:isUserGroup( RANKS ) then
    ply:kick( "bleh" )
end

or would this not work:
Code: [Select]
ply:isUserGroup( RANKS )
and I would have to use:
Code: [Select]
ply:isUserGroup("admin") or ply:isUserGroup("owner") then ...
Help here would help a lot :P
Thanks.
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: ply:isUserGroup advice
« Reply #1 on: May 13, 2015, 08:18:10 PM »
I did something like this for an addon I made for a friend a while ago

Although I never tried using an if statement like that, I'm 99% sure that won't work
Here's how I would do it while still using tables like you are
table.HasValue

Player:GetUserGroup

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ply:isUserGroup advice
« Reply #2 on: May 13, 2015, 08:21:06 PM »
It would return an error.
"string expected ... returned table"

The proper way to do it, would be as Zmaster states. Use those 2 functions to create your check.

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: ply:isUserGroup advice
« Reply #3 on: May 13, 2015, 08:21:46 PM »
Thanks Zmaster, another question:

How would I get it to ONLY activate when "maintenance mode" is activated, the only way I could think of is to create a ulx command that changes a variable to true or something... like "active = true", but when a map is changed, or server restarted this would be reset back to false wouldn't it?

example:
Code: [Select]
function playerJoin( ply )
if active == true then
...

but as I said, if the map has changed or server restarted then the "active" would be reset back to false
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: ply:isUserGroup advice
« Reply #4 on: May 13, 2015, 08:23:24 PM »
http://wiki.garrysmod.com/page/gameevent/Listen
https://github.com/Nayruden/Ulysses/blob/052983fb132af59859784d3d6320ccdba01fe802/ulib/lua/ulib/server/ucl.lua#L562-L573

That is literally everything you need to do this.  It won't even let them download files.

I got ninja'd, but for the mode being saved, you could just create a cvar or save to a data file.

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: ply:isUserGroup advice
« Reply #5 on: May 13, 2015, 08:25:23 PM »
http://wiki.garrysmod.com/page/gameevent/Listen
https://github.com/Nayruden/Ulysses/blob/052983fb132af59859784d3d6320ccdba01fe802/ulib/lua/ulib/server/ucl.lua#L562-L573

That is literally everything you need to do this.  It won't even let them download files.

I got ninja'd, but for the mode being saved, you could just create a cvar or save to a data file.

New to lua, could you post an example? or perhaps link to another add-on that's used that before.
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: ply:isUserGroup advice
« Reply #6 on: May 13, 2015, 08:33:38 PM »
Would the following work:

Code: [Select]
CreateConVar( "server_mode", "1" )
(server_mode 1 to enable) and to turn it off just add another but with 0?

Code: [Select]
CreateConVar( "server_mode", "0" )
and to read it:
Code: [Select]
if GetConVarNumber( "server_mode" ) == 1 then
...

Is this right?
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given