From 03c9fbb95305f7e390ee0c3e89fe22e785331528 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 16 Dec 2019 21:31:42 +0000 Subject: [PATCH] Added the ability to have a fast limit --- __resource.lua | 2 +- cl_radar.lua | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- config.lua | 2 +- docs/version.txt | 2 +- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/__resource.lua b/__resource.lua index 76da125..d2543f5 100644 --- a/__resource.lua +++ b/__resource.lua @@ -10,7 +10,7 @@ resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' name 'Wraith ARS 2X' description 'An advanced radar system for FiveM' author 'WolfKnight' -version 'beta2b' +version 'beta2c' ui_page "nui/radar.html" diff --git a/cl_radar.lua b/cl_radar.lua index 34c5720..26b6e3e 100644 --- a/cl_radar.lua +++ b/cl_radar.lua @@ -106,7 +106,7 @@ RADAR.vars = { displayText = { "¦¦¦", "FAS" }, optionsText = { "On¦", "Off" }, options = { true, false }, optionIndex = 1, settingText = "fastDisplay" }, { displayText = { "¦SL", "SEn" }, optionsText = { "¦1¦", "¦2¦", "¦3¦", "¦4¦", "¦5¦" }, options = { 0.2, 0.4, 0.6, 0.8, 1.0 }, optionIndex = 3, settingText = "same" }, { displayText = { "¦OP", "SEn" }, optionsText = { "¦1¦", "¦2¦", "¦3¦", "¦4¦", "¦5¦" }, options = { 0.2, 0.4, 0.6, 0.8, 1.0 }, optionIndex = 3, settingText = "opp" }, - { displayText = { "BEE", "P¦¦" }, optionsText = { "Off", "¦1¦", "¦2¦", "¦3¦", "¦4¦", "¦5¦" }, options = { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 }, optionIndex = 4, settingText = "beep" }, + { displayText = { "bEE", "P¦¦" }, optionsText = { "Off", "¦1¦", "¦2¦", "¦3¦", "¦4¦", "¦5¦" }, options = { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 }, optionIndex = 4, settingText = "beep" }, { displayText = { "Uni", "tS¦" }, optionsText = { "USA", "INT" }, options = { "mph", "kmh" }, optionIndex = 1, settingText = "speedType" } }, @@ -341,6 +341,50 @@ function RADAR:OpenRemote() end end +-- Returns if the fast limit option should be available for the radar +function RADAR:IsFastLimitAllowed() + return self.config.allow_fast_limit +end + +-- Only create the functions if the fast limit config option is enabled +if ( RADAR:IsFastLimitAllowed() ) then + -- Adds settings into the radar's variables for when the allow_fast_limit variable is true + function RADAR:CreateFastLimitConfig() + -- Create the options for the menu + local fastOptions = + { + { displayText = { "FAS", "Loc" }, optionsText = { "On¦", "Off" }, options = { true, false }, optionIndex = 2, settingText = "fastLock" }, + { displayText = { "FAS", "SPd" }, optionsText = {}, options = {}, optionIndex = 12, settingText = "fastLimit" } + } + + -- Iterate from 5 to 200 in steps of 5 and insert into the fast limit option + for i = 5, 200, 5 do + local text = UTIL:FormatSpeed( i ) + + table.insert( fastOptions[2].optionsText, text ) + table.insert( fastOptions[2].options, i ) + end + + -- Create the settings with the default options + self:SetSettingValue( "fastLock", false ) + self:SetSettingValue( "fastLimit", 60 ) + + -- Add the fast options to the main menu options table + table.insert( self.vars.menuOptions, fastOptions[1] ) + table.insert( self.vars.menuOptions, fastOptions[2] ) + end + + -- Returns the numerical fast limit + function RADAR:GetFastLimit() + return self.vars.settings["fastLimit"] + end + + -- Returns if the fast lock menu option is on or off + function RADAR:IsFastLockEnabled() + return self.vars.settings["fastLock"] + end +end + --[[---------------------------------------------------------------------------------- Radar menu functions @@ -1385,7 +1429,8 @@ function RADAR:Main() -- and stored in the trace stage, but the speed would've only been obtained and stored once, which -- means that it woulsn't be the current speed local vehSpeed = GetEntitySpeed( av[ant][i].veh ) - data.antennas[ant][i].speed = UTIL:FormatSpeed( self:GetVehSpeedConverted( vehSpeed ) ) + local convertedSpeed = self:GetVehSpeedConverted( vehSpeed ) + data.antennas[ant][i].speed = UTIL:FormatSpeed( convertedSpeed ) -- Work out if the vehicle is closing or away local ownH = UTIL:Round( GetEntityHeading( PLY.veh ), 0 ) @@ -1397,6 +1442,14 @@ function RADAR:Main() self:SetAntennaFastData( ant, data.antennas[ant][i].speed, data.antennas[ant][i].dir ) else self:SetAntennaData( ant, data.antennas[ant][i].speed, data.antennas[ant][i].dir ) + end + + -- Lock the speed automatically if the fast limit system is allowed + if ( self:IsFastLimitAllowed() ) then + -- Make sure the speed is larger than the limit, and that there isn't already a locked speed + if ( self:IsFastLockEnabled() and convertedSpeed > self:GetFastLimit() and not self:IsAntennaSpeedLocked( ant ) ) then + self:LockAntennaSpeed( ant ) + end end else -- If the active vehicle is not valid, we reset the internal data @@ -1426,6 +1479,10 @@ Citizen.CreateThread( function() RADAR:CacheNumRays() RADAR:UpdateRayEndCoords() + if ( RADAR:IsFastLimitAllowed() ) then + RADAR:CreateFastLimitConfig() + end + while ( true ) do RADAR:Main() diff --git a/config.lua b/config.lua index 7343798..db7149d 100644 --- a/config.lua +++ b/config.lua @@ -24,7 +24,7 @@ RADAR.config.rear_lock_key = 112 -- Radar fast limit locking -- When enabled, the player will be able to define a fast limit within the radar's menu, when a vehicle -- exceeds the fast limit, it will be locked into the fast box. Default setting is disabled to maintain realism -RADAR.config.allow_fast_limit = false +RADAR.config.allow_fast_limit = true -- Fast Lock Blip -- true = vehicles that go over the fast limit will have a blip added to the minimap for a short period of time diff --git a/docs/version.txt b/docs/version.txt index 62d3a3b..f741c92 100644 --- a/docs/version.txt +++ b/docs/version.txt @@ -1 +1 @@ -beta2b \ No newline at end of file +beta2c \ No newline at end of file