# 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?

##### Link to comment

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.
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
)```
Edited by loki2143
• 1
##### Link to comment

Thanks man, you are awesome!

No prob.

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

• ### Recently Browsing   0 members

• No registered users viewing this page.
×

• #### Social Media

×
• Create New...