Sign in to follow this  
Artisz

Vehicle cap position

Recommended Posts

Hi!

 

I want to create a fuel system. But I don't know how to calculate the cap's position. I know, that I can do it with getElementPosition, getElementRotation and Offset. But how?

Share this post


Link to post

For every vehicle the cap is in a different position so you will have to create a table with offsets.

The best way for the offsets to line up every time at any angle is using the element's Matrix.

For this you'd need to enable OOP in your script.

Here's a simple code that does this and make the offsets simple for you to edit

-- This is the offsetTable where we add the vehicles and its  fuel cap
-- [vehicle Model] = Vector3(Right, Forward, Up)
local oT = {
    [411] = Vector3(1.08,-2.1,0.09), --Infernus
    [400] = Vector3(-1,-2.1,-0.09), --Landstalker
    [485] = Vector3(-0.79,0.7,0), --Baggage
}

local color = tocolor( 255, 255, 255 ) -- Simple color variable.

-- Run this function for every frame.
addEventHandler( "onClientRender", root, 
    function( )
        --Create a table of all the vehicles in the server.
        local vehs = getElementsByType"vehicle"

        -- Loop through every vehicle in the server.
        for i=1,#vehs do
            -- Checks if the vehicle's model is in the offsetTable.
            if oT[vehs[i].model] then

                -- Create some simple variables.
                local veh,model,offset = vehs[i],vehs[i].model,oT[vehs[i].model]

                -- Convert the global position to screen position.
                local screenOffset = Vector2(getScreenFromWorldPosition( veh.matrix:transformPosition(offset), 0, false ))

                -- Draw a circle at that location.
                dxDrawText( "●", screenOffset, screenOffset, color, 2, "default", "center", "center" )
            end
        end
    end 
)

https://streamable.com/x3mlx

Edited by loki2143
added video example
  • Like 1

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.