Skip to content

Commit ce023f1

Browse files
committed
💥 feat(decorator): add decorator to be alias of some functions like @onnet = RegisterNetEvent (must use require by our)
shared_script '@es_extended/shared/require.lua'
1 parent 5ec7ab0 commit ce023f1

File tree

16 files changed

+362
-60
lines changed

16 files changed

+362
-60
lines changed

‎client/functions/init.lua‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ require('client.functions.services.notifications')
1818
require('client.functions.services.ui')
1919
require('client.functions.services.games')
2020

21-
RegisterNetEvent('esx:showNotification', ESX.ShowNotification)
21+
@onNet('esx:showNotification', ESX.ShowNotification)
2222

23-
RegisterNetEvent('esx:showAdvancedNotification', ESX.ShowAdvancedNotification)
23+
@onNet('esx:showAdvancedNotification', ESX.ShowAdvancedNotification)
2424

25-
RegisterNetEvent('esx:showHelpNotification', ESX.ShowHelpNotification)
25+
@onNet('esx:showHelpNotification', ESX.ShowHelpNotification)
2626

27-
AddEventHandler('onResourceStop', function(resourceName)
27+
@onStop(function(resourceName)
2828
for i = 1, #ESX.UI.Menu.Opened, 1 do
2929
if ESX.UI.Menu.Opened[i] then
3030
if ESX.UI.Menu.Opened[i].resourceName == resourceName or ESX.UI.Menu.Opened[i].namespace == resourceName then

‎client/functions/services/games/init.lua‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Core.EnumerateEntitiesWithinDistance = function(entities, isPlayerEntities, coor
3737
return nearbyEntities
3838
end
3939

40-
require('client.functions.services.game.players-peds')
41-
require('client.functions.services.game.utils')
42-
require('client.functions.services.game.objects')
43-
require('client.functions.services.game.vehicles')
44-
require('client.functions.services.game.raycast')
40+
require('client.functions.services.games.players-peds')
41+
require('client.functions.services.games.utils')
42+
require('client.functions.services.games.objects')
43+
require('client.functions.services.games.vehicles')
44+
require('client.functions.services.games.raycast')

‎client/functions/services/ui/init.lua‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
---@param str string The string to hash
2+
---@return string The hashed string
3+
function ESX.HashString(str)
4+
return ('~INPUT_%s~'):format(('%x'):format(joaat(str) & 0x7fffffff + 2 ^ 31):upper())
5+
end
6+
7+
---@param command_name string The command name
8+
---@param label string The label to show
9+
---@param input_group string The input group
10+
---@param key string The key to bind
11+
---@param on_press function The function to call on press
12+
---@param on_release? function The function to call on release
13+
function ESX.RegisterInput(command_name, label, input_group, key, on_press, on_release)
14+
local command = on_release and '+' .. command_name or command_name
15+
RegisterCommand(command, on_press, false)
16+
Core.Input[command_name] = ESX.HashString(command)
17+
if on_release then
18+
RegisterCommand('-' .. command_name, on_release, false)
19+
end
20+
RegisterKeyMapping(command, label or '', input_group or 'keyboard', key or '')
21+
end
22+
123
---@param menuType string
224
---@param open function The function to call on open
325
---@param close function The function to call on close

‎client/modules/adjustments/basic-actions/player_crouch.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local crouchCommand = 'player_crouch'
22
local animSet = 'move_ped_crouched'
33
local crouched = false
44

5-
RegisterCommand(crouchCommand, function()
5+
@command(crouchCommand, function()
66
local isDead = LocalPlayer.state.isDead or false
77

88
if not isDead then

‎client/modules/adjustments/basic-actions/player_finger_pointing.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ local function stopPointing()
4141
RemoveAnimDict(anim.dict)
4242
end
4343

44-
RegisterCommand(pointingCommand, function()
44+
@command(pointingCommand, function()
4545
local ped = cache.ped
4646

4747
if not IsPedInAnyVehicle(ped, true) and not LocalPlayer.state.isDead then

‎client/modules/adjustments/basic-actions/player_handsup.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local anim = {
55
name = 'handsup_enter',
66
}
77

8-
RegisterCommand(handsupCommand, function()
8+
@command(handsupCommand, function()
99
local ped = cache.ped
1010
local notInVehicle = cache.vehicle == false or cache.vehicle == nil
1111

‎client/modules/adjustments/basic-actions/player_slide.lua‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ return function(cooldown)
99
exitName = 'exit',
1010
}
1111

12-
RegisterCommand('+press_shift', function()
12+
@command('+press_shift', function()
1313
pressShift = true
1414
end, false)
1515

16-
RegisterCommand('-press_shift', function()
16+
@command('-press_shift', function()
1717
pressShift = false
1818
end, false)
1919

2020
RegisterKeyMapping('+press_shift', '(Don\'t change) Press Shift', 'keyboard', 'LSHIFT')
2121

22-
RegisterCommand(slideCommand, function()
22+
@command(slideCommand, function()
2323
local isDead = LocalPlayer.state.isDead or false
2424

2525
if canSlide and not isDead and pressShift then

‎client/modules/adjustments/init.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ end
227227

228228
function M:DisableRadio()
229229
if adjustment.remove_hud_components[16] then
230-
AddEventHandler('esx:enteredVehicle', function(vehicle)
230+
@on('esx:enteredVehicle', function(vehicle)
231231
SetVehRadioStation(vehicle, 'OFF')
232232
SetUserRadioControlEnabled(false)
233233
end)

‎client/modules/death/init.lua‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function M:Died()
7979
end
8080

8181
function M:Load()
82-
AddEventHandler('esx:onPlayerSpawn', function()
82+
@on('esx:onPlayerSpawn', function()
8383
LocalPlayer.state:set('isDead', false, true)
8484

8585
Citizen.CreateThreadNow(function()
@@ -97,7 +97,7 @@ function M:Load()
9797
end)
9898
end)
9999

100-
AddEventHandler('esx:onPlayerDeath', function()
100+
@on('esx:onPlayerDeath', function()
101101
LocalPlayer.state:set('isDead', true, true)
102102
end)
103103
end

‎client/modules/init.lua‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ local M = {
2020

2121
local registerCallback = lib.callback.register
2222

23-
RegisterNetEvent('esx:requestModel', function(model)
23+
@onNet('esx:requestModel', function(model)
2424
ESX.Streaming.RequestModel(model)
2525
end)
2626

@@ -34,7 +34,7 @@ end
3434

3535
local hybridType = public.hybrid_data
3636

37-
RegisterNetEvent('esx:playerLoaded', function(xPlayer, isNew)
37+
@onNet('esx:playerLoaded', function(xPlayer, isNew)
3838
local tries = 0
3939
repeat
4040
Core.Items = lib.loadJson('db.items')
@@ -157,7 +157,7 @@ RegisterNetEvent('esx:playerLoaded', function(xPlayer, isNew)
157157
lib.print.info('Player has initialized')
158158
end)
159159

160-
RegisterNetEvent('esx:setInventory', function(_newInventory)
160+
@onNet('esx:setInventory', function(_newInventory)
161161
local newInventory = {}
162162

163163
for index, item in ipairs(_newInventory) do
@@ -178,21 +178,21 @@ local function onPlayerSpawn()
178178
ESX.SetPlayerData('dead', false)
179179
end
180180

181-
AddEventHandler('playerSpawned', onPlayerSpawn)
182-
AddEventHandler('esx:onPlayerSpawn', onPlayerSpawn)
181+
@on('playerSpawned', onPlayerSpawn)
182+
@on('esx:onPlayerSpawn', onPlayerSpawn)
183183

184-
AddEventHandler('esx:onPlayerDeath', function()
184+
@on('esx:onPlayerDeath', function()
185185
ESX.SetPlayerData('dead', true)
186186
end)
187187

188-
AddEventHandler('skinchanger:modelLoaded', function()
188+
@on('skinchanger:modelLoaded', function()
189189
while not ESX.PlayerLoaded do
190190
Wait(100)
191191
end
192192
TriggerEvent('esx:restoreLoadout')
193193
end)
194194

195-
AddEventHandler('esx:restoreLoadout', function()
195+
@on('esx:restoreLoadout', function()
196196
local ammoTypes = {}
197197
RemoveAllPedWeapons(cache.ped, true)
198198

@@ -249,7 +249,7 @@ AddStateBagChangeHandler('VehicleProperties', nil, function(bagName, _, value)
249249
ESX.Game.SetVehicleProperties(vehicle, value)
250250
end)
251251

252-
RegisterNetEvent('esx:setAccountMoney', function(account)
252+
@onNet('esx:setAccountMoney', function(account)
253253
local retval = true
254254
if hybridType == true or hybridType == 'hash' then
255255
retval = pcall(function()
@@ -274,23 +274,23 @@ RegisterNetEvent('esx:setAccountMoney', function(account)
274274
ESX.SetPlayerData('accounts', ESX.PlayerData.accounts)
275275
end)
276276

277-
RegisterNetEvent('esx:setJob', function(job)
277+
@onNet('esx:setJob', function(job)
278278
ESX.SetPlayerData('job', job)
279279
end)
280280

281-
RegisterNetEvent('esx:setGroup', function(group)
281+
@onNet('esx:setGroup', function(group)
282282
ESX.SetPlayerData('group', group)
283283
end)
284284

285-
RegisterNetEvent('esx:registerSuggestions', function(registeredCommands)
285+
@onNet('esx:registerSuggestions', function(registeredCommands)
286286
for name, command in pairs(registeredCommands) do
287287
if command.suggestion then
288288
TriggerEvent('chat:addSuggestion', ('/%s'):format(name), command.suggestion.help, command.suggestion.arguments)
289289
end
290290
end
291291
end)
292292

293-
RegisterNetEvent('esx:addInventoryItem', function(item, count)
293+
@onNet('esx:addInventoryItem', function(item, count)
294294
local retval = true
295295

296296
if hybridType == true or hybridType == 'hash' then
@@ -313,7 +313,7 @@ RegisterNetEvent('esx:addInventoryItem', function(item, count)
313313
end
314314
end)
315315

316-
RegisterNetEvent('esx:removeInventoryItem', function(item, count)
316+
@onNet('esx:removeInventoryItem', function(item, count)
317317
local retval = true
318318

319319
if hybridType == true or hybridType == 'hash' then
@@ -336,7 +336,7 @@ RegisterNetEvent('esx:removeInventoryItem', function(item, count)
336336
end
337337
end)
338338

339-
RegisterNetEvent('esx:addLoadoutItem', function(weaponName, weaponLabel, ammo)
339+
@onNet('esx:addLoadoutItem', function(weaponName, weaponLabel, ammo)
340340
local data = {
341341
name = weaponName,
342342
ammo = ammo,
@@ -369,7 +369,7 @@ RegisterNetEvent('esx:addLoadoutItem', function(weaponName, weaponLabel, ammo)
369369
ESX.SetPlayerData('loadout', ESX.PlayerData.loadout)
370370
end)
371371

372-
RegisterNetEvent('esx:removeLoadoutItem', function(weaponName, weaponLabel)
372+
@onNet('esx:removeLoadoutItem', function(weaponName, weaponLabel)
373373
local retval = true
374374

375375
if hybridType == true or hybridType == 'hash' then
@@ -399,16 +399,16 @@ registerCallback('esx:getVehicleType', function(model)
399399
return ESX.GetVehicleTypeClient(model)
400400
end)
401401

402-
RegisterNetEvent('esx:updatePlayerData', function(key, val)
402+
@onNet('esx:updatePlayerData', function(key, val)
403403
ESX.SetPlayerData(key, val)
404404
end)
405405

406406
---@param command string
407-
RegisterNetEvent('esx:executeCommand', function(command)
407+
@onNet('esx:executeCommand', function(command)
408408
ExecuteCommand(command)
409409
end)
410410

411-
AddEventHandler('onResourceStop', function(resource)
411+
@on('onResourceStop', function(resource)
412412
if Core.Events[resource] then
413413
for i = 1, #Core.Events[resource] do
414414
RemoveEventHandler(Core.Events[resource][i])

0 commit comments

Comments
 (0)