Jump to content

Attaching dxText to vehicle component


FuriouZ

Recommended Posts

Hello all!

I have question that how i can attach dxText to vehicle component

Example(guieditor)

mta-screen_2014-04-13_14-25-43.png

If i move camera front of the car,then i get theese errors, otherwise debug doesn't show any errors, but text doesn't appear too

mta-screen_2014-04-13_14-42-25.png

addEventHandler("onClientRender",root,
   function()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    local getComponent = getVehicleComponents(vehicle)
       if ( vehicle ) then
           for k in pairs (getComponent) do
	        local vcpX, vcpY, vcpZ = getVehicleComponentPosition(vehicle, "bump_rear_dummy")
			local vcpSP,vcpSP = getScreenFromWorldPosition ( vcpX, vcpY, vcpZ )
		    if ( vcpSP and vcpSP ) then
				dxDrawLine(vcpSP,vcpSP,796, 547, 871, 472, tocolor(255, 255, 255, 255), 2, true)
                   dxDrawLine(vcpSP,vcpSP,871, 472, 1010, 473, tocolor(255, 255, 255, 255), 2, true)
                   dxDrawText(vcpSP,vcpSP,"Damage: 100%", 871, 449, 1010, 473, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
		    end
		end
    end
   end
)

Edited by Guest
Link to comment

How i get the vehicle matrix ?

something like this ?

        local vehicle = getPedOccupiedVehicle(localPlayer) 
        local vehX, vehY, vehZ, vehLX, vehLY, vehLZ = getCameraMatrix (vehicle) 
        local vcpSP,vcpSP = getScreenFromWorldPosition ( vehX, vehY, vehZ, vehLX, vehLY, vehLZ ) 

Link to comment
function getPositionFromElementOffset(element,offX,offY,offZ) 
  local m = getElementMatrix ( element )  -- Get the matrix 
  local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform 
  local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
  local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
  return x, y, z                               -- Return the transformed point 
end 

Get the offset which equals to minX and minY of vehicle's bounding box and draw a line between the element position and that point.

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