Jump to content

Name of player


TorNix~|nR

Recommended Posts

On 12/11/2016 at 5:47 PM, TorNix~|nR said:

hey I use this, and it doesn't work :/


 
  1.  
  1.  
  1.  
  1. addEventHandler("onClientRender", getRootElement(), function ()for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("HassoN") then if v == localPlayer then return end dxDrawTextOnElement(v,"HassoN",1,20,0,0,255,255,1,"arial") end endend)

This is very bad, you're running a loop for every pixel that is rendered.. That would cause major lag issues especially if you have quite a bit of players on the server.

This is a solution however it may not work, run this clientside.

local root = getRootElement()
local localPlayer = getLocalPlayer()
local players = getElementsByType("player")

-- Configuration
local teams = true -- if you change this to false or anything else then you will use acl groups
local moderator = "Mod"
local superModerator = "SMod" -- These are just display names, you can change these to whatever you want.
local admin = "OP"
local console = "Owner"
--

setTimer(function()
	for _,p in pairs(players) do
		local teamName = getTeamName(getPlayerTeam(p))
		setElementData(p,"team",teamName)
	end
end,1000,0)

addEventHandler("onClientRender",root,function()
	if teams == true then
		local team = getElementData(localPlayer,"team")
		dxDrawTextOnElement(localPlayer,team,1,20,0,0,255,255,1,"arial")
	else
		local acc = getAccountName(getPlayerAccount(localPlayer))
		if not isGuestAccount(getPlayerAccount(localPlayer)) then
			if (isObjectInACLGroup("user."..acc,aclGetGroup("Moderator"))) then
				dxDrawTextOnElement(localPlayer,moderator,1,20,0,0,255,255,1,"arial")
			elseif (isObjectInACLGroup("user."..acc,aclGetGroup("SuperModerator"))) then
				dxDrawTextOnElement(localPlayer,superModerator,1,20,0,0,255,255,1,"arial")
			elseif (isObjectInACLGroup("user."..acc,aclGetGroup("Admin"))) then
				dxDrawTextOnElement(localPlayer,admin,1,20,0,0,255,255,1,"arial")
			elseif (isObjectInACLGroup("user."..acc,aclGetGroup("Console"))) then
				dxDrawTextOnElement(localPlayer,console,1,20,0,0,255,255,1,"arial")
			end
		end
	end
end)

 

Edited by shaio
Link to comment

Without reading anything in this topic, are you sure you're running the latest client and server version? Is the file set as a client sided file in your meta?

(reading the post now)

 

The function you're using is a useful function, which means you have to include the function from the wiki in your file.

function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,checkBuildings,checkVehicles,checkPeds,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)
				local x, y, z = getElementPosition(TheElement)
				local x2, y2, z2 = getElementPosition(localPlayer)
				local distance = distance or 20
				local height = height or 1
                                local checkBuildings = checkBuildings or true
                                local checkVehicles = checkVehicles or false
                                local checkPeds = checkPeds or false
                                local checkObjects = checkObjects or true
                                local checkDummies = checkDummies or true
                                local seeThroughStuff = seeThroughStuff or false
                                local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
                                local ignoredElement = ignoredElement or nil
				if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
					local sx, sy = getScreenFromWorldPosition(x, y, z+height)
					if(sx) and (sy) then
						local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
						if(distanceBetweenPoints < distance) then
							dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center")
			end
		end
	end
end

add that at the bottom or top from your file, I would go for top.

Edited by tosfera
Link to comment

working thanks!

but this have much bugs, and the acl doesn't work, only the team (but with much bugs)

can anyone help please?

-- Configuration
local teams = true -- if you change this to false or anything else then you will use acl groups
local moderator = "Mod"
local superModerator = "SMod" -- These are just display names, you can change these to whatever you want.
local admin = "OP"
local console = "Owner"
--

setTimer(function()
	for _,p in pairs(players) do
		local teamName = getTeamName(getPlayerTeam(p))
		setElementData(p,"team",teamName)
	end
end,1000,0)

