ULX

Author Topic: Restricting Players by their group.  (Read 7099 times)

0 Members and 1 Guest are viewing this topic.

Offline Smoot178

  • Newbie
  • *
  • Posts: 39
  • Karma: -4
Restricting Players by their group.
« on: May 08, 2007, 03:28:39 PM »
heres my situation.  I have my server that I want to only let players of a certain group spawn things.  Using the UTeam setup, How can I disallow players that have the default 'Player' group not be able to do anything except walk around.  In addition, I want users of the Members, Trusted, Admins, Superadmins, and Headadmins group to be able to do anything they want.  (Yah there are custom groups in there).  How could one do this?  I'm noob at LUA so if you are kind enough to help, make it noob friendly.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Restricting Players by their group.
« Reply #1 on: May 08, 2007, 04:44:11 PM »
Though I'm sure one of my more experienced coder brethren here might be able to assist more, ULX (which, relies on ULib UCLs) wasn't written to restrict the spawning of props the way you wish.

HOWEVER,
ULib does allow for such code, and custom groups, to be written and controlled.

See your gmod/addons/Ulib/format.txt, the section at the end regarding groups.txt.
Code: [Select]
Format of group in groups.txt--
"<group_name>"
{
"allow"
{
"1" "ulx kick"
"2" "ulx ban"
}
"deny"
{
"1" "ulx cexec"
}
}

