# Setup

## In-depth Guied

You just downloaded the script and wonder how to set it up so it works on your server? Well, you're in the right place to do so.

{% stepper %}
{% step %}

### Dependencies

Make sure you have all the right dependencies to run the script, you can find theese [here](/yecoyz/free-resources/duty/dependencies.md).
{% endstep %}

{% step %}

### Setup framework compability

Change this in your framework for the script to work with your paycheck system.<br>

{% tabs %}
{% tab title="qb-core" %}
{% code title="server/functions.lua" %}

```lua
local OffDutyInfo = nil
if (GetResourceState("yecoyz_duty") == "started") then
    OffDutyInfo = exports["yecoyz_duty"]:GetOffDutyPayInfo()
end

function PaycheckInterval()
    if not next(QBCore.Players) then 
        SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval)
        return 
    end
    for _, Player in pairs(QBCore.Players) do
        if not Player then return end
        local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
        if not payment then payment = Player.PlayerData.job.payment end

        local onDuty = Player.PlayerData.job.onduty
        if (GetResourceState("yecoyz_duty") == "started") then
            onDuty = exports["yecoyz_duty"]:GetDutyState(Player.PlayerData.source)
            local multiplier = exports["yecoyz_duty"]:GetSalaryMultiplier(Player.PlayerData.source)
            payment = math.floor(payment*multiplier)
        end

        local offDutyPay = true
        if (not onDuty) then
            if (OffDutyInfo) and (OffDutyInfo.offDutyPay) then
                payment = math.floor(payment*OffDutyInfo.multiplier)
            else
                offDutyPay = false
            end
        end
        if Player.PlayerData.job and payment > 0 and (offDutyPay or onDuty) then
            if QBCore.Config.Money.PayCheckSociety then
                local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
                if account ~= 0 then
                    if account < payment then
                        TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
                    else
                        Player.Functions.AddMoney('bank', payment, 'paycheck')
                        exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
                        TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
                    end
                else
                    Player.Functions.AddMoney('bank', payment, 'paycheck')
                    TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
                end
            else
                Player.Functions.AddMoney('bank', payment, 'paycheck')
                TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
            end
        end
    end
    SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval)
end
```

{% endcode %}
{% endtab %}

{% tab title="qbx\_core" %}
{% code title="server/loops.lua" %}

```lua
local function pay(player)
    local job = player.PlayerData.job
    local jobData = GetJob(job.name)
    if (not jobData) then return end

    local payment = jobData.grades[job.grade.level].payment or job.payment
    if (not payment or payment <= 0) then return end

    if (GetResourceState("yecoyz_duty") == "started") then
        local onDuty = exports["yecoyz_duty"]:GetDutyState(player.PlayerData.source)

        if (onDuty) then
            local multiplier = exports["yecoyz_duty"]:GetSalaryMultiplier(player.PlayerData.source)
            payment = math.floor(payment * multiplier)
        elseif (not jobData.offDutyPay) then
            return
        else
            local offDutyInfo = exports["yecoyz_duty"]:GetOffDutyPayInfo()
            if offDutyInfo and offDutyInfo.multiplier then
                payment = math.floor(payment * offDutyInfo.multiplier)
            end
        end
    else
        if (not jobData.offDutyPay) and (not job.onduty) then return end
    end

    if (not config.money.paycheckSociety) then
        config.sendPaycheck(player, payment)
        return
    end

    local account = config.getSocietyAccount(job.name)
    if (not account) then
        config.sendPaycheck(player, payment)
        return
    end

    if (account < payment) then
        Notify(player.PlayerData.source, locale('error.company_too_poor'), 'error')
        return
    end

    config.removeSocietyMoney(job.name, payment)
    config.sendPaycheck(player, payment)
end
```

{% endcode %}
{% endtab %}

{% tab title="es\_extended 1.10.10 or later" %}
{% code title="server/modules/paycheck.lua" fullWidth="true" %}

