Jump to content

Dx draw bug


Deep thinker

Recommended Posts

hello i have created a simple staff tag but i am using dxdrawtext to make it but it's bugged .it includes every time to have this tag when i am in the criminal team it draws the text.

function renderStaffTag()
	local streamedPlayers = getElementsByType ("player", root, true)
	if getPlayerTeam(p) or getPlayerTeam(p) ~= getTeamFromName("Staff") then
	if streamedPlayers and #streamedPlayers ~= 0 then
		local lpos = {getElementPosition(localPlayer)}
		for _,p in ipairs (streamedPlayers) do
			if p and isElement (p) then
					local ppos = {getElementPosition(p)}
					if getDistanceBetweenPoints3D (lpos[1], lpos[2], lpos[3], ppos[1], ppos[2], ppos[3]) <= 20 then
						local x, y = getScreenFromWorldPosition (ppos[1], ppos[2], ppos[3]+1.2)
						if x and y then
							dxDrawText ("Staff Member", x+1, y+1, x, y, tocolor (0, 0, 0), 1, "pricedown", "center")
							dxDrawText ("Staff Member", x, y, x, y, tocolor (52, 0, 66), 1, "pricedown", "center")
						end
					end
				end
			end
		end
	end
end
addEventHandler ("onClientRender", root, renderStaffTag)

 

Link to comment

Line 3: if you have a team (and you said you were in criminal team) the condition is true and then the code is executed, check again that line
Edit: i suggest you to fix the tabbings to align the ends to their respective statement if these are presents in your script

Edited by LoPollo
  • Like 1
Link to comment
29 minutes ago, LoPollo said:

Line 3: if you have a team (and you said you were in criminal team) the condition is true and then the code is executed, check again that line
Edit: i suggest you to fix the tabbings to align the ends to their respective statement if these are presents in your script

i have checked the line 3, i have also edited it but there is  a bug 

function renderStaffTag()
    local streamedPlayers = getElementsByType ("player", root, true)
    if not getPlayerTeam(p) or getPlayerTeam(p) ~= getTeamFromName("Staff") then return end
    if streamedPlayers and #streamedPlayers ~= 0 then
        local lpos = {getElementPosition(localPlayer)}
        for _,p in ipairs (streamedPlayers) do
            if p and isElement (p) then
                    local ppos = {getElementPosition(p)}
                    if getDistanceBetweenPoints3D (lpos[1], lpos[2], lpos[3], ppos[1], ppos[2], ppos[3]) <= 20 then
                        local x, y = getScreenFromWorldPosition (ppos[1], ppos[2], ppos[3]+1.2)
                        if x and y then
                            dxDrawText ("Staff Member", x+1, y+1, x, y, tocolor (0, 0, 0), 1, "pricedown", "center")
                            dxDrawText ("Staff Member", x, y, x, y, tocolor (52, 0, 66), 1, "pricedown", "center")
                        end
                    end
                end
            end
        end
    end

addEventHandler ("onClientRender", root, renderStaffTag)

now it doesn't draw anything .

Link to comment

Use this : 

function renderStaffTag()
    local streamedPlayers = getElementsByType ("player", root, true)
        local lpos = {getElementPosition(localPlayer)}
        for _,p in ipairs (streamedPlayers) do
            if p and isElement (p) then
			    if not getPlayerTeam(p) or getPlayerTeam(p) ~= getTeamFromName("Staff") then return end
    if streamedPlayers and #streamedPlayers ~= 0 then
                    local ppos = {getElementPosition(p)}
                    if getDistanceBetweenPoints3D (lpos[1], lpos[2], lpos[3], ppos[1], ppos[2], ppos[3]) <= 20 then
                        local x, y = getScreenFromWorldPosition (ppos[1], ppos[2], ppos[3]+1.2)
                        if x and y then
                            dxDrawText ("Staff Member", x+1, y+1, x, y, tocolor (0, 0, 0), 1, "pricedown", "center")
                            dxDrawText ("Staff Member", x, y, x, y, tocolor (52, 0, 66), 1, "pricedown", "center")
                        end
                    end
                end
            end
        end
    end

addEventHandler ("onClientRender", root, renderStaffTag)

 

  • Like 1
Link to comment
1 minute ago, Default said:

Use this : 


function renderStaffTag()
    local streamedPlayers = getElementsByType ("player", root, true)
        local lpos = {getElementPosition(localPlayer)}
        for _,p in ipairs (streamedPlayers) do
            if p and isElement (p) then
			    if not getPlayerTeam(p) or getPlayerTeam(p) ~= getTeamFromName("Staff") then return end
    if streamedPlayers and #streamedPlayers ~= 0 then
                    local ppos = {getElementPosition(p)}
                    if getDistanceBetweenPoints3D (lpos[1], lpos[2], lpos[3], ppos[1], ppos[2], ppos[3]) <= 20 then
                        local x, y = getScreenFromWorldPosition (ppos[1], ppos[2], ppos[3]+1.2)
                        if x and y then
                            dxDrawText ("Staff Member", x+1, y+1, x, y, tocolor (0, 0, 0), 1, "pricedown", "center")
                            dxDrawText ("Staff Member", x, y, x, y, tocolor (52, 0, 66), 1, "pricedown", "center")
                        end
                    end
                end
            end
        end
    end

addEventHandler ("onClientRender", root, renderStaffTag)

 

thank you ,it worked successfully

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