You could/can start writing your own groups there in groups.txt. This would at least allow you to get a head start on the ULX commands you want (or don't want) to give  your groups.

I have to say though, there isn't really a noob friendly task. Sorry. Access control rarely is.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Smoot178

  • Newbie
  • *
  • Posts: 39
  • Karma: -4
Re: Restricting Players by their group.
« Reply #2 on: May 08, 2007, 05:03:56 PM »
Are there any ULX commands to restrict props and stuff? 

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Restricting Players by their group.
« Reply #3 on: May 08, 2007, 05:04:44 PM »
Save the following code as blockspawn.lua in the /garrysmod/addons/ulib/lua/ULib/modules folder.
Put the groups that should be allowed to spawn things in the table.

Code: [Select]
if not SERVER then return end

local groups = { "superadmin", "admin", "opperator" } --Add your groups here

local function block_spawn( ply )
    for _,v in groups do
        if ply:IsUserGroup( v ) then
            return
        end
    end
    ULib.tsay( ply, "You are not allowed to spawn objects." )
    return false
end
hook.Add( "PlayerSpawnObject", "block_spawn", block_spawn )
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline Smoot178

  • Newbie
  • *
  • Posts: 39
  • Karma: -4
Re: Restricting Players by their group.
« Reply #4 on: May 09, 2007, 03:18:36 PM »
that doesnt work :(

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Restricting Players by their group.
« Reply #5 on: May 09, 2007, 04:03:29 PM »
that doesnt work :(

*sigh*
Never. Ever. Never just say "it doesn't work"
Give detail. Error messages.
Did you set up your groups.txt?
If you have that set properly, the code should work.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Smoot178

  • Newbie
  • *
  • Posts: 39
  • Karma: -4
Re: Restricting Players by their group.
« Reply #6 on: May 09, 2007, 04:15:28 PM »
hehe.  I added the groups but users that are just clients can spawn items.  No errors...

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Restricting Players by their group.
« Reply #7 on: May 09, 2007, 04:16:56 PM »
Okay, got it to work myself thanks.
« Last Edit: May 09, 2007, 04:39:58 PM by cold12141 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Restricting Players by their group.
« Reply #8 on: May 09, 2007, 07:41:22 PM »
Okay, got it to work myself thanks.

Great!
Cold12141(registered) = Smoot178(guest)?
For those that might read this in the future and wish help with the same challenge, what did you do to get it working?


"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Restricting Players by their group.
« Reply #9 on: May 09, 2007, 08:27:42 PM »
Great!
Cold12141(registered) = Smoot178(guest)?
For those that might read this in the future and wish help with the same challenge, what did you do to get it working?




No, we are two seperate people  :)

Here's the code in which I changed it to in order to get it working:
Code: [Select]
if not SERVER then return end
local function block_spawn( userid, model, propid )
if userid:IsUserGroup( ULib.ACCESS_SUPERADMIN ) then
return
elseif userid:IsUserGroup( ULib.ACCESS_ADMIN ) then
return
elseif userid:IsUserGroup( ULib.ACCESS_HEAD ) then
return
elseif userid:IsUserGroup( ULib.ACCESS_OPERATOR ) then
return
elseif userid:IsUserGroup( ULib.ACCESS_MEMBER ) then
return
elseif userid:IsUserGroup( ULib.ACCESS_TRUST ) then
return
else
ULib.tsay( userid, "You are not allowed to build." )
return false
end
end
local function block_tool( pl, tr, toolmode )
    if pl:IsUserGroup( ULib.ACCESS_SUPERADMIN ) then
return
elseif pl:IsUserGroup( ULib.ACCESS_ADMIN ) then
return
elseif pl:IsUserGroup( ULib.ACCESS_HEAD ) then
return
elseif pl:IsUserGroup( ULib.ACCESS_OPERATOR ) then
return
elseif pl:IsUserGroup( ULib.ACCESS_MEMBER ) then
return
elseif pl:IsUserGroup( ULib.ACCESS_TRUST ) then
return
else
ULib.tsay( pl, "You are not allowed to build." )
return false
end
end
hook.Add( "PlayerSpawnProp", "block_propspawn", block_spawn )
hook.Add( "PlayerSpawnEffect", "block_effectspawn", block_spawn )
hook.Add( "PlayerSpawnVehicle", "block_vehiclespawn", block_spawn )
hook.Add( "PlayerSpawnSENT", "block_sentspawn", block_spawn )
hook.Add( "CanTool", "block_tool", block_tool )
That also has my custom groups built in.
Note: I'm a big lua noob.
« Last Edit: May 10, 2007, 02:41:12 PM by cold12141 »

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Restricting Players by their group.
« Reply #10 on: May 10, 2007, 01:29:04 PM »
Ah, perhapse the PlayerSpawnObject hook doesn't have a return value. (There is no documentation for it, I just know it gets called on anything they spawn).
The for loop should still work, and CanTool can point to the same function as the PlayerSpawn* hooks since all you need is the ply argument whic is first on both.

Code: [Select]
if not SERVER then return end

local groups = { "superadmin", "admin", "opperator" } --Add your groups here

local function block_build( ply )
    for _,v in groups do
        if ply:IsUserGroup( v ) then
            return
        end
    end
    ULib.tsay( ply, "You are not allowed to build." )
    return false
end
hook.Add( "PlayerSpawnProp", "block_prop", block_build )
hook.Add( "PlayerSpawnEffect", "block_effect", block_build )
hook.Add( "PlayerSpawnVehicle", "block_vehicle", block_build )
hook.Add( "PlayerSpawnSENT", "block_sent", block_build )
hook.Add( "CanTool", "block_tool", block_build )

Try that (slightly more efficient).
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Restricting Players by their group.
« Reply #11 on: May 10, 2007, 04:00:09 PM »
Error was something to do with the table.

[EDIT] Cold, I've split your post. See Developers Corner - Custom ULX AddTrustee code Explanation (and help with your code!) there.
« Last Edit: May 10, 2007, 04:19:33 PM by JamminR »

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Restricting Players by their group.
« Reply #12 on: May 11, 2007, 10:00:54 AM »
Oops, forgot about the ipairs (I've been working with Python too much lately.)
Code: [Select]
if not SERVER then return end

local groups = { "superadmin", "admin", "opperator" } --Add your groups here

local function block_build( ply )
    for _,v in ipairs( groups ) do
        if ply:IsUserGroup( v ) then
            return
        end
    end
    ULib.tsay( ply, "You are not allowed to build." )
    return false
end
hook.Add( "PlayerSpawnProp", "block_prop", block_build )
hook.Add( "PlayerSpawnEffect", "block_effect", block_build )
hook.Add( "PlayerSpawnVehicle", "block_vehicle", block_build )
hook.Add( "PlayerSpawnSENT", "block_sent", block_build )
hook.Add( "CanTool", "block_tool", block_build )

That should work now. (hopefully ::))
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage