Jump to content

3D DX for one element


iMr.3a[Z]eF

Recommended Posts

Hello everybody. I'd like to make 3D DX for one element but the code makes the DX for all elementss (Markers)

Here is the original code:

addEventHandler ( "onClientRender", root, 
    function ( ) 
        for index, p in pairs ( getElementsByType ( "marker", resourceRoot ) ) do 
            local x, y, z = getElementPosition ( p ) 
            local x2, y2, z2 = getElementPosition ( localPlayer ) 
            if isLineOfSightClear ( x, y, z, x2, y2, z2, true, true, false, true ) then 
                local sx, sy = getScreenFromWorldPosition ( x, y, z+1 ) 
                if sx and sy then 
                    local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) 
                    if distance < 30 then 
                        dxDrawText ( "Get Your Cash", sx+2, sy+2, sx, sy, tocolor(0, 0, 0, 200), 2-(distance/20), "arial", "center", "center" ) 
                    end 
                end 
            end 
        end 
    end 
) 

And here what I tried but never works:

addEventHandler ( "onClientRender", root, 
    function ( ) 
            local x, y, z = getElementPosition ( isElement (Enter) ) 
            local x2, y2, z2 = getElementPosition ( localPlayer ) 
            if isLineOfSightClear ( x, y, z, x2, y2, z2, true, true, false, true ) then 
                local sx, sy = getScreenFromWorldPosition ( x, y, z+1 ) 
                if sx and sy then 
                    local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) 
                    if distance < 44 then 
                        dxDrawText ( "Police Station", sx+2, sy+2, sx, sy, tocolor(0, 0, 255, 255), 6-(distance/20), "default-bold", "center", "center" ) 
                        dxDrawText ( "Police Station", sx+2, sy-1, sx, sy, tocolor(255, 255, 255, 200), 6-(distance/20), "default-bold", "center", "center" ) 
                    end 
                end 
            end 
        end 
) 

The marker is:

local Enter = createMarker(1555.1221923828,-1675.6265869141, 16.1953125, "corona", 1.5, 0, 0, 255, 255 ) 

Link to comment

because your getting all of the markers, use this:

textsToDraw = {} 
maxrange = 25 
  
local Enter = createMarker(1555.1221923828,-1675.6265869141, 16.1953125, "corona", 1.5, 0, 0, 255, 255 ) 
  
addEventHandler("onClientRender",root, 
    function() 
        for a,b in pairs(textsToDraw) do 
            x2,y2,z2 = b[1],b[2],b[3] 
            px,py,pz = getElementPosition(getLocalPlayer()) 
            scx,scy = getScreenFromWorldPosition (x2,y2,z2) 
            camX,camY,camZ = getCameraMatrix() 
            if scx and scy and getDistanceBetweenPoints3D(camX,camY,camZ,x2,y2,z2+5) <= maxrange and isLineOfSightClear(px,py,pz,x2,y2,z2,true,false,false,true,false,true,false,lp) then 
            dxDrawFramedText(b[4],scx-0.5*dxGetTextWidth(b[4],0.30,"bankgothic"),scy+30-0.5*dxGetFontHeight(0.30,"bankgothic"),x, y+5,tocolor ( b[5], b[6], b[7], 255 ), 0.80,"bankgothic") 
            end 
        end 
    end 
) 
  
function add3DText(x,y,z,text,r,g,b) 
    table.insert(textsToDraw,{x,y,z,text,r,g,b}) 
end 
  
function dxDrawFramedText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , postGUI , frameColor ) 
    color = color or tocolor ( 255 , 255 , 255 , 255 ) 
    frameColor = frameColor or tocolor ( 0 , 0 , 0 , 255 ) 
    scale = scale or 1 
    alignX = alignX or "left" 
    alignY = alignY or "top" 
    clip = clip or false 
    wordBreak = wordBreak or false 
    postGUI = postGUI or false 
    dxDrawText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , postGUI ) 
end 
local xxxm,yyym,zzzm = getElementPosition( Enter ) 
add3DText( xxxm-0.51,yyym+1.01,zzzm+1, "Police Station", 255, 255, 255 ) 
add3DText( xxxm-0.5,yyym+1,zzzm+1, "Police Station", 0, 0, 255 ) 

Edited by Guest
Link to comment
local Enter = createMarker( ... ) 
  
addEventHandler ( "onClientRender", root, 
    function ( ) 
        local x, y, z = getElementPosition ( Enter ) 
        local x2, y2, z2 = getElementPosition ( localPlayer ) 
        if isLineOfSightClear ( x, y, z, x2, y2, z2, true, true, false, true ) then 
            local sx, sy = getScreenFromWorldPosition ( x, y, z+1 ) 
            if sx and sy then 
                local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) 
                if distance < 44 then 
                    dxDrawText ( "Police Station", sx+2, sy+2, sx, sy, tocolor(0, 0, 255, 255), 6-(distance/20), "default-bold", "center", "center" ) 
                    dxDrawText ( "Police Station", sx+2, sy-1, sx, sy, tocolor(255, 255, 255, 200), 6-(distance/20), "default-bold", "center", "center" ) 
                end 
            end 
        end 
    end 
) 

