fix: power button spam breaking display

This commit is contained in:
Dan
2021-02-24 15:16:30 +00:00
parent 912b0f72d7
commit 21fde3468e

View File

@@ -379,33 +379,36 @@ end
-- Toggles the radar power -- Toggles the radar power
function RADAR:TogglePower() function RADAR:TogglePower()
-- Toggle the power variable -- Only power up if the system is not already powering up
self.vars.power = not self.vars.power if ( not self:IsPoweringUp() ) then
-- Toggle the power variable
-- Send the NUI message to toggle the power self.vars.power = not self.vars.power
SendNUIMessage( { _type = "radarPower", state = self:IsPowerOn() } )
-- Power is now turned on
if ( self:IsPowerOn() ) then
-- Also make sure the operator menu is inactive
self:SetMenuState( false )
-- Tell the system the radar is 'powering up' -- Send the NUI message to toggle the power
self:SetPoweringUpState( true ) SendNUIMessage( { _type = "radarPower", state = self:IsPowerOn() } )
-- Set a 2 second countdown -- Power is now turned on
Citizen.SetTimeout( 2000, function() if ( self:IsPowerOn() ) then
-- Tell the system the radar has 'powered up' -- Also make sure the operator menu is inactive
self:SetPoweringUpState( false ) self:SetMenuState( false )
-- Tell the system the radar is 'powering up'
self:SetPoweringUpState( true )
-- Let the UI side know the system has loaded -- Set a 2 second countdown
SendNUIMessage( { _type = "poweredUp" } ) Citizen.SetTimeout( 2000, function()
end ) -- Tell the system the radar has 'powered up'
else self:SetPoweringUpState( false )
-- If the system is being turned off, then we reset the antennas
self:ResetAntenna( "front" ) -- Let the UI side know the system has loaded
self:ResetAntenna( "rear" ) SendNUIMessage( { _type = "poweredUp" } )
end end )
else
-- If the system is being turned off, then we reset the antennas
self:ResetAntenna( "front" )
self:ResetAntenna( "rear" )
end
end
end end
-- Toggles the display state of the radar system -- Toggles the display state of the radar system