addEventHandler("onClientRender",root,function()
	if teams == true then
		local team = getElementData(localPlayer,"team")
		dxDrawTextOnElement(localPlayer,team,1,20,0,0,255,255,1,"arial")
	else
		local acc = getAccountName(getPlayerAccount(localPlayer))
		if not isGuestAccount(getPlayerAccount(localPlayer)) then
			if (isObjectInACLGroup("user."..acc,aclGetGroup("Moderator"))) then
				dxDrawTextOnElement(localPlayer,moderator,1,20,0,0,255,255,1,"arial")
			elseif (isObjectInACLGroup("user."..acc,aclGetGroup("SuperModerator"))) then
				dxDrawTextOnElement(localPlayer,superModerator,1,20,0,0,255,255,1,"arial")
			elseif (isObjectInACLGroup("user."..acc,aclGetGroup("Admin"))) then
				dxDrawTextOnElement(localPlayer,admin,1,20,0,0,255,255,1,"arial")
			elseif (isObjectInACLGroup("user."..acc,aclGetGroup("Console"))) then
				dxDrawTextOnElement(localPlayer,console,1,20,0,0,255,255,1,"arial")
			end
		end
	end
end)

 

I need just that, for acls no need teams, for example for VIP ACL: a VIP tag, like that photo

I try so much, but I can not :/ help?

Edited by TorNix~|nR
Link to comment

You're almost trying to kill the client there, seriously.. don't work like that. Better use these steps;

  1. player logs in/joins the server
  2. set their data (their acl group OR a default group), something like: 'rank'
  3. in the onClientRender, loop through the players, get their rank
  4. once you got their rank, get the correct render name (make it an array/table and read it from there for ease)
  5. you're done.
Link to comment

Try this instead, less buggy, uses less ram, and uses element data. Figured it would be just what you're looking for.

-------- Serverside --------
local root = getRootElement()
-- Configuration
teams = true -- if you change this to false or anything else then you will use acl groups
ranks = {
	{name = "VIP"}
}
--

addEventHandler("onPlayerLogin",root,function()
	local teamName = getTeamName(getPlayerTeam(source))
	setAccountData(getPlayerAccount(source),"team",teamName)
	local acc = getAccountName(getPlayerAccount(source))
	for _,rank in pairs(ranks) do
		if not isGuestAccount(getPlayerAccount(source)) then
			if (isObjectInACLGroup("user."..acc,aclGetGroup(rank.name))) then
				setAccountData(getPlayerAccount(source),"acl",rank.name)
			end
		end
	end
end)
----------------------------

