How do I give someone a rank through Glua. For example when the player clicks a button it sets them to a certain rank eg
[CODE]local giverank = vgui.Create( "Button" )
giverank:SetSize( 150, 30 )
giverank:SetText( "Accept" )
giverank:SetVisible( true )
function giverank:OnMousePressed()
local ply = LocalPlayer()
ply: --- Give rank part here?
end[/CODE]
[QUOTE=Skate;45384933]How do I give someone a rank through Glua. For example when the player clicks a button it sets them to a certain rank eg
[CODE]local giverank = vgui.Create( "Button" )
giverank:SetSize( 150, 30 )
giverank:SetText( "Accept" )
giverank:SetVisible( true )
function giverank:OnMousePressed()
local ply = LocalPlayer()
ply: --- Give rank part here?
end[/CODE][/QUOTE]
Try using this:
groups.changeUserGroup( ID, Group )
To see how it works, take a look at "ulx\lua\ulx\xgui\groups.lua" (Line 162)
[QUOTE=Skate;45384933]How do I give someone a rank through Glua. For example when the player clicks a button it sets them to a certain rank eg
[CODE]local giverank = vgui.Create( "Button" )
giverank:SetSize( 150, 30 )
giverank:SetText( "Accept" )
giverank:SetVisible( true )
function giverank:OnMousePressed()
local ply = LocalPlayer()
ply: --- Give rank part here?
end[/CODE][/QUOTE]
You need to network it to the server, you can only set rank on the server, once on the serverside you can use [url]http://wiki.garrysmod.com/page/Player/SetUserGroup[/url]
[QUOTE=Braden1996;45384946]Try using this:
groups.changeUserGroup( ID, Group )
To see how it works, take a look at "ulx\lua\ulx\xgui\groups.lua" (Line 162)[/QUOTE]
That alone won't work, since button is clientside and you can only effectively change usergroups serverside.
You'll need to send a net message.
[QUOTE=Khub;45384958]That alone won't work, since button is clientside and you can only effectively change usergroups serverside.
You'll need to send a net message.[/QUOTE]
Well, that's how XGUI does it in their groups section - which I presume is Client Side unless ULX is doing it's silly things. If my suggestion doesn't work, you'll be best to use a 'net.SendToServer' and then 'net.WriteString' to write both the SteamID and the GroupID. Once Server-Side it's pretty easy :)
[QUOTE=Braden1996;45384987]Well, that's how XGUI does it in their groups section - which I presume is Client Side unless ULX is doing it's silly things. If my suggestion doesn't work, you'll be best to use a 'net.SendToServer' and then 'net.WriteString' to write both the SteamID and the GroupID. Once Server-Side it's pretty easy :)[/QUOTE]
There's no reason to send your own SteamID, as you can get that by using the player entity which net.Receive provide.
Also, on the serverside you add with ULib.ucl.addUser(id, {}, {}, group)
I just double checked, using my initial method of using 'groups.changeUserGroup( ID, Group )' will work as inside that function there are RunConsoleCommands which effectively send your player's SteamID and group to the Server - where ULX deals with them properly. That's how ULX deals with this problem, so that's the safest way for you to approach it too.
Best of luck :)
[editline]14th July 2014[/editline]
[QUOTE=ms333;45385013]There's no reason to send your own SteamID, as you can get that by using the player entity which net.Receive provide.[/QUOTE]
He never said the SteamID would just be his own. What if it was another player?
[QUOTE=Braden1996;45385014]I just double checked, using my initial method of using 'groups.changeUserGroup( ID, Group )' will work as inside that function there are RunConsoleCommands which effectively send your player's SteamID and group to the Server - where ULX deals with them properly. That's how ULX deals with this problem, so that's the safest way for you to approach it too.
Best of luck :)
[editline]14th July 2014[/editline]
He never said the SteamID would just be his own. What if it was another player?[/QUOTE]
In net receive, it give the Player entity in the arguments, I don't understand what you're on about.
Also, is ULX retarded? Can you seriously rank yourself client side?
[QUOTE=AnonTakesOver;45385021]In net receive, it give the Player entity in the arguments, I don't understand what you're on about.
Also, is ULX retarded? Can you seriously rank yourself client side?[/QUOTE]
I don't really know where they're defining this function: [url]https://github.com/Nayruden/Ulysses/search?q=changeUserGroup[/url]
[editline]14th July 2014[/editline]
[lua]
function groups.changeUserGroup( ID, group )
if ID == "NULL" then
Derma_Message( "Cannot add/remove invalid players (Bots) using XGUI!", "XGUI NOTICE" )
else
if group == "user" then
RunConsoleCommand( "ulx", "removeuserid", ID )
else
RunConsoleCommand( "ulx", "adduserid", ID, group )
end
end
end
[/lua]
There^ You could use that method.
[QUOTE=ms333;45385027]I don't really know where they're defining this function: [url]https://github.com/Nayruden/Ulysses/search?q=changeUserGroup[/url]
[editline]14th July 2014[/editline]
[lua]
function groups.changeUserGroup( ID, group )
if ID == "NULL" then
Derma_Message( "Cannot add/remove invalid players (Bots) using XGUI!", "XGUI NOTICE" )
else
if group == "user" then
RunConsoleCommand( "ulx", "removeuserid", ID )
else
RunConsoleCommand( "ulx", "adduserid", ID, group )
end
end
end
[/lua]
There^ You could use that method.[/QUOTE]
Lol, that's the method I suggested.. But that function is already created; so you obviously don't need to recreate it when you could just use it directly.
[QUOTE=ms333;45385027]I don't really know where they're defining this function: [url]https://github.com/Nayruden/Ulysses/search?q=changeUserGroup[/url]
[editline]14th July 2014[/editline]
[lua]
function groups.changeUserGroup( ID, group )
if ID == "NULL" then
Derma_Message( "Cannot add/remove invalid players (Bots) using XGUI!", "XGUI NOTICE" )
else
if group == "user" then
RunConsoleCommand( "ulx", "removeuserid", ID )
else
RunConsoleCommand( "ulx", "adduserid", ID, group )
end
end
end
[/lua]
There^ You could use that method.[/QUOTE]
Ohh, yeah, if that's what ulx does, it makes more sense, it runs a console command which the server then validates to make sure that the person adding the target to the group has the powers to do so I assume.
I was going to say, if you could just add yourself client side without any checks...
[QUOTE=Braden1996;45385045]Lol, that's the method I suggested.. But that function is already created; so you obviously don't need to recreate it when you could just use it directly.[/QUOTE]
I took it from ulx... Just acknowledging that it's there, which I was unaware of.
[QUOTE=AnonTakesOver;45385021]In net receive, it give the Player entity in the arguments, I don't understand what you're on about.
Also, is ULX retarded? Can you seriously rank yourself client side?[/QUOTE]
Oh my god, you people really like to talk blindly.
Obviously ULX requires a method of adding players to groups Client-Side - otherwise you would have to use your server's console or lua_run or something like that. So I just went and found the method which ULX uses to send change-group requests to the server. Once this request is received server-side; ULX does all the checks and such and if the player doesn't have the appropriate permission - nothing will happen with the request.
And you seem unable to comprehend about what I was saying regarding net.recieve. The argument which is passed into the callback function is the player who did net.SendToServer. But, what if that player was trying to change the usergroup of a different player? How would the net.recieve know which player's group to change? It can't, unless we send it a SteamID or something else similar.
Next time, please actually understand what you're posting before just posting blind-sighted. I'm only trying to help the guy out by saving him as much time as possible and telling him that there is already a function which exists for his required purpose; so he might as well just it.
[editline]14th July 2014[/editline]
[QUOTE=ms333;45385052]I took it from ulx... Just acknowledging that it's there, which I was unaware of.[/QUOTE]
Sorry lol I was just getting very mad at some of the people above smashing on my reasoning.
[editline]14th July 2014[/editline]
Now can any of you lovely people change those mean 'Dumb' ratings on my posts :(
[QUOTE=Braden1996;45385071]Oh my god, you people really like to talk blindly.
Obviously ULX requires a method of adding players to groups Client-Side - otherwise you would have to use your server's console or lua_run or something like that. So I just went and found the method which ULX uses to send change-group requests to the server. Once this request is received server-side; ULX does all the checks and such and if the player doesn't have the appropriate permission - nothing will happen with the request.
And you seem unable to comprehend about what I was saying regarding net.recieve. The argument which is passed into the callback function is the player who did net.SendToServer. But, what if that player was trying to change the usergroup of a different player? How would the net.recieve know which player's group to change? It can't, unless we send it a SteamID or something else similar.
Next time, please actually understand what you're posting before just posting blind-sighted. I'm only trying to help the guy out by saving him as much time as possible and telling him that there is already a function which exists for his required purpose; so he might as well just it.
[editline]14th July 2014[/editline]
Sorry lol I was just getting very mad at some of the people above smashing on my reasoning.[/QUOTE]
If you actually look at the code OP provided, he defined ply as LocalPlayer, meaning that he just wanted to set the local player's rank, which there then isn't a reason to send the SteamID.
Also, there's no need to have a function clientside to change rank, it could either be a networked request or simply a console command which it already is in this case. They're just making it simpler, but it's not required.
Well apart from the rant, thanks for that :suicide:
[QUOTE=ms333;45385083]If you actually look at the code OP provided, he defined ply as LocalPlayer, meaning that he just wanted to set the local player's rank, which there then isn't a reason to send the SteamID.
Also, there's no need to have a function clientside to change rank, it could either be a networked request or simply a console command which it already is in this case. They're just making it simpler, but it's not required.[/QUOTE]
Ahhh, I never noticed that he specifically wanted a LocalPlayer's group to change cause I didn't read his code - which seems a bit of an odd thing to do. And yes, there isn't a need to use a function; but it makes the entire system much easier to manage.
[QUOTE=Braden1996;45385096]Ahhh, I never noticed that he specifically wanted a LocalPlayer's group to change cause I didn't read his code - which seems a bit of an odd thing to do. And yes, there isn't a need to use a function; but it makes the entire system much easier to manage.[/QUOTE]
That is odd indeed, and if he's ranked as user it won't really work with groups.changeUserGroup since it requires you to be SA...
[QUOTE=Braden1996;45385096]Ahhh, I never noticed that he specifically wanted a LocalPlayer's group to change cause I didn't read his code - which seems a bit of an odd thing to do. And yes, there isn't a need to use a function; but it makes the entire system much easier to manage.[/QUOTE]
Makes more sense to use your method [IMG]http://icons.iconarchive.com/icons/famfamfam/silk/16/thumb-up-icon.png[/IMG]
Although like ms333 said. Users can't change their own ranks
[QUOTE=ms333;45385127]That is odd indeed, and if he's ranked as user it won't really work with groups.changeUserGroup since it requires you to be SA...[/QUOTE]
Forgive me if I'm being a bit dopey, but where does groups.changeUserGroup require you to be an SA? If you mean that it checks your permissions Server-side, then yes; that could be an issue. But why in gods Earth would you want to let an ordinary user change their group?
If you want it to work regardless of the user's current rank, then you'd have to use something custom.. say net messages with your own steamid hard coded on the server's receive check
[QUOTE=Blasteh;45385267]If you want it to work regardless of the user's current rank, then you'd have to use something custom.. say net messages with your own steamid hard coded on the server's receive check[/QUOTE]
hard coded? Or you know, you could just
[code]
-- Client
net.Start("MakeMeAdmin")
net.SendToServer()
-- Server
util.AddNetworkString("MakeMeAdmin")
net.Receive("MakeMeAdmin", function( len, ply )
local id = ply:SteamID()
-- make that id admin.
-- if setusergroup works you could just do ply:SetUserGroup("admin")
end)
[/code]
Why would you need to hard code anything?
You can add users to any group server side without needing an already super admins id.
[QUOTE=Braden1996;45385197]Forgive me if I'm being a bit dopey, but where does groups.changeUserGroup require you to be an SA? If you mean that it checks your permissions Server-side, then yes; that could be an issue. But why in gods Earth would you want to let an ordinary user change their group?[/QUOTE]
Its more of a testing thing. I wanted to try create something where when users agree to the terms it changes their rank from guest who cannot move, or type or anything to a member. Playing around customizing things
[QUOTE=AnonTakesOver;45385283]hard coded? Or you know, you could just
[code]
-- Client
net.Start("MakeMeAdmin")
net.SendToServer()
-- Server
util.AddNetworkString("MakeMeAdmin")
net.Receive("MakeMeAdmin", function( len, ply )
local id = ply:SteamID()
-- make that id admin.
-- if setusergroup works you could just do ply:SetUserGroup("admin")
end)
[/code]
Why would you need to hard code anything?
You can add users to any group server side without needing an already super admins id.[/QUOTE]
Because if they were already in an admin group then they wouldn't need to ask the server for themselves to be put in an admin group??
edit: also, because you should never let a client request admin and just do it without any checks.
[QUOTE=Skate;45385551]Its more of a testing thing. I wanted to try create something where when users agree to the terms it changes their rank from guest who cannot move, or type or anything to a member. Playing around customizing things[/QUOTE]
I had a suspicious you would be doing something like that. You'd be best to do it all yourself, independent of ULX as that's not really what it is designed for. It wouldn't be all that tricky to implement, I'd suggest you create an SQL Table with two fields 'SteamID' and 'Accepted'. From that you can easily finish up the task and you'll probably learn a lot doing it too :)
Sorry, you need to Log In to post a reply to this thread.