diff --git a/cl_radar.lua b/cl_radar.lua index 81fcc5e..a4b1eae 100644 --- a/cl_radar.lua +++ b/cl_radar.lua @@ -58,7 +58,7 @@ RADAR.vars = -- Variables for the front antenna [ "front" ] = { xmit = false, -- Whether the antenna is on or off - mode = 1, -- Current antenna mode, 1 = same, 2 = opp, 3 = same and opp + mode = 0, -- Current antenna mode, 0 = none, 1 = same, 2 = opp, 3 = same and opp speed = 0, -- Speed of the vehicle caught by the front antenna dir = nil, -- Direction the caught vehicle is going, 0 = towards, 1 = away fastMode = 1, -- Current fast mode, 1 = polling, 2 = lock on at first fast vehicle @@ -69,7 +69,7 @@ RADAR.vars = [ "rear" ] = { xmit = false, -- Whether the antenna is on or off - mode = 1, -- Current antenna mode, 1 = same, 2 = opp, 3 = same and opp + mode = 0, -- Current antenna mode, 0 = none, 1 = same, 2 = opp, 3 = same and opp speed = 0, -- Speed of the vehicle caught by the front antenna dir = nil, -- Direction the caught vehicle is going, 0 = towards, 1 = away fastMode = 1, -- Current fast mode, 1 = polling, 2 = lock on at first fast vehicle @@ -367,7 +367,9 @@ end Radar antenna functions ------------------------------------------------------------------------]]-- function RADAR:ToggleAntenna( ant ) - self.vars.antennas[ant].xmit = not self.vars.antennas[ant].xmit + if ( self:IsPowerOn() ) then + self.vars.antennas[ant].xmit = not self.vars.antennas[ant].xmit + end end function RADAR:IsAntennaTransmitting( ant ) @@ -441,36 +443,6 @@ function RADAR:SetAntennaFastLock( ant, state ) end ---[[------------------------------------------------------------------------ - Radar sort mode functions -------------------------------------------------------------------------]]-- ---[[ function RADAR:GetSortModeText() - return self.sorting[self.vars.sortMode].name -end - -function RADAR:GetSortModeFunc() - return self.sorting[self.vars.sortMode].func -end - -function RADAR:IsSortModeFastest() - if ( self.vars.sortMode == 2 ) then - return true - end - - return false -end - -function RADAR:ToggleSortMode() - if ( self.vars.sortMode < #self.sorting ) then - self.vars.sortMode = self.vars.sortMode + 1 - else - self.vars.sortMode = 1 - end - - UTIL:Notify( "Radar mode set to " .. self:GetSortModeText() ) -end ]] - - --[[------------------------------------------------------------------------ Radar captured vehicle functions ------------------------------------------------------------------------]]-- @@ -491,7 +463,7 @@ function RADAR:InsertCapturedVehicleData( t, rt ) end end -function RADAR:RemoveDuplicateCapturedVehicles() +--[[ function RADAR:RemoveDuplicateCapturedVehicles() for k, vehTable in pairs( self.capturedVehicles ) do local veh = vehTable.veh local rt = vehTable.rayType @@ -500,7 +472,7 @@ function RADAR:RemoveDuplicateCapturedVehicles() if ( v.veh == veh and k ~= b and rt == v.rayType ) then table.remove( self.capturedVehicles, b ) end end end -end +end ]] --[[------------------------------------------------------------------------ @@ -651,11 +623,6 @@ function RADAR:RunControlManager() SetNuiFocus( true, true ) end - -- 'X' key, change the sort mode - --[[ if ( IsDisabledControlJustPressed( 1, 105 ) ) then - self:ToggleSortMode() - end ]] - if ( IsDisabledControlJustPressed( 1, 117 ) ) then self:TogglePower() UTIL:Notify( "Radar power toggled." ) @@ -683,10 +650,14 @@ end --[[------------------------------------------------------------------------ NUI callback ------------------------------------------------------------------------]]-- -RegisterNUICallback( "remote", function( data, cb ) - if ( data == "close" ) then - SetNuiFocus( false, false ) - end +RegisterNUICallback( "closeRemote", function( data ) + SetNuiFocus( false, false ) +end ) + +RegisterNUICallback( "setAntennaMode", function( data ) + RADAR:SetAntennaMode( data.value, tostring( data.mode ) ) + + print( "Set antenna: " .. data.value .. " to mode " .. tostring( data.mode ) ) end ) @@ -701,11 +672,11 @@ function RADAR:Main() local plyVeh = GetVehiclePedIsIn( ped, false ) -- Check to make sure the player is in the driver's seat, and also that the vehicle has a class of VC_EMERGENCY (18) - if ( DoesEntityExist( plyVeh ) and GetPedInVehicleSeat( plyVeh, -1 ) == ped and GetVehicleClass( plyVeh ) == 18 and ( self:IsPowerOn() and self:IsEitherAntennaOn() ) ) then + if ( DoesEntityExist( plyVeh ) and GetPedInVehicleSeat( plyVeh, -1 ) == ped and GetVehicleClass( plyVeh ) == 18 and self:IsPowerOn() ) then local plyVehPos = GetEntityCoords( plyVeh ) -- First stage of the radar - get all of the vehicles hit by the radar - if ( self:GetRadarStage() == 0 ) then + if ( self:GetRadarStage() == 0 --[[ and self:IsEitherAntennaOn() ]] ) then if ( self:GetRayTraceState() == 0 ) then local vehs = self:GetVehiclePool() @@ -717,41 +688,14 @@ function RADAR:Main() end elseif ( self:GetRadarStage() == 1 ) then -- self:RemoveDuplicateCapturedVehicles() - + + -- Only grab data to send if there have actually been vehicles captured by the radar if ( not UTIL:IsTableEmpty( self:GetCapturedVehicles() ) ) then local vehsForDisplay = self:GetVehiclesForAntenna() - self:SetActiveVehicles( vehsForDisplay ) - - if ( vehsForDisplay[1] ~= nil ) then - local test = UTIL:FormatSpeed( UTIL:Round( self:GetVehSpeedFormatted( vehsForDisplay[1].speed ), 0 ) ) - SendNUIMessage( { test1 = test } ) - elseif ( vehsForDisplay[1] == nil ) then - SendNUIMessage( { test1 = -1 } ) - end - - if ( vehsForDisplay[2] ~= nil ) then - local test = UTIL:FormatSpeed( UTIL:Round( self:GetVehSpeedFormatted( vehsForDisplay[2].speed ), 0 ) ) - SendNUIMessage( { test2 = test } ) - elseif ( vehsForDisplay[2] == nil ) then - SendNUIMessage( { test2 = -1 } ) - end - - if ( vehsForDisplay[3] ~= nil ) then - local test = UTIL:FormatSpeed( UTIL:Round( self:GetVehSpeedFormatted( vehsForDisplay[3].speed ), 0 ) ) - SendNUIMessage( { test3 = test } ) - elseif ( vehsForDisplay[3] == nil ) then - SendNUIMessage( { test3 = -1 } ) - end - - if ( vehsForDisplay[4] ~= nil ) then - local test = UTIL:FormatSpeed( UTIL:Round( self:GetVehSpeedFormatted( vehsForDisplay[4].speed ), 0 ) ) - SendNUIMessage( { test4 = test } ) - elseif ( vehsForDisplay[4] == nil ) then - SendNUIMessage( { test4 = -1 } ) - end + -- self:SetActiveVehicles( vehsForDisplay ) -- not really any point in setting this else - self:SetActiveVehicles( { nil, nil, nil, nil } ) + -- self:SetActiveVehicles( { nil, nil, nil, nil } ) end self:ResetRadarStage() @@ -778,7 +722,7 @@ Citizen.CreateThread( function() while ( true ) do RADAR:Main() - Citizen.Wait( 50 ) + Citizen.Wait( 100 ) end end ) diff --git a/nui/radar.html b/nui/radar.html index 4020d64..50f43ea 100644 --- a/nui/radar.html +++ b/nui/radar.html @@ -113,14 +113,13 @@
-

FRONT ANTENNA

- +
@@ -129,7 +128,7 @@
- +
diff --git a/nui/radar.js b/nui/radar.js index 5688346..53aa03d 100644 --- a/nui/radar.js +++ b/nui/radar.js @@ -88,6 +88,13 @@ const remoteButtons = } } +const antennaModes = +{ + same: 0, + opp: 1, + both: 2 +} + // Hide the radar and remote, this way we can bypass setting a style of 'display: none;' in the HTML file elements.radar.hide(); elements.remote.hide(); @@ -97,6 +104,13 @@ remoteButtons.toggleDisplay.click( function() { elements.radar.fadeToggle(); } ) +function toggleRemote() +{ + elements.remote.toggle(); +} + +// function toggleLabel( ) + // This function is used to send data back through to the LUA side function sendData( name, data ) { $.post( "http://" + resourceName + "/" + name, JSON.stringify( data ), function( datab ) { @@ -106,15 +120,33 @@ function sendData( name, data ) { } ); } +// This runs when the JS file is loaded, loops through all of the remote buttons and assigns them an onclick function +function remoteInit() +{ + elements.remote.find( "button" ).each( function( i, obj ) { + if ( $( this ).attr( "data-action" ) && $( this ).attr( "data-value" ) ) { + $( this ).click( function() { + let action = $( this ).data( "action" ); + let value = $( this ).data( "value" ); + let mode = $( this ).data( "mode" ); + + sendData( action, { value, mode } ); + } ) + } + } ); +} + // Close the remote when the user presses the 'Escape' key document.onkeyup = function ( event ) { if ( event.keyCode == 27 ) { - sendData( "remote", "close" ); - $( "#rc" ).toggle(); + sendData( "closeRemote", null ); + toggleRemote(); } } +remoteInit(); + // The main event listener, this is what the NUI messages sent by the LUA side arrive at, they are // then handled properly via a switch/case that runs the relevant code window.addEventListener( "message", function( event ) { @@ -123,24 +155,6 @@ window.addEventListener( "message", function( event ) { if ( item.pathName ) { resourceName = item.pathName; } else if ( item.activateRemote ) { - $( "#rc" ).toggle(); - } else if ( item.test1 ) { - elements.antennas.front.targetSpeed.html( item.test1 ); - } else if ( item.test2 ) { - elements.antennas.front.fast.speed.html( item.test2 ); - } else if ( item.test3 ) { - elements.antennas.rear.targetSpeed.html( item.test3 ); - } else if ( item.test4 ) { - elements.antennas.rear.fast.speed.html( item.test4 ); - } - - if ( item.test1 == -1 ) { - elements.antennas.front.targetSpeed.html( "¦¦¦" ); - } else if ( item.test2 == -1 ) { - elements.antennas.front.fast.speed.html( "¦¦¦" ); - } else if ( item.test3 == -1 ) { - elements.antennas.rear.targetSpeed.html( "¦¦¦" ); - } else if ( item.test4 == -1 ) { - elements.antennas.rear.fast.speed.html( "¦¦¦" ); - } + toggleRemote(); + } } ); \ No newline at end of file