-------- Clientside --------
local root = getRootElement()
addEventHandler("onClientRender",root,function()
	if teams == true then
		local team = getElementData(localPlayer,"team")
		if team then
			dxDrawTextOnElement(localPlayer,team,1,20,0,0,255,255,1,"arial")
		end
	else
		local acc = getAccountName(getPlayerAccount(localPlayer))
		local rank = getAccountData(getPlayerAccount(localPlayer),"acl")
		if not isGuestAccount(getPlayerAccount(localPlayer)) then
			if rank then
				if (isObjectInACLGroup("user."..acc,aclGetGroup(rank)) then
					dxDrawTextOnElement(localPlayer,rank,1,20,0,0,255,255,1,"arial")
				end
			end
		end
	end
end)
----------------------------

 

Link to comment
aMyGroups = { 'Console','Admin','Moderator' };

addEventHandler ( 'onPlayerLogin',root,
    function (  _,aMyAccount )
    if isGuestAccount ( aMyAccount ) then return end;
    for _,aGroup in next,aMyGroups do
    if isObjectInACLGroup ( 'user.'..getAccountName ( aMyAccount ),aclGetGroup ( aGroup ) ) then
            setElementData ( source,'aDrawMyText',true );
      	    end
        break
    end
end
);

 

 

-- On Client Side

dxDrawTextOnElement = function (TheElement,text,height,distance,R,G,B,alpha,size,font,checkBuildings,checkVehicles,checkPeds,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)
                local x, y, z = getElementPosition(TheElement)
                local x2, y2, z2 = getElementPosition(localPlayer)
                local distance = distance or 20
                local height = height or 1
                                local checkBuildings = checkBuildings or true
                                local checkVehicles = checkVehicles or false
                                local checkPeds = checkPeds or false
                                local checkObjects = checkObjects or true
                                local checkDummies = checkDummies or true
                                local seeThroughStuff = seeThroughStuff or false
                                local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
                                local ignoredElement = ignoredElement or nil
                if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
                    local sx, sy = getScreenFromWorldPosition(x, y, z+height)
                    if(sx) and (sy) then
                        local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
                        if(distanceBetweenPoints < distance) then
                            dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center")
            end
        end
    end
end

addEventHandler ( 'onClientRender',root,
    function (      )
        if getElementData ( localPlayer,'aDrawMyText' ) or getPlayerTeam ( localPlayer ) == getTeamFromName ( 'aMyTeamName' ) then
            dxDrawTextOnElement ( localPlayer,'Staff Member',1,10,255,0,0,255,1 )
        end
    end
)

-- PS. You have to login again also change the team name in line 3 in render function.GL.

 

PS. First code with orange functions is in server side! @shaio

Edited by iPrestege
Typo
Link to comment
7 hours ago, TorNix~|nR said:

Okey, will wait, and thanks too much ^^

Okay this script is tested and fully functional, almost fully customizable as well. Your tag will not display for you, but it will for other players. Best of luck to you. I hope this is what you were looking for. If there is anything else you want added, let me know.

server.lua - 

-------- Serverside --------
local root = getRootElement()
-- Configuration
teams = false -- Turning this to false will make the text acl group names. Turning it to true will use team names.
teamColor = true --[[ If teams are on and this is false the tags will be black. If teams are off and this is off,
			you will use acl colors in the ranks table. If this is on and teams are off, you will use
			the players team color but with the acl tag.]]
ranks = { -- Do not add a console rank it might screw things up..
	{id = "Everyone",r = 255,g = 255,b = 255}, -- < You need this rank or else the tag will display as false. I've made it display "Player".
	{id = "Moderator",r = 0,g = 255,b = 0},
	{id = "SuperModerator",r = 0,g = 255,b = 255},
	{id = "Admin",r = 0,g = 0,b = 255}
}
--

addEventHandler("onResourceStart",root,function()
	for _,plr in pairs(getElementsByType("player")) do
		if teams == true then
			local team = getTeamName(getPlayerTeam(plr))
			local r,g,b = getTeamColor(getPlayerTeam(plr))
			if team then
				setElementData(plr,"text",team)
				if teamColor == true then
					setElementData(plr,"r",r)
					setElementData(plr,"g",g)
					setElementData(plr,"b",b)
				else
					setElementData(plr,"r",0)
					setElementData(plr,"g",0)
					setElementData(plr,"b",0)
				end
			end
		else
			local acc = getAccountName(getPlayerAccount(plr))
			if not isGuestAccount(getPlayerAccount(plr)) then
				for _,rank in pairs(ranks) do
					if (isObjectInACLGroup("user."..acc,aclGetGroup(rank.id))) then
						if teamColor == true then
							local r,g,b = getTeamColor(getPlayerTeam(plr))
							setElementData(plr,"r",r)
							setElementData(plr,"g",g)
							setElementData(plr,"b",b)
						else
							setElementData(plr,"r",rank.r)
							setElementData(plr,"g",rank.g)
							setElementData(plr,"b",rank.b)
						end
						if rank.id == "Everyone" then
							setElementData(plr,"text","Player")
						else
							setElementData(plr,"text",rank.id)
						end
					end
				end
			end
		end
	end
end)

addEventHandler("onPlayerLogin",root,function()
	if teams == true then
		local team = getTeamName(getPlayerTeam(source))
		local r,g,b = getTeamColor(getPlayerTeam(source))
		if team then
			setElementData(source,"text",team)
			if teamColor == true then
				setElementData(source,"r",r)
				setElementData(source,"g",g)
				setElementData(source,"b",b)
			else
				setElementData(source,"r",0)
				setElementData(source,"g",0)
				setElementData(source,"b",0)
			end
		end
	else
		local acc = getAccountName(getPlayerAccount(source))
		if not isGuestAccount(getPlayerAccount(source)) then
			for _,rank in pairs(ranks) do
				if (isObjectInACLGroup("user."..acc,aclGetGroup(rank.id))) then
					if teamColor == true then
						local r,g,b = getTeamColor(getPlayerTeam(source))
						setElementData(source,"r",r)
						setElementData(source,"g",g)
						setElementData(source,"b",b)
					else
						setElementData(source,"r",rank.r)
						setElementData(source,"g",rank.g)
						setElementData(source,"b",rank.b)
					end
					if rank.id == "Everyone" then
						setElementData(source,"text","Player")
					else
						setElementData(source,"text",rank.id)
					end
				end
			end
		end
	end
end)
----------------------------

 

client.lua - 

-------- Clientside --------
local root = getRootElement()
local localPlayer = getLocalPlayer()
local height = 1.2 -- You can change this to say how high you want it above the player.

function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,checkBuildings,checkVehicles,checkPeds,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)
	local x, y, z = getElementPosition(TheElement)
	local x2, y2, z2 = getElementPosition(localPlayer)
	local distance = distance or 20
	local height = height or 1
	local checkBuildings = checkBuildings or true
	local checkVehicles = checkVehicles or false
	local checkPeds = checkPeds or false
	local checkObjects = checkObjects or true
	local checkDummies = checkDummies or true
	local seeThroughStuff = seeThroughStuff or false
	local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
	local ignoredElement = ignoredElement or nil
	if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
		local sx, sy = getScreenFromWorldPosition(x, y, z+height)
		if(sx) and (sy) then
			local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
			if(distanceBetweenPoints < distance) then
				dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center")
			end
		end
	end
