mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 14:01:26 +00:00
feat - ESX.RegisterInput
This commit is contained in:
@@ -5,7 +5,7 @@ ESX.PlayerLoaded = false
|
||||
Core.CurrentRequestId = 0
|
||||
Core.ServerCallbacks = {}
|
||||
Core.TimeoutCallbacks = {}
|
||||
|
||||
ESX.Input = {}
|
||||
ESX.UI = {}
|
||||
ESX.UI.HUD = {}
|
||||
ESX.UI.HUD.RegisteredElements = {}
|
||||
@@ -136,6 +136,27 @@ function ESX.ShowFloatingHelpNotification(msg, coords)
|
||||
EndTextCommandDisplayHelp(2, false, false, -1)
|
||||
end
|
||||
|
||||
ESX.HashString = function(str)
|
||||
local format = string.format
|
||||
local upper = string.upper
|
||||
local gsub = string.gsub
|
||||
local hash = GetHashKey(str)
|
||||
local input_map = format("~INPUT_%s~", upper(format("%x", hash)))
|
||||
input_map = string.gsub(input_map, "FFFFFFFF", "")
|
||||
|
||||
return input_map
|
||||
end
|
||||
|
||||
|
||||
ESX.RegisterInput = function(command_name, label, input_group, key, on_press, on_release)
|
||||
RegisterCommand(on_release ~= nil and "+" .. command_name or command_name, on_press)
|
||||
ESX.Input[command_name] = on_release ~= nil and ESX.HashString("+" .. command_name) or ESX.HashString(command_name)
|
||||
if on_release then
|
||||
RegisterCommand("-" .. command_name, on_release)
|
||||
end
|
||||
RegisterKeyMapping(on_release ~= nil and "+" .. command_name or command_name, label, input_group, key)
|
||||
end
|
||||
|
||||
function ESX.TriggerServerCallback(name, cb, ...)
|
||||
Core.ServerCallbacks[Core.CurrentRequestId] = cb
|
||||
|
||||
|
||||
Reference in New Issue
Block a user