mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 17:28:53 +00:00
refactor: address code review feedback
This commit is contained in:
@@ -236,7 +236,11 @@ function Adjustments:Multipliers()
|
||||
end
|
||||
|
||||
function Adjustments:ApplyPlayerStats()
|
||||
if not Config.PlayerStatsByGender.enabled then return end
|
||||
if not Config.PlayerStatsByGender.enabled then return end
|
||||
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^3adjustments^7] applying player stats...')
|
||||
end
|
||||
|
||||
if Config.EnableDebug then
|
||||
print('[^3adjustments^7] applying player stats...')
|
||||
@@ -244,7 +248,7 @@ function Adjustments:ApplyPlayerStats()
|
||||
|
||||
local gender = self:GetPlayerGender()
|
||||
if not gender then
|
||||
if Config.EnableDebug then
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^1adjustments^7] failed to detect gender')
|
||||
end
|
||||
return
|
||||
@@ -252,7 +256,7 @@ function Adjustments:ApplyPlayerStats()
|
||||
|
||||
local stats = Config.PlayerStatsByGender[gender]
|
||||
if not stats then
|
||||
if Config.EnableDebug then
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^1adjustments^7] no stats found for gender: ' .. gender)
|
||||
end
|
||||
return
|
||||
@@ -260,17 +264,25 @@ function Adjustments:ApplyPlayerStats()
|
||||
|
||||
if stats.stamina then
|
||||
SetRunSprintMultiplierForPlayer(ESX.playerId, stats.stamina)
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^2adjustments^7] stamina: ' .. tostring(stats.stamina))
|
||||
end
|
||||
end
|
||||
|
||||
if stats.strength then
|
||||
SetPlayerMeleeWeaponDamageModifier(ESX.playerId, stats.strength)
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^2adjustments^7] strength: ' .. tostring(stats.strength))
|
||||
end
|
||||
end
|
||||
|
||||
if stats.swimSpeed then
|
||||
SetSwimMultiplierForPlayer(ESX.playerId, stats.swimSpeed)
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^2adjustments^7] swimSpeed: ' .. tostring(stats.swimSpeed))
|
||||
end
|
||||
end
|
||||
|
||||
-- moveSpeed requires continuous loop
|
||||
if stats.moveSpeed then
|
||||
self.currentMoveSpeed = stats.moveSpeed
|
||||
if not self.moveSpeedThreadRunning then
|
||||
@@ -294,13 +306,13 @@ end
|
||||
|
||||
function Adjustments:GetPlayerGender()
|
||||
if not ESX.PlayerLoaded then
|
||||
if Config.EnableDebug then
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^1adjustments^7] player not loaded yet')
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if Config.EnableDebug then
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^3adjustments^7] detecting gender using: ' .. (Config.PlayerStatsByGender.useCharacterData and 'character data' or 'ped model'))
|
||||
end
|
||||
|
||||
@@ -325,6 +337,12 @@ function Adjustments:GetPlayerGender()
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #Config.PlayerStatsByGender.femalePeds do
|
||||
if model == Config.PlayerStatsByGender.femalePeds[i] then
|
||||
return 'female'
|
||||
end
|
||||
end
|
||||
|
||||
-- Native fallback
|
||||
if IsPedMale(ESX.PlayerData.ped) then
|
||||
return 'male'
|
||||
@@ -336,6 +354,11 @@ function Adjustments:GetPlayerGender()
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
function Adjustments:RefreshPlayerStats()
|
||||
self:ApplyPlayerStats()
|
||||
end
|
||||
|
||||
function Adjustments:Load()
|
||||
self:RemoveHudComponents()
|
||||
self:DisableAimAssist()
|
||||
@@ -353,20 +376,32 @@ function Adjustments:Load()
|
||||
self:Multipliers()
|
||||
|
||||
AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^3adjustments^7] esx:playerloaded event triggered')
|
||||
end
|
||||
self:ApplyPlayerStats()
|
||||
end)
|
||||
|
||||
if not Config.PlayerStatsByGender.useCharacterData then
|
||||
AddEventHandler('skinchanger:modelLoaded', function()
|
||||
self:ApplyPlayerStats()
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^3adjustments^7] skinchanger:modelloaded event triggered')
|
||||
end
|
||||
self:RefreshPlayerStats()
|
||||
end)
|
||||
else
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^3adjustments^7] skinchanger event not registered (using character data)')
|
||||
end
|
||||
end
|
||||
|
||||
AddEventHandler('esx:onPlayerSpawn', function()
|
||||
self:ApplyPlayerStats()
|
||||
if Config.PlayerStatsByGender.debugMode then
|
||||
print('[^3adjustments^7] esx:onplayerspawn event triggered')
|
||||
end
|
||||
self:RefreshPlayerStats()
|
||||
end)
|
||||
|
||||
if Config.PlayerStatsByGender.enabled and Config.EnableDebug then
|
||||
if Config.PlayerStatsByGender.enabled and Config.PlayerStatsByGender.debugMode then
|
||||
print('[^2adjustments^7] player stats by gender loaded')
|
||||
print('[^3adjustments^7] enabled: ' .. tostring(Config.PlayerStatsByGender.enabled))
|
||||
print('[^3adjustments^7] use character data: ' .. tostring(Config.PlayerStatsByGender.useCharacterData))
|
||||
|
||||
@@ -44,6 +44,37 @@ Config.Multipliers = {
|
||||
vehicleDensity = 1.0
|
||||
}
|
||||
|
||||
|
||||
Config.PlayerStatsByGender = {
|
||||
enabled = true,
|
||||
debugMode = true,
|
||||
useCharacterData = true, -- true: uses ESX.PlayerData.sex | false: uses ped model/skin
|
||||
malePeds = {
|
||||
`mp_m_freemode_01`,
|
||||
},
|
||||
femalePeds = {
|
||||
`mp_f_freemode_01`,
|
||||
},
|
||||
male = {
|
||||
stamina = 1.0,
|
||||
strength = 1.0,
|
||||
swimSpeed = 1.25,
|
||||
moveSpeed = 1.0,
|
||||
|
||||
-- ADD NEW STATS HERE
|
||||
-- 1. Uncomment line below (remove --)
|
||||
-- 2. Change value: 1.0 = normal, 1.5 = +50%, 0.5 = -50%
|
||||
-- 3. Find natives: https://docs.fivem.net/natives/
|
||||
-- statName = 1.0,
|
||||
},
|
||||
female = {
|
||||
stamina = 1.15,
|
||||
strength = 0.85,
|
||||
swimSpeed = 1.25,
|
||||
moveSpeed = 7.00,
|
||||
}
|
||||
}
|
||||
|
||||
-- Pattern string format
|
||||
--1 will lead to a random number from 0-9.
|
||||
--A will lead to a random letter from A-Z.
|
||||
|
||||
Reference in New Issue
Block a user