Turbe$Z Posted March 1, 2017 Share Posted March 1, 2017 local acl = getPlayerAcls(thePlayer) dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " " .. state .. "" .. " (" .. tostring(acl) .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false ) local drawX = sx - NAMETAG_WIDTH*scale/2 how to fix this? Link to comment
Mr.Loki Posted March 1, 2017 Share Posted March 1, 2017 getPlayerAcls is a custom server-sided function it wont work client-sided Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 and how can i add "acl" to client, from server side? Link to comment
Mr.Loki Posted March 1, 2017 Share Posted March 1, 2017 You can store it in element data from a table to a string with toJSON format then when you want to use it just convert it back to a table using fromJSON you should do it onPlayerLogin and onResourceStart Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 This why not working? --client local admin = getElementData(getLocalPlayer(), "Admin") dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " " .. state .. "" .. " (" .. admin .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false ) local drawX = sx - NAMETAG_WIDTH*scale/2 --server addEventHandler("onPlayerLogin",root, function() if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source ) ), aclGetGroup ( "Admin" ))then setElementData(source,"Admin",true) end end) Link to comment
Mr.Loki Posted March 1, 2017 Share Posted March 1, 2017 You were going correct till you set "Admin" to true a better key should be something everyone could use. Setting a key like "PlayerAcl" and the value of it to the name of the acl is good. Like this: local admin = getElementData(getLocalPlayer(), "PlayerACL") dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " " .. state .. "" .. " (" .. admin .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false ) local drawX = sx - NAMETAG_WIDTH*scale/2 addEventHandler("onPlayerLogin",root, function() if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source ) ), aclGetGroup ( "Admin" ))then setElementData(source,"PlayerACL","Admin") end end) Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 9 minutes ago, Mr.Loki said: You were going correct till you set "Admin" to true a better key should be something everyone could use. Setting a key like "PlayerAcl" and the value of it to the name of the acl is good. Like this: local admin = getElementData(getLocalPlayer(), "PlayerACL") dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " " .. state .. "" .. " (" .. admin .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false ) local drawX = sx - NAMETAG_WIDTH*scale/2 addEventHandler("onPlayerLogin",root, function() if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source ) ), aclGetGroup ( "Admin" ))then setElementData(source,"PlayerACL","Admin") end end) and how can i add more acl? i tried this: elseif isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source ) ), aclGetGroup ( "Everyone" )) then setElementData(source,"PlayerACL","") but doesn't working "Everyone", and "Admin" working fine. Link to comment
Mr.Loki Posted March 1, 2017 Share Posted March 1, 2017 after you setElementData you should use break or return in the function so everything else does not get overwritten. Here's a better way of doing it, This function i made returns the first acl it detects the player is in local allowed= "Admin,SuperModerator,Moderator,Everyone" function hasPermission(player) local ACLs = split(allowed, ',') for _, group in pairs(ACLs)do local ACLgroup = aclGetGroup ( group ) if ACLgroup then local accName = getAccountName(getPlayerAccount( player )) if isObjectInACLGroup ( "user.".. accName, ACLgroup ) then return group end end end end addEventHandler("onPlayerLogin",root, function() local acl = hasPermission(source) setElementData(source,"PlayerACL", acl) end) If you want you can edit the order of the ACL groups in the allowed var. its best to order it from highest rank to lowest 1 Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 5 minutes ago, Mr.Loki said: after you setElementData you should use break or return in the function so everything else does not get overwritten. Here's a better way of doing it, This function i made returns the first acl it detects the player is in local allowed= "Admin,SuperModerator,Moderator,Everyone" function hasPermission(player) local ACLs = split(allowed, ',') for _, group in pairs(ACLs)do local ACLgroup = aclGetGroup ( group ) if ACLgroup then local accName = getAccountName(getPlayerAccount( player )) if isObjectInACLGroup ( "user.".. accName, ACLgroup ) then return group end end end end addEventHandler("onPlayerLogin",root, function() local acl = hasPermission(source) setElementData(source,"PlayerACL", acl) end) If you want you can edit the order of the ACL groups in the allowed var. its best to order it from highest rank to lowest Thanks!!! Working! But, i got error by another function attempt to index local 'str' (a boolean value) function dxDrawColorText(str, ax, ay, bx, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) ax = ax + w color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 5, 6)), 255) end last = e+1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) end end How to fix this? Link to comment
Mr.Loki Posted March 1, 2017 Share Posted March 1, 2017 this happens because the player element data for "PlayerACL" isn't set and is returning false a simple bypass is to just convert str to a string so if u see a player with false as acl they just need to relog you can make a function that loops the players and sets their "PlayerACL" to their acl name onResourceStart function dxDrawColorText(str, ax, ay, bx, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) local str = tostring(str) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) ax = ax + w color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 5, 6)), 255) end last = e+1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) end end Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 9 minutes ago, Mr.Loki said: this happens because the player element data for "PlayerACL" isn't set and is returning false a simple bypass is to just convert str to a string so if u see a player with false as acl they just need to relog you can make a function that loops the players and sets their "PlayerACL" to their acl name onResourceStart function dxDrawColorText(str, ax, ay, bx, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) local str = tostring(str) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) ax = ax + w color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 5, 6)), 255) end last = e+1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) end end like this? addEventHandler ( "onResourceStart",root, function() local acl = hasPermission(source) setElementData(source,"PlayerACL", acl) end) Link to comment
Mr.Loki Posted March 1, 2017 Share Posted March 1, 2017 Yeah but you need o loop through all the players and instead of root use resourceRoot because using root means all elements including other resources addEventHandler ( "onResourceStart",resourceRoot, function() local players = getElementsByType"player" for i,plr in pairs(players)do local acl = hasPermission(plr) setElementData(plr,"PlayerACL", acl) end end) Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 8 minutes ago, Mr.Loki said: Yeah but you need o loop through all the players and instead of root use resourceRoot because using root means all elements including other resources addEventHandler ( "onResourceStart",resourceRoot,function() local players = getElementsByType"player" for i,plr in pairs(players)do local acl = hasPermission(plr) setElementData(plr,"PlayerACL", acl) endend) Thanks and how to remove 'false' text from not logged in players? with isGuestAccount? Link to comment
Mr.Loki Posted March 1, 2017 Share Posted March 1, 2017 (edited) You can use the same data "PlayerACL" in the render function Edited March 1, 2017 by Mr.Loki Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 3 minutes ago, Mr.Loki said: You can use the same data "PlayerACL" in the render function How? Sorry, me very noob:c Link to comment
Moderators Citizen Posted March 1, 2017 Moderators Share Posted March 1, 2017 (edited) 9 minutes ago, Turbo777 said: Thanks and how to remove 'false' text from not logged in players? with isGuestAccount? You might want to get a fallback value like "Guest" if the getElementData returns false: local admin = getElementData(getLocalPlayer(), "PlayerACL") or "Guest" Edited March 1, 2017 by Citizen 1 Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 2 minutes ago, Citizen said: You might want to get a fallback value like "Guest" if the getElementData returns false: local admin = getElementData(getLocalPlayer(), "PlayerACL") or "Guest" Ohh, thanks Link to comment
Mr.Loki Posted March 1, 2017 Share Posted March 1, 2017 Also i forgot to consider the players who have not logged in yet this fix checks if the player has logged in addEventHandler ( "onResourceStart",resourceRoot, function() local players = getElementsByType"player" for i,plr in pairs(players)do if not isGuestAccount(getPlayerAccount(plr))then local acl = hasPermission(plr) setElementData(plr,"PlayerACL", acl) end end end) 1 Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 (edited) 8 minutes ago, Mr.Loki said: Also i forgot to consider the players who have not logged in yet this fix checks if the player has logged in addEventHandler ( "onResourceStart",resourceRoot,function() local players = getElementsByType"player" for i,plr in pairs(players)do if not isGuestAccount(getPlayerAccount(plr))then local acl = hasPermission(plr) setElementData(plr,"PlayerACL", acl) end endend) now connected my friend to the server, and he does not have admin, but show "Admin" text in her name. how to fix this? Edited March 1, 2017 by Turbo777 Link to comment
Turbe$Z Posted March 1, 2017 Author Share Posted March 1, 2017 2 minutes ago, Mr.Loki said: There u go problem solved Yes Link to comment
itHyperoX Posted March 1, 2017 Share Posted March 1, 2017 (edited) wrong topic Edited March 1, 2017 by TheMOG 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