Block key binds from being registered if the resource name is not wk_wars2x

This commit is contained in:
Dan
2020-11-13 19:15:04 +00:00
parent 8d40970f98
commit 93439a7df3
2 changed files with 57 additions and 47 deletions

View File

@@ -44,60 +44,64 @@ local pairs = pairs
Key bind registering Key bind registering
----------------------------------------------------------------------------------]]-- ----------------------------------------------------------------------------------]]--
local function RegisterKeyBinds() local function RegisterKeyBinds()
UTIL:Log( "Registering radar commands and key binds." ) if ( UTIL:IsResourceNameValid() ) then
UTIL:Log( "Registering radar commands and key binds." )
-- Opens the remote control -- Opens the remote control
RegisterCommand( "radar_remote", function() RegisterCommand( "radar_remote", function()
if ( not RADAR:GetKeyLockState() ) then if ( not RADAR:GetKeyLockState() ) then
RADAR:OpenRemote() RADAR:OpenRemote()
end end
end ) end )
RegisterKeyMapping( "radar_remote", "Open Remote Control", "keyboard", CONFIG.keyDefaults.remote_control ) RegisterKeyMapping( "radar_remote", "Open Remote Control", "keyboard", CONFIG.keyDefaults.remote_control )
-- Locks speed from front antenna -- Locks speed from front antenna
RegisterCommand( "radar_fr_ant", function() RegisterCommand( "radar_fr_ant", function()
if ( not RADAR:GetKeyLockState() ) then if ( not RADAR:GetKeyLockState() ) then
RADAR:LockAntennaSpeed( "front" ) RADAR:LockAntennaSpeed( "front" )
end end
end ) end )
RegisterKeyMapping( "radar_fr_ant", "Front Antenna Lock/Unlock", "keyboard", CONFIG.keyDefaults.front_lock ) RegisterKeyMapping( "radar_fr_ant", "Front Antenna Lock/Unlock", "keyboard", CONFIG.keyDefaults.front_lock )
-- Locks speed from rear antenna -- Locks speed from rear antenna
RegisterCommand( "radar_bk_ant", function() RegisterCommand( "radar_bk_ant", function()
if ( not RADAR:GetKeyLockState() ) then if ( not RADAR:GetKeyLockState() ) then
RADAR:LockAntennaSpeed( "rear" ) RADAR:LockAntennaSpeed( "rear" )
end end
end ) end )
RegisterKeyMapping( "radar_bk_ant", "Rear Antenna Lock/Unlock", "keyboard", CONFIG.keyDefaults.rear_lock ) RegisterKeyMapping( "radar_bk_ant", "Rear Antenna Lock/Unlock", "keyboard", CONFIG.keyDefaults.rear_lock )
-- Locks front plate reader -- Locks front plate reader
RegisterCommand( "radar_fr_cam", function() RegisterCommand( "radar_fr_cam", function()
if ( not RADAR:GetKeyLockState() ) then if ( not RADAR:GetKeyLockState() ) then
READER:LockCam( "front", true, false ) READER:LockCam( "front", true, false )
end end
end ) end )
RegisterKeyMapping( "radar_fr_cam", "Front Plate Reader Lock/Unlock", "keyboard", CONFIG.keyDefaults.plate_front_lock ) RegisterKeyMapping( "radar_fr_cam", "Front Plate Reader Lock/Unlock", "keyboard", CONFIG.keyDefaults.plate_front_lock )
-- Locks rear plate reader -- Locks rear plate reader
RegisterCommand( "radar_bk_cam", function() RegisterCommand( "radar_bk_cam", function()
if ( not RADAR:GetKeyLockState() ) then if ( not RADAR:GetKeyLockState() ) then
READER:LockCam( "rear", true, false ) READER:LockCam( "rear", true, false )
end end
end ) end )
RegisterKeyMapping( "radar_bk_cam", "Rear Plate Reader Lock/Unlock", "keyboard", CONFIG.keyDefaults.plate_rear_lock ) RegisterKeyMapping( "radar_bk_cam", "Rear Plate Reader Lock/Unlock", "keyboard", CONFIG.keyDefaults.plate_rear_lock )
-- Toggles the key lock state -- Toggles the key lock state
RegisterCommand( "radar_key_lock", function() RegisterCommand( "radar_key_lock", function()
RADAR:ToggleKeyLock() RADAR:ToggleKeyLock()
end ) end )
RegisterKeyMapping( "radar_key_lock", "Toggle Keybind Lock", "keyboard", CONFIG.keyDefaults.key_lock ) RegisterKeyMapping( "radar_key_lock", "Toggle Keybind Lock", "keyboard", CONFIG.keyDefaults.key_lock )
-- Deletes all of the KVPs -- Deletes all of the KVPs
RegisterCommand( "reset_radar_data", function() RegisterCommand( "reset_radar_data", function()
DeleteResourceKvp( "wk_wars2x_ui_data" ) DeleteResourceKvp( "wk_wars2x_ui_data" )
DeleteResourceKvp( "wk_wars2x_om_data" ) DeleteResourceKvp( "wk_wars2x_om_data" )
DeleteResourceKvp( "wk_wars2x_new_user" ) DeleteResourceKvp( "wk_wars2x_new_user" )
end, false ) end, false )
else
UTIL:Log( "ERROR: Resource name is not wk_wars2x. Key binds will not be registered for compatibility reasons. Contact the server owner and ask them to change the resource name back to wk_wars2x" )
end
end end

View File

@@ -31,6 +31,7 @@
---------------------------------------------------------------------------------------]]-- ---------------------------------------------------------------------------------------]]--
UTIL = {} UTIL = {}
UTIL.resourceName = ""
-- Returns a number to a set number of decimal places -- Returns a number to a set number of decimal places
function UTIL:Round( num, numDecimalPlaces ) function UTIL:Round( num, numDecimalPlaces )
@@ -136,6 +137,11 @@ function UTIL:DrawDebugText( x, y, scale, centre, text )
DrawText( x, y ) DrawText( x, y )
end end
Citizen.CreateThread( function() UTIL.resourceName = GetCurrentResourceName() end )
function UTIL:IsResourceNameValid()
return self.resourceName == "wk_wars2x"
end
--[[The MIT License (MIT) --[[The MIT License (MIT)
Copyright (c) 2017 IllidanS4 Copyright (c) 2017 IllidanS4