Jump to content

3D DX for one element


iMr.3a[Z]eF

Recommended Posts

Posted

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 ) 

To Visit Us

Press Here: mtasa://5.9.206.180:22002

b648040241b8f01.png

0d0a7bb38ca13e5.png

Posted (edited)

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

Looking for tutorials or information? check out: www.simpleask.co.uk

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

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

Looking for tutorials or information? check out: www.simpleask.co.uk

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