fairyoggy Posted January 31, 2021 Share Posted January 31, 2021 (edited) 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 January 31, 2021 by factlight Link to comment
Moderators IIYAMA Posted January 31, 2021 Moderators Share Posted January 31, 2021 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 1 Link to comment
fairyoggy Posted February 1, 2021 Author Share Posted February 1, 2021 @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 comment
Moderators IIYAMA Posted February 1, 2021 Moderators Share Posted February 1, 2021 2 hours ago, factlight said: Why is there such a long distance? In theory, if a car hits a radius, its value UID appears in the right corner Hmm, I have no idea. Maybe it takes the size of the vehicle in consideration. You can improve your distance check with https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D 1 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