• Print

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

0 Members and 1 Guest are viewing this topic.

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: ply:isUserGroup advice
« Reply #15 on: May 13, 2015, 09:25:54 pm »
FINAL VERSION... I promise lol
Code: Lua
  1. local convar = CreateConVar("server_mode", "0", FCVAR_ARCHIVE)  -- Basically creates a console command that saves between maps
  2.  
  3. local whitelisted_groups = {} -- table for whitelisted groups
  4.  
  5. gameevent.Listen( "player_connect" ) -- Hooks into the engine's code if I'm not mistaken  (I don't fully understand how it works)
  6.  
  7.  
  8. hook.Add( "player_connect", "player_whitelist", function( data )  -- Lets us hook into the even we're listening too up there ^^
  9.         if convar:GetInt() == 1 then -- if server_mode is equal to 1
  10.                 local steamid = data.networkid -- this is the steamid from the data we got from the hook
  11.                 local userid = data.userid
  12.                 local group = ULib.ucl.getUserInfoFromID(steamid).group -- new ULib function to check user info by steamid
  13.                 if not table.HasValue(whitelisted_groups, group) then -- checks if the group is not in your server whitelist
  14.                         RunConsoleCommand("kickid", userid, "YOU NO ALLOWED!!!!! D:")  
  15.                 end
  16.         end
  17. end )

EDIT:  This would make a nice addon in the releases section.  Which is exactly what you want it for?
« Last Edit: May 13, 2015, 09:29:51 pm by Aaron113 »

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: ply:isUserGroup advice
« Reply #16 on: May 13, 2015, 09:33:18 pm »
That is my bad, I didn't fully test it.

Code: [Select]
local convar = CreateConVar("server_mode", "0", FCVAR_ARCHIVE)  -- Basically creates a console command that saves between maps

local whitelisted_groups = {} -- table for whitelisted groups

gameevent.Listen( "player_connect" ) -- Hooks into the engine's code if I'm not mistaken  (I don't fully understand how it works)


hook.Add( "player_connect", "player_whitelist", function( data )  -- Lets us hook into the even we're listening too up there ^^
if convar:GetInt() == 1 then -- if server_mode is equal to 1
local steamid = data.networkid -- this is the steamid from the data we got from the hook
local userid = data.userid
local group = ULib.ucl.getUserInfoFromID(steamid) -- new ULib function to check user info by steamid
if not table.HasValue(whitelisted_groups, group.group) then -- checks if the group is not in your server whitelist
RunConsoleCommand("kickid", userid, "ENTER YOUR MESSAGE HERE")   
end
end
end )

EDIT:  Ignore me, now I'm doing something else wrong now.... I need to pay closer attention.

EDIT2:  Should be fixed again.

Okay thanks, so if I wanted to give messages to people who ARE in the group, it would be
Code: Lua
  1.                 if not table.HasValue(whitelisted_groups, group.group) then -- checks if the group is not in your server whitelist
  2.                         RunConsoleCommand("kickid", userid, "ENTER YOUR MESSAGE HERE")  
  3. else
  4. ply:PrintMessage("bleh")
  5. end
  6.                 end

example ^
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 #17 on: May 13, 2015, 09:35:03 pm »
Oh and btw, I don't really feel good uploading this and claiming it as my own lol, considering basically 100% of this is yours... I would however put it on my server, and put it on releases and give you 100% credit.
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 #18 on: May 13, 2015, 09:37:56 pm »
AND... to make the ulx command to change the cvar, it would basically be
Code: Lua
  1. function ulx.servermode ( ply )
  2. game.ConsoleCommand("server_mode 1")
  3. end
then the rest of the normal ulx stuff right? and that would automatically make it switch right?
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: ply:isUserGroup advice
« Reply #19 on: May 13, 2015, 09:41:04 pm »
Okay thanks, so if I wanted to give messages to people who ARE in the group, it would be
Code: Lua
  1.                 if not table.HasValue(whitelisted_groups, group.group) then -- checks if the group is not in your server whitelist
  2.                         RunConsoleCommand("kickid", userid, "ENTER YOUR MESSAGE HERE")  
  3. else
  4. ply:PrintMessage("bleh")
  5. end
  6.                 end

example ^
No, this is catching people as soon as they connect to the server.  Meaning at the loading screen.  If you want to print a message to them, you would have to wait for them to spawn and put it in some PlayerSpawn hook.

Oh and btw, I don't really feel good uploading this and claiming it as my own lol, considering basically 100% of this is yours... I would however put it on my server, and put it on releases and give you 100% credit.
I guess if you give me credit and make sure the addon works fine, I could care less.

AND... to make the ulx command to change the cvar, it would basically be
Code: Lua
  1. function ulx.servermode ( ply )
  2. game.ConsoleCommand("server_mode 1")
  3. end
then the rest of the normal ulx stuff right? and that would automatically make it switch right?
That should work, it just won't kick anyone who is currently in the server out and it will not change the name of the server or anything.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: ply:isUserGroup advice
« Reply #20 on: May 19, 2015, 08:38:15 am »
According to the gmod wiki, (I have no clue what player_connect is either but..) data.networkid is not steamid, but unique ID. I could be completely wrong, I think I have seen Garry call it a unique id to be steam id before in the past.
« Last Edit: May 19, 2015, 08:41:19 am by Bite That Apple »
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: ply:isUserGroup advice
« Reply #21 on: May 19, 2015, 08:40:46 am »
According to the gmod wiki, (I have no clue what player_connect is either but..) data.networkid is not steamid, but unique ID. So, not sure how you're getting that to work as a Steam ID.
I don't think so, it worked just fine in the last version I gave.  I guess I would have to double check, but I'm pretty confident that it is steamid seeing as it worked.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: ply:isUserGroup advice
« Reply #22 on: May 19, 2015, 08:44:34 am »
I don't think so, it worked just fine in the last version I gave.  I guess I would have to double check, but I'm pretty confident that it is steamid seeing as it worked.

Yeah, I think I had made a mistake. I didn't finish reading the wiki.

Local steamid = data.networkid // Same as Player: Unique ID ()
Local id = data.userid // Same as Player: UserID ()


- - -

With that in mind though, what function in ulib allows ulib to search in the users.txt for if a player exists in it, and then grab the group data, if that's possible? Because if what I'm thinking is possible, I could fix my player joined announcement script to actually show colour for players who are connected.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: ply:isUserGroup advice
« Reply #23 on: May 19, 2015, 09:20:23 am »
With that in mind though, what function in ulib allows ulib to search in the users.txt for if a player exists in it, and then grab the group data, if that's possible? Because if what I'm thinking is possible, I could fix my player joined announcement script to actually show colour for players who are connected.
MrPresident recently added this to ULib.  I believe you could possibly fetch uteam's colors for groups after that.

EDIT:  Keep in mind that my code on first post of page will error if the user doesn't exist.  I figured whoever uses it can figure that out.
« Last Edit: May 19, 2015, 09:24:21 am by Aaron113 »

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: ply:isUserGroup advice
« Reply #24 on: May 20, 2015, 08:47:13 am »
MrPresident recently added this to ULib.  I believe you could possibly fetch uteam's colors for groups after that.

EDIT:  Keep in mind that my code on first post of page will error if the user doesn't exist.  I figured whoever uses it can figure that out.

Alright, thanks. I'll check it out and see if I can get something to get working. I'll post on my own favorite thread (Questions, Questions, Questions! thread) if I have any issues.
« Last Edit: May 20, 2015, 08:49:21 am by Bite That Apple »
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

  • Print