jingzhi Posted March 24, 2015 Posted March 24, 2015 Hey guys, is there a function to use or a way to dxDraw something based on cordinates in gta? For example, i want to draw "police station" text in front of police station, is that possilbe? Thank y'all!
Addlibs Posted March 24, 2015 Posted March 24, 2015 3D (with perspective)? Or just in a world position?
jingzhi Posted March 24, 2015 Author Posted March 24, 2015 3D (with perspective)? Or just in a world position? In a world position,
Addlibs Posted March 24, 2015 Posted March 24, 2015 This resource might help you: https://community.multitheftauto.com/in ... ls&id=3090
darhal Posted March 24, 2015 Posted March 24, 2015 Yes it s possible here is the code local g_screenX, g_screenY = guiGetScreenSize(); local gScale = 0.3; local gAlphaDistance = 25; local gMaxDistance = 50; -- 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 } }; --------------------- --Settings --just edit those to change color text and postion x = 0 y = 0 z = 0 r, g, b = 255, 0, 255 text = "Hello World" -- ////////////////////////////////// -- // 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 addEventHandler ( "onClientRender", root, function ( ) x = x y = y z = z r = r g = g b = b text = text px, py, pz = getCameraMatrix(); distance_1 = getDistanceBetweenPoints3D( px, py, pz, x, y, z ); if distance_1 <= gMaxDistance then local x_, y_ = getScreenFromWorldPosition( x, y, z + 0.95, 0.06 ); if x_ and y_ 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( tostring(text), x_, y_, x_, y_, tocolor ( r, g, b, textalpha ), textscale * gTextSize, "arial", "center", "bottom", false, false, false, true ); end end end end )
The Don Posted March 24, 2015 Posted March 24, 2015 https://community.multitheftauto.com/in ... ls&id=7613 Example -- Client dxDraw3DText = exports["3d_dx_texts"]:dxDraw3DText("Text Name",x,y,z)
jingzhi Posted March 24, 2015 Author Posted March 24, 2015 This resource might help you: https://community.multitheftauto.com/in ... ls&id=3090 ty ))
jingzhi Posted March 24, 2015 Author Posted March 24, 2015 Yes it s possible here is the code local g_screenX, g_screenY = guiGetScreenSize(); local gScale = 0.3; local gAlphaDistance = 25; local gMaxDistance = 50; -- 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 } }; --------------------- --Settings --just edit those to change color text and postion x = 0 y = 0 z = 0 r, g, b = 255, 0, 255 text = "Hello World" -- ////////////////////////////////// -- // 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 addEventHandler ( "onClientRender", root, function ( ) x = x y = y z = z r = r g = g b = b text = text px, py, pz = getCameraMatrix(); distance_1 = getDistanceBetweenPoints3D( px, py, pz, x, y, z ); if distance_1 <= gMaxDistance then local x_, y_ = getScreenFromWorldPosition( x, y, z + 0.95, 0.06 ); if x_ and y_ 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( tostring(text), x_, y_, x_, y_, tocolor ( r, g, b, textalpha ), textscale * gTextSize, "arial", "center", "bottom", false, false, false, true ); end end end end ) ty
jingzhi Posted March 24, 2015 Author Posted March 24, 2015 https://community.multitheftauto.com/index.php?p=resources&s=details&id=7613Example -- Client dxDraw3DText = exports["3d_dx_texts"]:dxDraw3DText("Text Name",x,y,z) ty ))
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now