end

addEventHandler("onClientRender",root,function()
	for _,plr in pairs(getElementsByType("player")) do
		if plr ~= localPlayer then
			local r,g,b = getElementData(plr,"r"),getElementData(plr,"g"),getElementData(plr,"b")
			dxDrawTextOnElement(plr,tostring(getElementData(plr,"text")),height,30,r,g,b,255,1.5,"arial")
		end
	end
end)
----------------------------

 

Edited by shaio
Link to comment

Use this server.lua instead, it's less code.

 

-------- Serverside --------
local root = getRootElement()
-- Configuration
teams = true -- Turning this to false will make the text acl group names. Turning it to true will use team names.
teamColor = true --[[ If teams are on and this is false the tags will be black. If teams are off and this is off,
			you will use acl colors in the ranks table. If this is on and teams are off, you will use
			the players team color but with the acl tag.]]
ranks = { -- Do not add a console rank it might screw things up..
	{id = "Everyone",r = 255,g = 255,b = 255}, -- < You need this rank or else the tag will display as false. I've made it display "Player".
	{id = "Moderator",r = 0,g = 255,b = 0},
	{id = "SuperModerator",r = 0,g = 255,b = 255},
	{id = "Admin",r = 0,g = 0,b = 255}
}
--

setTimer(function()
	for _,plr in pairs(getElementsByType("player")) do
		if teams == true then
			local team = getTeamName(getPlayerTeam(plr))
			local r,g,b = getTeamColor(getPlayerTeam(plr))
			if team then
				setElementData(plr,"text",team)
				if teamColor == true then
					setElementData(plr,"r",r)
					setElementData(plr,"g",g)
					setElementData(plr,"b",b)
				else
					setElementData(plr,"r",0)
					setElementData(plr,"g",0)
					setElementData(plr,"b",0)
				end
			end
		else
			local acc = getAccountName(getPlayerAccount(plr))
			if not isGuestAccount(getPlayerAccount(plr)) then
				for _,rank in pairs(ranks) do
					if (isObjectInACLGroup("user."..acc,aclGetGroup(rank.id))) then
						if teamColor == true then
							local r,g,b = getTeamColor(getPlayerTeam(plr))
							setElementData(plr,"r",r)
							setElementData(plr,"g",g)
							setElementData(plr,"b",b)
						else
							setElementData(plr,"r",rank.r)
							setElementData(plr,"g",rank.g)
							setElementData(plr,"b",rank.b)
						end
						if rank.id == "Everyone" then
							setElementData(plr,"text","Player")
						else
							setElementData(plr,"text",rank.id)
						end
					end
				end
			end
		end
	end
end,1000,0)
----------------------------

 

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