From cde5bef492e1cda4754f543ccf2b04217c013771 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 14 Mar 2021 14:24:15 +0000 Subject: [PATCH] feat: only allow one player to have the remote open --- cl_radar.lua | 33 +++++++++++++++++++++++---------- cl_sync.lua | 10 ++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cl_radar.lua b/cl_radar.lua index 6d7998e..ae44d1f 100644 --- a/cl_radar.lua +++ b/cl_radar.lua @@ -156,6 +156,8 @@ AddEventHandler( "onResourceStart", function( resourceName ) RegisterKeyBinds() LoadUISettings() + + DecorSetBool( PlayerPedId(), "wk_wars2x_sync_remoteOpen", false ) end ) end end ) @@ -626,20 +628,30 @@ end -- passenger can also open the remote, we check the config variable as well. function RADAR:OpenRemote() if ( not IsPauseMenuActive() and PLY:CanViewRadar() ) then - -- Tell the NUI side to open the remote - SendNUIMessage( { _type = "openRemote" } ) + -- Get the remote open state from the other player + local openByOtherPly = SYNC:IsRemoteAlreadyOpen( PLY:GetOtherPed() ) - if ( CONFIG.allow_quick_start_video ) then - -- Display the new user popup if we can - local show = GetResourceKvpInt( "wk_wars2x_new_user" ) + -- Check that the remote can be opened + if ( not openByOtherPly ) then + -- Tell the NUI side to open the remote + SendNUIMessage( { _type = "openRemote" } ) - if ( show == 0 ) then - SendNUIMessage( { _type = "showNewUser" } ) + SYNC:SetRemoteOpenState( true ) + + if ( CONFIG.allow_quick_start_video ) then + -- Display the new user popup if we can + local show = GetResourceKvpInt( "wk_wars2x_new_user" ) + + if ( show == 0 ) then + SendNUIMessage( { _type = "showNewUser" } ) + end end - end - -- Bring focus to the NUI side - SetNuiFocus( true, true ) + -- Bring focus to the NUI side + SetNuiFocus( true, true ) + else + UTIL:Notify( "Another player already has the remote open." ) + end end end @@ -1705,6 +1717,7 @@ end ) RegisterNUICallback( "closeRemote", function( data, cb ) -- Remove focus to the NUI side SetNuiFocus( false, false ) + SYNC:SetRemoteOpenState( false ) cb( "ok" ) end ) diff --git a/cl_sync.lua b/cl_sync.lua index d2384a2..f8d24a4 100644 --- a/cl_sync.lua +++ b/cl_sync.lua @@ -30,6 +30,8 @@ ---------------------------------------------------------------------------------------]]-- +DecorRegister( "wk_wars2x_sync_remoteOpen", 2 ) + --[[---------------------------------------------------------------------------------- Sync variables ----------------------------------------------------------------------------------]]-- @@ -39,6 +41,14 @@ SYNC = {} --[[---------------------------------------------------------------------------------- Sync functions ----------------------------------------------------------------------------------]]-- +function SYNC:IsRemoteAlreadyOpen( ply ) + return DecorGetBool( ply, "wk_wars2x_sync_remoteOpen" ) +end + +function SYNC:SetRemoteOpenState( state ) + DecorSetBool( PLY.ped, "wk_wars2x_sync_remoteOpen", state ) +end + -- Used to get the other ped (driver/passenger) in a vehicle and calls the given callback. This function will only work -- if the player can control the radar, it also ensures that the other ped (if found) exists and is a player. The other -- player's server ID is passed to the given callback as an argument.