feat: only allow one player to have the remote open

This commit is contained in:
Dan
2021-03-14 14:24:15 +00:00
parent 469166b2ca
commit cde5bef492
2 changed files with 33 additions and 10 deletions

View File

@@ -156,6 +156,8 @@ AddEventHandler( "onResourceStart", function( resourceName )
RegisterKeyBinds()
LoadUISettings()
DecorSetBool( PlayerPedId(), "wk_wars2x_sync_remoteOpen", false )
end )
end
end )
@@ -626,9 +628,16 @@ end
-- passenger can also open the remote, we check the config variable as well.
function RADAR:OpenRemote()
if ( not IsPauseMenuActive() and PLY:CanViewRadar() ) then
-- Get the remote open state from the other player
local openByOtherPly = SYNC:IsRemoteAlreadyOpen( PLY:GetOtherPed() )
-- Check that the remote can be opened
if ( not openByOtherPly ) then
-- Tell the NUI side to open the remote
SendNUIMessage( { _type = "openRemote" } )
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" )
@@ -640,6 +649,9 @@ function RADAR:OpenRemote()
-- 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 )

View File

@@ -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.