server/main.lua

  • πŸ‡«πŸ‡· AprΓ¨s ce code, ajoutez ceci

  • πŸ‡ΊπŸ‡Έ After this code, add this

local Jobs = setmetatable({}, {__index = function(_, key)
	return ESX.GetJobs()[key]
end})
  • πŸ‡«πŸ‡· Ajoutez ceci

  • Add this

local Jobs2 = setmetatable({}, {__index = function(_, key)
    return ESX.GetJobs2()[key]
end})
  • πŸ‡«πŸ‡· Trouvez cette event dans le fichier: esx_society:withdrawMoney et remplacez:

  • πŸ‡ΊπŸ‡Έ Find this event in the file: esx_society:withdrawMoney and replace:

RegisterServerEvent('esx_society:withdrawMoney')
AddEventHandler('esx_society:withdrawMoney', function(societyName, amount)
	local source = source
	local society = GetSociety(societyName)
	if not society then
		print(('[^3WARNING^7] Player ^5%s^7 attempted to withdraw from non-existing society - ^5%s^7!'):format(source, societyName))
		return
	end
	local xPlayer = ESX.GetPlayerFromId(source)
	amount = ESX.Math.Round(tonumber(amount))
	if (xPlayer.job.name == society.name) or (xPlayer.job2.name == society.name) then
		TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
			if amount > 0 and account.money >= amount then
				account.removeMoney(amount)
				xPlayer.addMoney(amount, TranslateCap('money_add_reason'))
				Config.Notify('have_withdrawn', xPlayer.source, ESX.Math.GroupDigits(amount))
			end
		end)
	else
		return print(('[^3WARNING^7] Player ^5%s^7 attempted to withdraw from society - ^5%s^7!'):format(source, society.name))
	end
end)
  • πŸ‡«πŸ‡· Trouvez cette event dans le fichier: esx_society:depositMoney et remplacez:

  • πŸ‡ΊπŸ‡Έ Find this event in the file: esx_society:depositMoney and replace:

RegisterServerEvent('esx_society:depositMoney')
AddEventHandler('esx_society:depositMoney', function(societyName, amount)
	local source = source
	local xPlayer = ESX.GetPlayerFromId(source)
	local society = GetSociety(societyName)
	if not society then
		print(('[^3WARNING^7] Player ^5%s^7 attempted to deposit to non-existing society - ^5%s^7!'):format(source, societyName))
		return
	end
	amount = ESX.Math.Round(tonumber(amount))
	if (xPlayer.job.name == society.name) or (xPlayer.job2.name == society.name) then
		if amount > 0 and xPlayer.getMoney() >= amount then
			TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
				xPlayer.removeMoney(amount, TranslateCap('money_remove_reason'))
				Config.Notify('have_deposited', xPlayer.source, ESX.Math.GroupDigits(amount))
				account.addMoney(amount)
			end)
		end
	else
		return print(('[^3WARNING^7] Player ^5%s^7 attempted to deposit to society - ^5%s^7!'):format(source, society.name))
	end
end)
  • πŸ‡«πŸ‡· Trouvez le callback dans le fichier: esx_society:getEmployees et remplacez:

  • πŸ‡ΊπŸ‡Έ Find this callback in the file: esx_society:getEmployees and replace:

lib.callback.register('esx_society:getEmployees', function(source, society)
	local xPlayer = ESX.GetPlayerFromId(source)
	local employees = {}
	if xPlayer.job.name == society then
		local response = MySQL.query.await('SELECT * FROM `users` WHERE `job` = ?', {society})
		for i = 1, #response do
			local row = response[i]
			employees[#employees+1] = {				
				identifier = row.identifier,
				name = row.firstname..' '..row.lastname,
				label = Jobs[society].label,
				grade = row.job_grade,
				grade_name = Jobs[society].grades[tostring(row.job_grade)].name,
				grade_label = Jobs[society].grades[tostring(row.job_grade)].label
			}
		end
	elseif xPlayer.job2.name == society then
		local response = MySQL.query.await('SELECT * FROM `users` WHERE `job2` = ?', {society})
		for i = 1, #response do
			local row = response[i]
			employees[#employees+1] = {				
				identifier = row.identifier,
				name = row.firstname..' '..row.lastname,
				label = Jobs2[society].label,
				grade = row.job2_grade,
				grade_name = Jobs2[society].grades[tostring(row.job2_grade)].name,
				grade_label = Jobs2[society].grades[tostring(row.job2_grade)].label
			}
		end
	end
	return employees
end)
  • πŸ‡«πŸ‡· Ajoutez ceci:

  • πŸ‡ΊπŸ‡Έ Add this:

lib.callback.register('esx_society:getJob2', function(source, society)
    if not Jobs2[society] then
        return false
    end
    local job2 = json.decode(json.encode(Jobs2[society]))
    local grades = {}
    for k,v in pairs(job2.grades) do
        table.insert(grades, v)
    end
    table.sort(grades, function(a, b)
        return a.grade < b.grade
    end)
    job2.grades = grades
    return job2
end)

