I’m working on another script, and am really, really stuck:
I’m currently trying to get a targetplane of a specific type, and I’ve found GetClosestVehicle to work marvelous. Here’s why:
It returns ONLY 1 specific vehicle
It gets the closest vehicle
In my scripting endeavors, I’ve unfortunately discovered that if the vehicle is moving, (this may be due to the script it belongs to), the native no longer works. The vehicleID is initially the output of the command…until said vehicle starts moving…
My problem is that there’s no accurate alternative for this native in which I can think of.
I’ve considered using raycasting capsule (StartShapeTestCapsule), however a problem occurs if two or more vehicles of that type are close to the player. I can’t believe I’m stuck asking this, but:
How can I get a SINGLE SPECIFIC vehicle, closest to the player that’s moving?
Maybe I don’t know wtf I’m talking about; I just tested this in the middle of the road with random vehicles that pass me by using the following code:
Citizen.CreateThread(function()
while true do
player = GetPlayerPed(-1)
playerloc = GetEntityCoords(player)
closestvehicle = GetClosestVehicle( playerloc.x, playerloc.y, playerloc.z, 13.2 , 0, 70)
--GetClosestVehicle( playerloc.x, playerloc.y, playerloc.z, 13.2 , 1981688531 , 16390 )
displaytext(closestvehicle)
Wait(0)
end
end)
function displaytext(texttodisplay)
SetTextScale(1.5, 1.5)
SetTextEntry("STRING")
AddTextComponentString(texttodisplay)
SetTextCentre(0)
DrawText(0.025, 0.70)
end
And it works just fine. I’m going to assume there’s something wrong with the flags; I’ll play with it, and hopefully I’ll be able to turn up some more documentation…
Okay! It looks like my currentstanding suspicions were correct. Using a rudimentary for loop within LUA, I was able to get all of the validplaneflags for “GetClosestVehicle” while a door was open and moving.
These flags will be uploaded as PlaneFlagsOnGroundMovingDoorOpen
Interesting…so I’ve run my shitty forloop in as many scenrios I can think of and got a few lists similar to the above. My goal is to have the nearest vehicle in ALL scenarios, so I used the unix command comm to find the common lines between all 3 of the files I’ve generated, and cut the list down to 256 flags for the specific plane I’m trying to use.
The goal is to find a flag for GetClosestVehicle that will allow me to target my specific plane in ALL scenarios.
The result will live in the “AllCommonFlags” file!
LOL Joking!
Never really heard of CVehicle. Google reveals it’s a headerfile (.h), but how does this play into lua? How can I test this directly? Are there any resources on reading / leveraging such files?