xXMADEXx Posted June 6, 2013 Share Posted June 6, 2013 Hello guys, i've created my this script, but i have one problem. When im flying in superman, i can see the text ( Which is what i want) but, when im on the ground, my name will go away.... Heres what i mean: http://imageshack.us/a/img405/7652/mtas ... 232608.png http://imageshack.us/photo/my-images/23 ... 32605.png/ Code: drawData = { } function createHeadText ( text, element, r, g, b ) if ( text and element and r and g and b ) then table.insert ( drawData, { text, element, r, g, b } ) end end addCommandHandler ( "track", function ( cmd, who ) createHeadText ( who, getPlayerFromName ( who ), 255, 0, 255 ) end ) ------------------ -- According to this, it says it sould be loading ------------------ addCommandHandler ( "viewtb", function ( ) local amount = tonumber ( #drawData ) outputChatBox ( tostring ( amount ) ) if ( amount > 0 ) then for i, v in ipairs ( drawData ) do local text, element, r, g, b = unpack ( drawData [ i ] ) outputChatBox ( tostring ( i )..": Text: "..text, r, g, b ) end end end ) addEventHandler ( "onClientRender", root, function ( ) for i, v in ipairs ( drawData ) do local text, element, r, g, b = unpack ( drawData [ i ] ) local x, y, z = getElementPosition ( localPlayer ) local tX, tY, tZ = getElementPosition ( element ) local dist = getDistanceBetweenPoints3D ( x, y, z, tX, tY, tZ ) local defdd = 5 -- Note: I have attempted changing this, but didn't do anything if ( dist < defdd ) then local scx, scy = getScreenFromWorldPosition ( tX, tY, tZ + 1) if ( isLineOfSightClear ( x, y, z, tX, tY, tZ ) ) then local scale = 2 * ( ( defdd - dist ) / defdd ) dxDrawText ( text, scx, scy, scx, scy, tocolor ( r, g, b, 255 ), scale, "default-bold", "center", "center", false, false, false ) end end end end ) Link to comment
50p Posted June 6, 2013 Share Posted June 6, 2013 Instead of getting distance between localPlayer and the element, check the distance between camera and element position. Also, the line of sight, you're checking if the line of sight is clear but you're not disabling the peds collision detection, so this will fail. Link to comment
xXMADEXx Posted June 6, 2013 Author Share Posted June 6, 2013 Okey... I tried doing what you said with the camera, and I got this: addEventHandler ( "onClientRender", root, function ( ) for i, v in ipairs ( drawData ) do local text, element, r, g, b = unpack ( drawData [ i ] ) local x, y, z = getElementPosition ( localPlayer ) local tX, tY, tZ, lx, ly, lz, _, _ = getCameraMatrix( ) local dist = getDistanceBetweenPoints3D ( x, y, z, tX, tY, tZ ) local defdd = 5 if ( dist < defdd ) then local scx, scy = getScreenFromWorldPosition ( tX, tY, tZ ) if ( isLineOfSightClear ( x, y, z, tX, tY, tZ ) ) then local scale = 2 * ( ( defdd - dist ) / defdd ) dxDrawText ( text, scx, scy, scx, scy, tocolor ( r, g, b, 255 ), scale, "default-bold", "center", "center", false, false, false ) end end end end ) but for some reason "scx" is returning a boolean. Link to comment
Moderators IIYAMA Posted June 6, 2013 Moderators Share Posted June 6, 2013 Sometimes it returns false, don't know why. if scx then --< Link to comment
50p Posted June 6, 2013 Share Posted June 6, 2013 What do you mean you don't know why? xXMADEXx, you're trying to get point on screen of camera's position. Camera position is at the position of the screen. onClientRender gets triggered after all elements' position get updated and other GTA stuff get renered, so there may be some "delay" if you want to draw something or update position of the camera. I'll now explain why it returns false SOMETIMES. An example: addEventHandler( "onClientRender", root, function( ) local x,y,z = getElementPosition( localPlayer ); setCameraMatrix( x,y,z+15, x,y,z ); end ); Try this script yourself. It's a simple old school top-down GTA camera. When you're moving the camera will follow, the problem is that the faster you move the more "shaky" the camera will be (test it to see what I mean) but if you'll use onClientPreRender then camera will be smooth just like you'd expect it to be. The reason is that onClientPreRender is triggered right after the GTA positions are updated and before all the world rendering. The reason why you get false sometimes is because the camera position gets updated and after all other rendering stuff you get camera's position (GTA:SA processing order). I'm pretty sure it will return false if the camera is not moving at all, am I correct? It's difficult to explain it for me in detail but I hope you get the idea. So, I suggest you get screen position of the element that you want to draw the text for. Currently your code would render all the text in the middle of the screen only when scx will not return false. Read the line 4, is that where you want to draw all the text? At the position of local player or element from drawData table? Link to comment
Moderators IIYAMA Posted June 6, 2013 Moderators Share Posted June 6, 2013 Short: So I am trying to get the camera position, but it is nil/false because it hasn't been updated? Link to comment
50p Posted June 6, 2013 Share Posted June 6, 2013 Short: get position of element on screen instead of camera position on the screen. Ask yourself: why do I get camera position on my screen and how is that even possible? Link to comment
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