From 23091c2e739ba34730a5791539baa7a526079a77 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 20:25:04 +0000 Subject: [PATCH] add spam free ensureNetToVeh() --- functions.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/functions.lua b/functions.lua index 7ef5b38..a9ba79d 100644 --- a/functions.lua +++ b/functions.lua @@ -190,6 +190,28 @@ function pushVehicle(entity) end end +function ensureNetToVeh(vehNetID) + if Config.System.Debug then print("^6Bridge^7: ^3ensureNetToVeh^7: ^2Requesting NetworkDoesNetworkIdExist^7(^6"..vehNetID.."^7)") end + local timeout = 100 + while not NetworkDoesNetworkIdExist(vehNetID) and timeout > 0 do + timeout -= 1 + Wait(10) + end + if not NetworkDoesNetworkIdExist(vehNetID) then + return 0 + end + timeout = 100 + local vehicle = NetToVeh(vehNetID) + while not DoesEntityExist(vehicle) and vehicle ~= 0 and timeout > 0 do + timeout -= 1 + Wait(10) + end + if not DoesEntityExist(vehicle) then + return 0 + end + return vehicle +end + function makeBlip(data) local blip = AddBlipForCoord(data.coords) SetBlipAsShortRange(blip, true)