```lua
local OffDutyInfo = nil
if (GetResourceState("yecoyz_duty") == "started") then
    OffDutyInfo = exports["yecoyz_duty"]:GetOffDutyPayInfo()
end

function StartPayCheck()
    CreateThread(function()
        while true do
            Wait(Config.PaycheckInterval)
            for player, xPlayer in pairs(ESX.Players) do
                local jobLabel = xPlayer.job.label
                local job = xPlayer.job.grade_name
                local salary = xPlayer.job.grade_salary
                local onDuty = xPlayer.job.onDuty

                if (GetResourceState("yecoyz_duty") == "started") then
                    local multiplier = exports["yecoyz_duty"]:GetSalaryMultiplier(xPlayer.source)
                    salary = math.floor(salary*multiplier)
                    onDuty = exports["yecoyz_duty"]:GetDutyState(xPlayer.source)
                end

                if xPlayer.paycheckEnabled then
                    if salary > 0 then
                        if job == "unemployed" then -- unemployed
                            xPlayer.addAccountMoney("bank", salary, "Welfare Check")
                            TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_help", salary), "CHAR_BANK_MAZE", 9)
                            if Config.LogPaycheck then
                                ESX.DiscordLogFields("Paycheck", "Paycheck - Unemployment Benefits", "green", {
                                    { name = "Player", value = xPlayer.name, inline = true },
                                    { name = "ID", value = xPlayer.source, inline = true },
                                    { name = "Amount", value = salary, inline = true },
                                })
                            end
                        elseif Config.EnableSocietyPayouts then -- possibly a society
                        local offDutyPay = true

                        if (not onDuty) then
                            if (OffDutyInfo) and (OffDutyInfo.offDutyPay) then
                                salary = math.floor(salary*OffDutyInfo.multiplier)
                            else
                                offDutyPay = false
                            end    
                        end

                        if (offDutyPay) then
                            TriggerEvent("esx_society:getSociety", xPlayer.job.name, function(society)
                                if society ~= nil then -- verified society
                                    TriggerEvent("esx_addonaccount:getSharedAccount", society.account, function(account)
                                        if account.money >= salary then -- does the society money to pay its employees?
                                            xPlayer.addAccountMoney("bank", salary, "Paycheck")
                                            account.removeMoney(salary)
                                            if Config.LogPaycheck then
                                                ESX.DiscordLogFields("Paycheck", "Paycheck - " .. jobLabel, "green", {
                                                    { name = "Player", value = xPlayer.name, inline = true },
                                                    { name = "ID", value = xPlayer.source, inline = true },
                                                    { name = "Amount", value = salary, inline = true },
                                                })
                                            end
    
                                            TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9)
                                        else
                                            TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), "", TranslateCap("company_nomoney"), "CHAR_BANK_MAZE", 1)
                                        end
                                    end)
                                    else -- not a society
                                        xPlayer.addAccountMoney("bank", salary, "Paycheck")
                                        if Config.LogPaycheck then
                                            ESX.DiscordLogFields("Paycheck", "Paycheck - " .. jobLabel, "green", {
                                                { name = "Player", value = xPlayer.name, inline = true },
                                                { name = "ID", value = xPlayer.source, inline = true },
                                                { name = "Amount", value = salary, inline = true },
                                            })
                                        end
                                        TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9)
                                    end
                                end)
                            end
                        else -- generic job
                            local offDutyPay = true
                            local onDuty = exports["yecoyz_duty"]:GetDutyState(xPlayer.source)

                            if (not onDuty) then
                                if (OffDutyInfo) and (OffDutyInfo.offDutyPay) then
                                    salary = math.floor(salary*OffDutyInfo.multiplier)
                                else
                                    offDutyPay = false
                                end    
                            end

                            if (offDutyPay) then
                                xPlayer.addAccountMoney("bank", salary, "Paycheck")
                                if Config.LogPaycheck then
                                    ESX.DiscordLogFields("Paycheck", "Paycheck - Generic", "green", {
                                        { name = "Player", value = xPlayer.name, inline = true },
                                        { name = "ID", value = xPlayer.source, inline = true },
                                        { name = "Amount", value = salary, inline = true },
                                    })
                                end
                                TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9)
                            end
                        end
                    end
                end
            end
        end
    end)
end
```

{% endcode %}
{% endtab %}

{% tab title="es\_extended before 1.10.10" %}
{% code title="server/modules/paycheck.lua" %}