lib.callback.register('esx_society:setJob2', function(source, identifier, job2, grade, actionType)
    local xPlayer = ESX.GetPlayerFromId(source)
    local isBoss = xPlayer.job2.grade_name == 'boss'
    local xTarget = ESX.GetPlayerFromIdentifier(identifier)
    if not isBoss then
        print(('[^3WARNING^7] Player ^5%s^7 attempted to setJob2 for Player ^5%s^7!'):format(source, xTarget.source))
		return false
    end
    if not xTarget then
        MySQL.update('UPDATE users SET job2 = ?, job2_grade = ? WHERE identifier = ?', {job2, grade, identifier},
        function()
            return false
        end)
        return
    end
    xTarget.setJob2(job2, grade)
	if actionType == 'hire' then
		Config.Notify('you_have_been_hired_job2', xTarget.source, job2)
		Config.Notify('you_have_hired', xPlayer.source, xTarget.getName())
	elseif actionType == 'promote' then
		Config.Notify('you_have_been_promoted', xTarget.source)
		Config.Notify('you_have_promoted', xPlayer.source, xTarget.getName(), xTarget.getJob2().grade_label)
	elseif actionType == 'demote' then
		Config.Notify('you_have_been_demoted', xTarget.source)
		Config.Notify('you_have_demoted', xPlayer.source, xTarget.getName(), xTarget.getJob2().grade_label)
	elseif actionType == 'fire' then
		Config.Notify('you_have_been_fired_job2', xTarget.source, xPlayer.getJob2().label)
		Config.Notify('you_have_fired', xPlayer.source, xTarget.getName())
	end
	return true
end)

lib.callback.register('esx_society:setJob2Salary', function(source, job2, grade, salary, gradeLabel)
    local xPlayer = ESX.GetPlayerFromId(source)
    if xPlayer.job2.name == job2and Config.BossGrades[xPlayer.job2.grade_name] then
        if salary <= Config.MaxSalary then
            MySQL.update('UPDATE job2_grades SET salary = ? WHERE job2_name = ? AND grade = ?', {salary, job2, grade},
            function(rowsChanged)
                Jobs2[job2].grades[tostring(grade)].salary = salary
                ESX.RefreshJobs2()
                Wait(1)
                local xPlayers = ESX.GetExtendedPlayers('job2', job2)
                for _, xTarget in pairs(xPlayers) do
                    if xTarget.job2.grade == grade then
                        xTarget.setJob2(job2, grade)
                    end
                end
				Config.Notify('salary_change', xPlayer.source, salary, gradeLabel)
				return true
            end)
        else
            print(('[^3WARNING^7] Player ^5%s^7 attempted to setJob2Salary over the config limit for ^5%s^7!'):format(source, job2))
			return false
        end
    else
        print(('[^3WARNING^7] Player ^5%s^7 attempted to setJob2Salary for ^5%s^7!'):format(source, job2))
		return false
    end
end)

lib.callback.register('esx_society:setJob2Label', function(source, job2, grade, label)
    local xPlayer = ESX.GetPlayerFromId(source)
    if xPlayer.job2.name == job2and Config.BossGrades[xPlayer.job2.grade_name] then
            MySQL.update('UPDATE job2_grades SET label = ? WHERE job2_name = ? AND grade = ?', {label, job2, grade},
            function(rowsChanged)
                Jobs2[job2].grades[tostring(grade)].label = label
                ESX.RefreshJobs2()
                Wait(1)
                local xPlayers = ESX.GetExtendedPlayers('job2', job2)
                for _, xTarget in pairs(xPlayers) do
                    if xTarget.job2.grade == grade then
                        xTarget.setJob2(job2, grade)
                    end
                end
				Config.Notify('grade_change', xPlayer.source, label)
				return true
            end)
    else
        print(('[^3WARNING^7] Player ^5%s^7 attempted to setJob2Labelfor ^5%s^7!'):format(source, job2))
		return false
    end
end)
  • πŸ‡«πŸ‡· Trouvez le callback dans le fichier: esx_society:getOnlinePlayers et remplacez:

  • πŸ‡ΊπŸ‡Έ Find this callback in the file: esx_society:getOnlinePlayers and replace:

lib.callback.register('esx_society:getOnlinePlayers', function(source)
		local onlinePlayers = {}
		local xPlayers = ESX.GetExtendedPlayers()
		for i=1, #(xPlayers) do 
			local xPlayer = xPlayers[i]
			table.insert(onlinePlayers, {
				source = xPlayer.source,
				identifier = xPlayer.identifier,
				name = xPlayer.name,
				job = xPlayer.job,
                		job2= xPlayer.job2
			})
		end
	return onlinePlayers
end)
  • πŸ‡«πŸ‡· Cherchez la fonction isPlayerBoss(playerId, arg)

  • πŸ‡ΊπŸ‡Έ Find the function isPlayerBoss(playerId, arg)

    • πŸ‡«πŸ‡· Puis, remplacez la fonction entiΓ¨re par celle-ci:

    • πŸ‡ΊπŸ‡Έ Then, replace the entire function with this one:

    function isPlayerBoss(playerId, arg)
        local xPlayer = ESX.GetPlayerFromId(playerId)
        local selected = xPlayer.job.name == arg and 'job' or xPlayer.job2.name == arg and 'job2' or false
        local value = {}
        if selected and xPlayer[selected].grade_name == 'boss' then
    		value = {true, selected}
            return value
        else
            print(('esx_society: %s attempted open a society boss menu!'):format(xPlayer.identifier))
            return false
        end
    end

Last updated