From 90cc4becd1b0ebd68626efb80c40ad009b37b91c Mon Sep 17 00:00:00 2001 From: Arctos2win <116841243+Arctos2win@users.noreply.github.com> Date: Sat, 18 Nov 2023 18:58:47 +0100 Subject: [PATCH 1/2] improve setjob function --- [core]/es_extended/server/classes/player.lua | 63 +++++++++----------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/[core]/es_extended/server/classes/player.lua b/[core]/es_extended/server/classes/player.lua index 31c732bda..633d3a11a 100644 --- a/[core]/es_extended/server/classes/player.lua +++ b/[core]/es_extended/server/classes/player.lua @@ -447,41 +447,34 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, ---@param newJob string ---@param grade string ---@return void - function self.setJob(newJob, grade) - grade = tostring(grade) - local lastJob = json.decode(json.encode(self.job)) - - if ESX.DoesJobExist(newJob, grade) then - local jobObject, gradeObject = ESX.Jobs[newJob], ESX.Jobs[newJob].grades[grade] - - self.job.id = jobObject.id - self.job.name = jobObject.name - self.job.label = jobObject.label - - self.job.grade = tonumber(grade) - self.job.grade_name = gradeObject.name - self.job.grade_label = gradeObject.label - self.job.grade_salary = gradeObject.salary - - if gradeObject.skin_male then - self.job.skin_male = json.decode(gradeObject.skin_male) - else - self.job.skin_male = {} - end - - if gradeObject.skin_female then - self.job.skin_female = json.decode(gradeObject.skin_female) - else - self.job.skin_female = {} - end - - _TriggerEvent('esx:setJob', self.source, self.job, lastJob) - self.triggerEvent('esx:setJob', self.job, lastJob) - Player(self.source).state:set("job", self.job, true) - else - print(('[es_extended] [^3WARNING^7] Ignoring invalid ^5.setJob()^7 usage for ID: ^5%s^7, Job: ^5%s^7'):format(self.source, job)) - end - end + function self.setJob(newJob, grade) + grade = tostring(grade) + local lastJob = self.job + + if not ESX.DoesJobExist(newJob, grade) then + return print(('[es_extended] [^3WARNING^7] Ignoring invalid ^5.setJob()^7 usage for ID: ^5%s^7, Job: ^5%s^7'):format(self.source, job)) + end + + local jobObject, gradeObject = ESX.Jobs[newJob], ESX.Jobs[newJob].grades[grade] + + self.job = { + id = jobObject.id, + name = jobObject.name, + label = jobObject.label, + + grade = grade, + grade_name = gradeObject.name, + grade_label = gradeObject.label, + grade_salary = gradeObject.salary, + + skin_male = gradeObject.skin_male and json.decode(gradeObject.skin_male) or {}, + skin_female = gradeObject.skin_female and json.decode(gradeObject.skin_female) or {} + } + + TriggerEvent('esx:setJob', self.source, self.job, lastJob) + self.triggerEvent('esx:setJob', self.job, lastJob) + Player(self.source).state:set("job", self.job, true) + end ---@param weaponName string ---@param ammo number From 004b782075f740d7f9a287376d94354e8d2f0c44 Mon Sep 17 00:00:00 2001 From: Arctos2win <116841243+Arctos2win@users.noreply.github.com> Date: Sat, 18 Nov 2023 19:01:47 +0100 Subject: [PATCH 2/2] tonumber a value --- [core]/es_extended/server/classes/player.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/[core]/es_extended/server/classes/player.lua b/[core]/es_extended/server/classes/player.lua index 633d3a11a..17f110ba7 100644 --- a/[core]/es_extended/server/classes/player.lua +++ b/[core]/es_extended/server/classes/player.lua @@ -462,7 +462,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, name = jobObject.name, label = jobObject.label, - grade = grade, + grade = tonumber(grade), grade_name = gradeObject.name, grade_label = gradeObject.label, grade_salary = gradeObject.salary,