```lua
local OffDutyInfo = nil
if (GetResourceState("yecoyz_duty") == "started") then
    OffDutyInfo = exports["yecoyz_duty"]:GetOffDutyPayInfo()
end

function StartPayCheck()
    CreateThread(function()
        while true do
            Wait(Config.PaycheckInterval)
            for player, xPlayer in pairs(ESX.Players) do
                local jobLabel = xPlayer.job.label
                local job = xPlayer.job.grade_name
                local salary = xPlayer.job.grade_salary
                local onDuty = true

                if (GetResourceState("yecoyz_duty") == "started") then
                    local multiplier = exports["yecoyz_duty"]:GetSalaryMultiplier(xPlayer.source)
                    salary = math.floor(salary*multiplier)
                    onDuty = exports["yecoyz_duty"]:GetDutyState(xPlayer.source)
                end

                if xPlayer.paycheckEnabled then
                    if salary > 0 then
                        if job == "unemployed" then -- unemployed
                            xPlayer.addAccountMoney("bank", salary, "Welfare Check")
                            TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_help", salary), "CHAR_BANK_MAZE", 9)
                            if Config.LogPaycheck then
                                ESX.DiscordLogFields("Paycheck", "Paycheck - Unemployment Benefits", "green", {
                                    { name = "Player", value = xPlayer.name, inline = true },
                                    { name = "ID", value = xPlayer.source, inline = true },
                                    { name = "Amount", value = salary, inline = true },
                                })
                            end
                        elseif Config.EnableSocietyPayouts then -- possibly a society
                        local offDutyPay = true

                        if (not onDuty) then
                            if (OffDutyInfo) and (OffDutyInfo.offDutyPay) then
                                salary = math.floor(salary*OffDutyInfo.multiplier)
                            else
                                offDutyPay = false
                            end    
                        end

                        if (offDutyPay) then
                            TriggerEvent("esx_society:getSociety", xPlayer.job.name, function(society)
                                if society ~= nil then -- verified society
                                    TriggerEvent("esx_addonaccount:getSharedAccount", society.account, function(account)
                                        if account.money >= salary then -- does the society money to pay its employees?
                                            xPlayer.addAccountMoney("bank", salary, "Paycheck")
                                            account.removeMoney(salary)
                                            if Config.LogPaycheck then
                                                ESX.DiscordLogFields("Paycheck", "Paycheck - " .. jobLabel, "green", {
                                                    { name = "Player", value = xPlayer.name, inline = true },
                                                    { name = "ID", value = xPlayer.source, inline = true },
                                                    { name = "Amount", value = salary, inline = true },
                                                })
                                            end
    
                                            TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9)
                                        else
                                            TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), "", TranslateCap("company_nomoney"), "CHAR_BANK_MAZE", 1)
                                        end
                                    end)
                                    else -- not a society
                                        xPlayer.addAccountMoney("bank", salary, "Paycheck")
                                        if Config.LogPaycheck then
                                            ESX.DiscordLogFields("Paycheck", "Paycheck - " .. jobLabel, "green", {
                                                { name = "Player", value = xPlayer.name, inline = true },
                                                { name = "ID", value = xPlayer.source, inline = true },
                                                { name = "Amount", value = salary, inline = true },
                                            })
                                        end
                                        TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9)
                                    end
                                end)
                            end
                        else -- generic job
                            local offDutyPay = true
                            local onDuty = exports["yecoyz_duty"]:GetDutyState(xPlayer.source)

                            if (not onDuty) then
                                if (OffDutyInfo) and (OffDutyInfo.offDutyPay) then
                                    salary = math.floor(salary*OffDutyInfo.multiplier)
                                else
                                    offDutyPay = false
                                end    
                            end

                            if (offDutyPay) then
                                xPlayer.addAccountMoney("bank", salary, "Paycheck")
                                if Config.LogPaycheck then
                                    ESX.DiscordLogFields("Paycheck", "Paycheck - Generic", "green", {
                                        { name = "Player", value = xPlayer.name, inline = true },
                                        { name = "ID", value = xPlayer.source, inline = true },
                                        { name = "Amount", value = salary, inline = true },
                                    })
                                end
                                TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9)
                            end
                        end
                    end
                end
            end
        end
    end)
end
```

{% endcode %}
{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

## Support

If you have any problems with the setup, we're happy to help in our discord witch you can find [here](https://discord.yecoyzresources.com/).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yecoyz-resources.gitbook.io/yecoyz/free-resources/duty/setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
