Hello,
I have a small problem with the function “GetClosestVehicle” it returns me 0 for a vehicle that I have made appear by hand. But the natural vehicle they look good value.
Example usage
VEHICLE::GET_CLOSEST_VEHICLE(x, y, z, radius, hash, unknown leave at 70)
x, y, z: Position to get closest vehicle to.
radius: Max radius to get a vehicle.
modelHash: Limit to vehicles with this model. 0 for any.
flags: The bitwise flags altering the function’s behaviour.
Does not return police cars or helicopters.
It seems to return police cars for me, does not seem to return helicopters, planes or boats for some reason
Only returns non police cars and motorbikes with the flag set to 70 and modelHash to 0. ModelHash seems to always be 0 when not a modelHash in the scripts, as stated above.
These flags were found in the b617d scripts: 0,2,4,6,7,23,127,260,2146,2175,12294,16384,16386,20503,32768,67590,67711,98309,100359.
Converted to binary, each bit probably represents a flag as explained regarding another native here: gtaforums.com/topic/822314-guide-driving-styles
At exactly 16384 which is 0100000000000000 in binary and 4000 in hexadecimal only planes are returned.
It’s probably more convenient to use worldGetAllVehicles(int *arr, int arrSize) and check the shortest distance yourself and sort if you want by checking the vehicle type with for example VEHICLE::IS_THIS_MODEL_A_BOAT
Police vehicles are not returned by GetClosestVehicle. However, I have no idea why it is not returning normal vehicles.
local pos = GetEntityCoords(player)
local entityWorld = GetOffsetFromEntityInWorldCoords(player, 0.0, 20.0, 0.0)
local rayHandle = CastRayPointToPoint(pos.x, pos.y, pos.z, entityWorld.x, entityWorld.y, entityWorld.z, 10, player, 0)
local a, b, c, d, vehicleHandle = GetRaycastResult(rayHandle)
if vehicleHandle ~= nil then
....
end
‘ELS’ vehicles are marked as mission vehicles, and it’d be a bit silly if, as a scripter, you’d look for a vehicle, and find a vehicle you just created yourself that you already know of.
I’m trying to get my code to find a vehicle the player has never entered,
but this vehicle is in the player’s possession, it’s a police vehicle.
I want a function on this vehicle without theoretical or player to fall,
I just want the fact that the player is close to the vehicle and so call the function
if IsVehicleSirenOn(vehicle) and IsVehicleSirenAudioOn(vehicle) then
SetSirenKeepOn(vehicle,true)
elseif IsVehicleSirenOn(vehicle) and not IsVehicleSirenAudioOn(vehicle) then
SetSirenKeepOn(vehicle,false)
end
What I’ve already managed to make work: If the player turns on the siren sound it will stay on regardless of whether it is inside or outside the vehicle.
What I couldn’t work: If the player turns off the siren sound and enters another vehicle and after that returns to the vehicle the siren remains muted.
In the code I wrote the siren is historical if the player is in or out of the vehicle, but if the player turns off and exits the vehicle and enters another vehicle and after that goes back to the vehicle, the siren that should be muted turns on fully, I need help to fix this.