Jump to content

[HELP]Only one dxText appears


HeK

Recommended Posts

Hey forum, i got this script here that makes dxText in the markers, but it only works for the 'marker' not for 'marker1' or 'marker2'. Can anyone help me?

--\\\\\\\\\\\\\\\\\\\\\\\\\\ 
--//    Setting 
  
local g_screenX, g_screenY = guiGetScreenSize(); 
local gScale = 0.3; 
local gAlphaDistance = 25; 
local gMaxDistance = 70; -- Max Distance 
local gTextAlpha = 120; 
local gTextSize = 1; 
local gAlphaDiff = gMaxDistance - gAlphaDistance; 
gScale = 1 / gScale * 800 / g_screenY; 
local gMaxScaleCurve = { { 0, 0 }, { 3, 3 }, { 13, 5 } }; 
local gTextScaleCurve = { { 0, 0.8 }, { 0.8, 1.2 }, { 99, 99 } }; 
local gTextAlphaCurve = { { 0, 0 }, { 25, 100 }, { 120, 190 }, { 255, 190 } }; 
  
local marker = createMarker( 1409.8000488281, 1672.8000488281, 10, 'Cylinder', 1.5, 0, 0, 255, 0 ); 
local marker1 = createMarker( 1409.8000488281, 1603.5, 10, 'Cylinder', 1.5, 0, 0, 255, 0 ); 
local marker2 = createMarker( 1409.8000488281, 1534.9000244141, 10, 'Cylinder', 1.5, 0, 0, 255, 0 ); 
  
addEventHandler ( 'onClientRender', root, 
    function ( ) 
        -- 
        local x, y, z = getCameraMatrix(); 
        local x1, y1, z1 = getElementPosition ( marker ); 
        local x2, y2, z2 = getElementPosition ( marker1 ); 
        local x3, y3, z3 = getElementPosition ( marker2 ); 
        local distance_1 = getDistanceBetweenPoints3D( x, y, z, x1, y1, z1 ); 
        local distance_2 = getDistanceBetweenPoints3D( x, y, z, x2, y2, z2 ); 
        local distance_3 = getDistanceBetweenPoints3D( x, y, z, x3, y3, z3 ); 
        -- 
        -- Hangar #1 
        if distance_1 <= gMaxDistance then 
            local x1_, y1_ = getScreenFromWorldPosition( x1, y1, z1 + 0.95, 0.06 ); 
            if x1_ and y1_ then 
                -- 
                local scale = 1 / ( gScale * ( distance_1 / gMaxDistance ) ); 
                local alpha = ( ( distance_1 - gAlphaDistance ) / gAlphaDiff ); 
                alpha = ( alpha < 0 ) and gTextAlpha or gTextAlpha - ( alpha * gTextAlpha ); 
                scale = math.evalCurve( gMaxScaleCurve, scale ); 
                local textscale = math.evalCurve( gTextScaleCurve, scale ); 
                local textalpha = math.evalCurve( gTextAlphaCurve, alpha ); 
                -- 
                dxDrawText( "Shooting - Aim", x1_, y1_, x1_, y1_, tocolor ( 255, 200, 0, textalpha ), textscale * gTextSize, "arial", "center", "bottom", false, false, false, true ); 
            end 
            -- Hangar #2 
        elseif distance_2 <= gMaxDistance then 
            local x2_, y2_ = getScreenFromWorldPosition( x2, y2, z2 + 0.95, 0.06 ); 
            if x2_ and y2_ then 
                -- 
                local scale = 1 / ( gScale * ( distance_2 / gMaxDistance ) ); 
                local alpha = ( ( distance_1 - gAlphaDistance ) / gAlphaDiff ); 
                alpha = ( alpha < 0 ) and gTextAlpha or gTextAlpha - ( alpha * gTextAlpha ); 
                scale = math.evalCurve( gMaxScaleCurve, scale ); 
                local textscale = math.evalCurve( gTextScaleCurve, scale ); 
                local textalpha = math.evalCurve( gTextAlphaCurve, alpha ); 
                -- 
                dxDrawText( "Grenade Practise", x2_, y2_, x2_, y2_, tocolor ( 255, 200, 0, textalpha ), textscale * gTextSize, "arial", "center", "bottom", false, false, false, true ); 
            end  
            -- Hangar #3 
        elseif distance_3 <= gMaxDistance then 
            local x3_, y3_ = getScreenFromWorldPosition( x3, y3, z3 + 0.95, 0.06 ); 
            if x3_ and y3_ then 
            -- 
                local scale = 1 / ( gScale * ( distance_3 / gMaxDistance ) ); 
                local alpha = ( ( distance_3 - gAlphaDistance ) / gAlphaDiff ); 
                alpha = ( alpha < 0 ) and gTextAlpha or gTextAlpha - ( alpha * gTextAlpha ); 
                scale = math.evalCurve( gMaxScaleCurve, scale ); 
                local textscale = math.evalCurve( gTextScaleCurve, scale ); 
                local textalpha = math.evalCurve( gTextAlphaCurve, alpha ); 
                -- 
                dxDrawText( "TDM", x3_, y3_, x3_, y3_, tocolor ( 255, 200, 0, textalpha ), textscale * gTextSize, "arial", "center", "bottom", false, false, false, true ); 
            end  
        end 
    end 
); 
  
-- ////////////////////////////////// 
-- //       MATH FUNCTIONS         // 
-- ////////////////////////////////// 
  
function math.evalCurve( curve, input ) 
    if input < curve[ 1 ][ 1 ] then 
        return curve[ 1 ][ 2 ]; 
    end 
    for idx = 2, #curve do 
        if input < curve[ idx ][ 1 ] then 
            local x1 = curve[ idx - 1 ][ 1 ]; 
            local y1 = curve[ idx - 1 ][ 2 ]; 
            local x2 = curve[ idx ][ 1 ]; 
            local y2 = curve[ idx ][ 2 ]; 
            local alpha = ( input - x1 ) / ( x2 - x1 ); 
            return math.lerp( y1, y2, alpha ); 
        end 
    end 
    return curve[ #curve ][ 2 ]; 
end 
  
function math.lerp( from, to, alpha ) 
    return from + ( to-from ) * alpha; 
end 

Link to comment

You should know how if/elseif statements work.

If 1 statement is correct then it skips others but if the first one is not true then it goes to the next one, if the next one is true then it skips others... So it is obvious that it will only work with 1 and it will be the one that is true. Use "if" instead of "elseif" if you want all of them to be independent.

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