Skip to content

Commit 58728dd

Browse files
committed
refactor(player-stats): improve code structure in ESX
1 parent da1a94f commit 58728dd

File tree

1 file changed

+16
-41
lines changed

1 file changed

+16
-41
lines changed

[core]/es_extended/client/modules/adjustments.lua

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -236,49 +236,41 @@ function Adjustments:Multipliers()
236236
end
237237

238238
function Adjustments:ApplyPlayerStats()
239-
if not Config.PlayerStatsByGender.enabled then return end
239+
if not Config.PlayerStatsByGender.enabled then return end
240240

241-
if Config.PlayerStatsByGender.debugMode then
241+
if Config.EnableDebug then
242242
print('[^3adjustments^7] applying player stats...')
243243
end
244244

245245
local gender = self:GetPlayerGender()
246246
if not gender then
247-
if Config.PlayerStatsByGender.debugMode then
247+
if Config.EnableDebug then
248248
print('[^1adjustments^7] failed to detect gender')
249249
end
250250
return
251251
end
252252

253253
local stats = Config.PlayerStatsByGender[gender]
254254
if not stats then
255-
if Config.PlayerStatsByGender.debugMode then
255+
if Config.EnableDebug then
256256
print('[^1adjustments^7] no stats found for gender: ' .. gender)
257257
end
258258
return
259259
end
260260

261261
if stats.stamina then
262262
SetRunSprintMultiplierForPlayer(ESX.playerId, stats.stamina)
263-
if Config.PlayerStatsByGender.debugMode then
264-
print('[^2adjustments^7] stamina: ' .. tostring(stats.stamina))
265-
end
266263
end
267264

268265
if stats.strength then
269266
SetPlayerMeleeWeaponDamageModifier(ESX.playerId, stats.strength)
270-
if Config.PlayerStatsByGender.debugMode then
271-
print('[^2adjustments^7] strength: ' .. tostring(stats.strength))
272-
end
273267
end
274268

275269
if stats.swimSpeed then
276270
SetSwimMultiplierForPlayer(ESX.playerId, stats.swimSpeed)
277-
if Config.PlayerStatsByGender.debugMode then
278-
print('[^2adjustments^7] swimSpeed: ' .. tostring(stats.swimSpeed))
279-
end
280271
end
281272

273+
-- moveSpeed requires continuous loop
282274
if stats.moveSpeed then
283275
self.currentMoveSpeed = stats.moveSpeed
284276
if not self.moveSpeedThreadRunning then
@@ -293,9 +285,6 @@ function Adjustments:ApplyPlayerStats()
293285
self.moveSpeedThreadRunning = false
294286
end)
295287
end
296-
if Config.PlayerStatsByGender.debugMode then
297-
print('[^2adjustments^7] moveSpeed: ' .. tostring(stats.moveSpeed))
298-
end
299288
end
300289

301290
-- ADD NEW STATS HERE
@@ -310,33 +299,35 @@ function Adjustments:ApplyPlayerStats()
310299

311300
-- if stats.statName then
312301
-- YourNative(ESX.playerId, stats.statName)
313-
-- if Config.PlayerStatsByGender.debugMode then
302+
-- if Config.EnableDebug then
314303
-- print('[^2adjustments^7] statName: ' .. tostring(stats.statName))
315304
-- end
316305
-- end
317306

318-
if Config.PlayerStatsByGender.debugMode then
307+
if Config.EnableDebug then
319308
print('[^2adjustments^7] stats applied for gender: ' .. gender)
320309
end
321310
end
322311

323312
function Adjustments:GetPlayerGender()
324313
if not ESX.PlayerLoaded then
325-
if Config.PlayerStatsByGender.debugMode then
314+
if Config.EnableDebug then
326315
print('[^1adjustments^7] player not loaded yet')
327316
end
328317
return
329318
end
330319

331-
if Config.PlayerStatsByGender.debugMode then
320+
if Config.EnableDebug then
332321
print('[^3adjustments^7] detecting gender using: ' .. (Config.PlayerStatsByGender.useCharacterData and 'character data' or 'ped model'))
333322
end
334323

335324
if Config.PlayerStatsByGender.useCharacterData then
325+
-- Option 1: character data
336326
if ESX.PlayerData.sex then
337327
return ESX.PlayerData.sex == 'm' and 'male' or 'female'
338328
end
339329
else
330+
-- Option 2: ped model
340331
local model = GetEntityModel(ESX.PlayerData.ped)
341332

342333
for i = 1, #Config.PlayerStatsByGender.malePeds do
@@ -351,6 +342,7 @@ function Adjustments:GetPlayerGender()
351342
end
352343
end
353344

345+
-- Native fallback
354346
if IsPedMale(ESX.PlayerData.ped) then
355347
return 'male'
356348
else
@@ -361,11 +353,6 @@ function Adjustments:GetPlayerGender()
361353
return nil
362354
end
363355

364-
365-
function Adjustments:RefreshPlayerStats()
366-
self:ApplyPlayerStats()
367-
end
368-
369356
function Adjustments:Load()
370357
self:RemoveHudComponents()
371358
self:DisableAimAssist()
@@ -383,32 +370,20 @@ function Adjustments:Load()
383370
self:Multipliers()
384371

385372
AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
386-
if Config.PlayerStatsByGender.debugMode then
387-
print('[^3adjustments^7] esx:playerloaded event triggered')
388-
end
389373
self:ApplyPlayerStats()
390374
end)
391375

392376
if not Config.PlayerStatsByGender.useCharacterData then
393377
AddEventHandler('skinchanger:modelLoaded', function()
394-
if Config.PlayerStatsByGender.debugMode then
395-
print('[^3adjustments^7] skinchanger:modelloaded event triggered')
396-
end
397-
self:RefreshPlayerStats()
378+
self:ApplyPlayerStats()
398379
end)
399-
else
400-
if Config.PlayerStatsByGender.debugMode then
401-
print('[^3adjustments^7] skinchanger event not registered (using character data)')
402-
end
403380
end
404381

405382
AddEventHandler('esx:onPlayerSpawn', function()
406-
if Config.PlayerStatsByGender.debugMode then
407-
print('[^3adjustments^7] esx:onplayerspawn event triggered')
408-
end
409-
self:RefreshPlayerStats()
383+
self:ApplyPlayerStats()
410384
end)
411-
if Config.PlayerStatsByGender.enabled and Config.PlayerStatsByGender.debugMode then
385+
386+
if Config.PlayerStatsByGender.enabled and Config.EnableDebug then
412387
print('[^2adjustments^7] player stats by gender loaded')
413388
print('[^3adjustments^7] enabled: ' .. tostring(Config.PlayerStatsByGender.enabled))
414389
print('[^3adjustments^7] use character data: ' .. tostring(Config.PlayerStatsByGender.useCharacterData))

0 commit comments

Comments
 (0)