Link to comment
because your getting all of the markers, use this:
textsToDraw = {} 
maxrange = 25 
  
local Enter = createMarker(1555.1221923828,-1675.6265869141, 16.1953125, "corona", 1.5, 0, 0, 255, 255 ) 
  
addEventHandler("onClientRender",root, 
    function() 
        for a,b in pairs(textsToDraw) do 
            x2,y2,z2 = b[1],b[2],b[3] 
            px,py,pz = getElementPosition(getLocalPlayer()) 
            scx,scy = getScreenFromWorldPosition (x2,y2,z2) 
            camX,camY,camZ = getCameraMatrix() 
            if scx and scy and getDistanceBetweenPoints3D(camX,camY,camZ,x2,y2,z2+5) <= maxrange and isLineOfSightClear(px,py,pz,x2,y2,z2,true,false,false,true,false,true,false,lp) then 
            dxDrawFramedText(b[4],scx-0.5*dxGetTextWidth(b[4],0.30,"bankgothic"),scy+30-0.5*dxGetFontHeight(0.30,"bankgothic"),x, y+5,tocolor ( b[5], b[6], b[7], 255 ), 0.80,"bankgothic") 
            end 
        end 
    end 
) 
  
function add3DText(x,y,z,text,r,g,b) 
    table.insert(textsToDraw,{x,y,z,text,r,g,b}) 
end 
  
function dxDrawFramedText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , postGUI , frameColor ) 
    color = color or tocolor ( 255 , 255 , 255 , 255 ) 
    frameColor = frameColor or tocolor ( 0 , 0 , 0 , 255 ) 
    scale = scale or 1 
    alignX = alignX or "left" 
    alignY = alignY or "top" 
    clip = clip or false 
    wordBreak = wordBreak or false 
    postGUI = postGUI or false 
    dxDrawText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , postGUI ) 
end 
local xxxm,yyym,zzzm = getElementPosition( Enter ) 
add3DText( xxxm,yyym,zzzm-2, "Write Here Some Text", 100, 0, 150 ) 

What's the point of that? instead of copying it from somewhere else, you could have just fixed the code he was using.

Link to comment
because your getting all of the markers, use this:
textsToDraw = {} 
maxrange = 25 
  
local Enter = createMarker(1555.1221923828,-1675.6265869141, 16.1953125, "corona", 1.5, 0, 0, 255, 255 ) 
  
addEventHandler("onClientRender",root, 
    function() 
        for a,b in pairs(textsToDraw) do 
            x2,y2,z2 = b[1],b[2],b[3] 
            px,py,pz = getElementPosition(getLocalPlayer()) 
            scx,scy = getScreenFromWorldPosition (x2,y2,z2) 
            camX,camY,camZ = getCameraMatrix() 
            if scx and scy and getDistanceBetweenPoints3D(camX,camY,camZ,x2,y2,z2+5) <= maxrange and isLineOfSightClear(px,py,pz,x2,y2,z2,true,false,false,true,false,true,false,lp) then 
            dxDrawFramedText(b[4],scx-0.5*dxGetTextWidth(b[4],0.30,"bankgothic"),scy+30-0.5*dxGetFontHeight(0.30,"bankgothic"),x, y+5,tocolor ( b[5], b[6], b[7], 255 ), 0.80,"bankgothic") 
            end 
        end 
    end 
) 
  
function add3DText(x,y,z,text,r,g,b) 
    table.insert(textsToDraw,{x,y,z,text,r,g,b}) 
end 
  
function dxDrawFramedText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , postGUI , frameColor ) 
    color = color or tocolor ( 255 , 255 , 255 , 255 ) 
    frameColor = frameColor or tocolor ( 0 , 0 , 0 , 255 ) 
    scale = scale or 1 
    alignX = alignX or "left" 
    alignY = alignY or "top" 
    clip = clip or false 
    wordBreak = wordBreak or false 
    postGUI = postGUI or false 
    dxDrawText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , postGUI ) 
end 
local xxxm,yyym,zzzm = getElementPosition( Enter ) 
add3DText( xxxm,yyym,zzzm-2, "Write Here Some Text", 100, 0, 150 ) 

What's the point of that? instead of copying it from somewhere else, you could have just fixed the code he was using.

actually it's the one i prefer to use and i am guaranteed it does work ( as i just done a test ), and this post of your's wasn't needed.

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