Jump to content

Distance to transport


Recommended Posts

Hi, help to solve the problem

How to reduce the distance of the checked vehicle?

function checkfuel()
local radius = 0.0001
local player = localPlayer
local x,y,z = getElementPosition(player)
local vehiclesAround = getElementsWithinRange(x, y, z, radius, "vehicle")
local vehicleElement = false
if #vehiclesAround == 0 then
return
end
for i = 1, #vehiclesAround do
vehicleElement = vehiclesAround[i]
local uid = getElementData(vehicleElement, "uid")
dxDrawText ("uid: "..uid, 850, screenHeight - 365, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" )
end
end

function HandleTheRendering ( )
	addEventHandler ( "onClientRender", root, checkfuel )
end

addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering )

 

Screen1

Screen2

Screen3

Screen4

Focus on the right side of the screen where the text is "uid"

In the first screenshot, the value of the first car 

In the second screenshot, the value of the second car

In the third screenshot, I stood between two cars, and the numbers mixed into one.
 How can I make sure that the distance from the car door is considered.

For example. if I'm not standing at the car door it will be like on screen 4

 

Edited by factlight
Link to post
  • Moderators
17 minutes ago, factlight said:

How can I make sure that the distance from the car door is considered.

 

This function can give you the position of the door:

https://wiki.multitheftauto.com/wiki/GetVehicleComponentPosition

(use the example functions to figure out the door component names)

Keep in mind that the door can fall off, might be handy to define the positions inside of a static table.

 


 

And this function can be used to compare the distance between you and the door:

https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D

  • Like 1
Link to post

@IIYAMA

Why is there such a long distance? In theory, if a car hits a radius, its value UID appears in the right corner

 

The machine does not touch the border of the radius. What am I doing wrong?

function checkfuel()
local radius = 1
local player = localPlayer
local x,y,z = getElementPosition(player)
local vehiclesAround = getElementsWithinRange(x, y, z, radius, "vehicle")
--local colshape = createColSphere(x, y, z, tonumber(radius)) -- Used this line to check the radius visually
local vehicleElement = false
if #vehiclesAround == 0 then
return
end
for i = 1, #vehiclesAround do
vehicleElement = vehiclesAround[i]
local uid = getElementData(vehicleElement, "uid")
dxDrawText ("uid: "..uid, 850, screenHeight - 365, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" )
end
end

function HandleTheRendering ( )
	addEventHandler ( "onClientRender", root, checkfuel )
end

addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering )

Screen1

Screen2

Screen3

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...