Jump to content

Why not show player acl?


Turbe$Z

Recommended Posts

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? :S 

Link to comment

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

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
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. :S 

Link to comment

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

  • Like 1
Link to comment
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!!! :D Working! :D

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

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
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

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
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 :D

and how to remove 'false' text from not logged in players?
with isGuestAccount?

Link to comment

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)
  • Like 1
Link to comment
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. O.o how to fix this? :S 

Edited by Turbo777
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...