From 8bbad1de5d5bbb8b2934f9fdc46eae826cf9745e Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 25 Mar 2020 10:34:42 +0000 Subject: [PATCH] Fixed a bug that caused boats and aircraft to be detected --- cl_radar.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++--- fxmanifest.lua | 2 +- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/cl_radar.lua b/cl_radar.lua index 694aa57..edd621b 100644 --- a/cl_radar.lua +++ b/cl_radar.lua @@ -219,7 +219,11 @@ RADAR.vars = capturedVehicles = {}, -- Table for temp id storage to stop unnecessary trace checks - tempVehicleIDs = {}, + -- needs to be redone + -- tempVehicleIDs = {}, + + -- Table to store the valid vehicle models + validVehicles = {}, -- The current vehicle data for display activeVehicles = {}, @@ -1291,6 +1295,47 @@ function RADAR:GetVehSpeedConverted( speed ) return UTIL:Round( speed * self.speedConversions[unit], 0 ) end +-- Returns the validity of the given vehicle model +function RADAR:GetVehicleValidity( key ) + return self.vars.validVehicles[key] +end + +-- Sets the validity for the given vehicle model +function RADAR:SetVehicleValidity( key, validity ) + self.vars.validVehicles[key] = validity +end + +-- Returns if vehicle validity data exists for the given vehicle model +function RADAR:DoesVehicleValidityExist( key ) + return self:GetVehicleValidity( key ) ~= nil +end + +-- Returns if the given vehicle is valid, as we don't want the radar to detect boats, helicopters, or planes! +function RADAR:IsVehicleValid( veh ) + -- Get the model of the vehicle + local mdl = GetEntityModel( veh ) + + -- Create a key based on the model + local key = tostring( mdl ) + + -- Check if the vehicle model is valid + local valid = self:GetVehicleValidity( key ) + + -- If the validity value hasn't been set for the vehicle model, then we do it now + if ( valid == nil ) then + -- If the model is not what we want, then set the validity to false + if ( IsThisModelABoat( mdl ) or IsThisModelAHeli( mdl ) or IsThisModelAPlane( mdl ) ) then + self:SetVehicleValidity( key, false ) + return false + else + self:SetVehicleValidity( key, true ) + return true + end + end + + return valid +end + -- Gathers all of the vehicles in the local area of the player function RADAR:GetAllVehicles() -- Create a temporary table @@ -1298,8 +1343,10 @@ function RADAR:GetAllVehicles() -- Iterate through vehicles for v in UTIL:EnumerateVehicles() do - -- Insert the vehicle id into the temporary table - table.insert( t, v ) + if ( self:IsVehicleValid( v ) ) then + -- Insert the vehicle id into the temporary table + table.insert( t, v ) + end end -- Return the table diff --git a/fxmanifest.lua b/fxmanifest.lua index d26c812..ed72be7 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -38,7 +38,7 @@ game "gta5" name "Wraith ARS 2X" description "Police radar and plate reader system for FiveM" author "WolfKnight" -version "1.1.1" +version "1.1.2" -- Include the files files {