Zuher Laith Posted January 17, 2016 Share Posted January 17, 2016 Greetings Everyone .. Recently I was looking for an Code to Get The Player Groups to Make the Idea Clear .. Example: In Admin Panel (P) , On Selected Player, it Gave's you the Player Groups , Like (Console, Admin, Everyone) etc. So Basically What I want is to Get the Logged User Groups & Insert it On a Label .. So it's Only Give's the Player Groups Information the Source Player, Not for Another Player. Here is What i Tried: - I tried to Copy the Code in Admin Panel Of Setting the Player Groups, but After Taking a Look on the Code, It was Difficult for Me because I'am not that "PRO" Level At Lua. Any Suggestions Or help Please ? .. Waiting for Reply. Link to comment
Addlibs Posted January 17, 2016 Share Posted January 17, 2016 Admin panel is quite complicated but it doesn't do anything more complex (in that respect) than syncing clientside table with serverside ACL and then looping the table, checking whether such groups in particular apply to the context (the player you're checking against) and concatenation the names of such groups into one string. Link to comment
Zuher Laith Posted January 18, 2016 Author Share Posted January 18, 2016 Admin panel is quite complicated but it doesn't do anything more complex (in that respect) than syncing clientside table with serverside ACL and then looping the table, checking whether such groups in particular apply to the context (the player you're checking against) and concatenation the names of such groups into one string. Could you tell me more please ? or Giving me an Example Code at least ? .. I Didn't Got the Idea .. Link to comment
WhoAmI Posted January 18, 2016 Share Posted January 18, 2016 If I understand it you want to show player's groups, yea? If so, function would look like that -- serverside function getGroups(player) if (isElement(player) and getElementType(player) == "player") then local allGroups = aclGroupList(); local groups = ""; for _, v in ipairs(allGroups) do if (isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), v)) then groups = aclGroupGetName(v) .. ", " .. groups; end end return groups; end end It should return a string which will contain all names of groups that declared player is in. Link to comment
Zuher Laith Posted January 18, 2016 Author Share Posted January 18, 2016 @WhoAmI Yes that's what i was pointing at .. What about the Client Side? because i'am new around here because i want to Set the Groups Into a Label Called Project.CurrentGroupLabel I guess i can't Set the Groups Into the Label In Server Side Right ? .. Link to comment
WhoAmI Posted January 18, 2016 Share Posted January 18, 2016 Okay, then in the event that you create this label add following lines triggerServerEvent("s_getGroups", localPlayer) --insert this into event you create CurrentGroupLabel addEvent("c_getGroups", true) addEventHandler("c_getGroups", localPlayer, function (groups) guiSetText(Project.CurrentGroupLabel, groups) end ); And the serverside code should look like that function getGroups() if (isElement(source) and getElementType(source) == "player") then local allGroups = aclGroupList(); local groups = ""; for _, v in ipairs(allGroups) do if (isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(source)), v)) then groups = aclGroupGetName(v) .. ", " .. groups; end end triggerClientEvent(source, "c_getGroups", source, groups); end end addEvent("s_getGroups", true) addEventHandler("s_getGroups", root, getGroups) Link to comment
Zuher Laith Posted January 18, 2016 Author Share Posted January 18, 2016 @WhoAmI Works Like Magic ! Great !! Thanks for help my friend. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now