# Functions

{% tabs %}
{% tab title="vRP" %}
Functions are made for a basic **Dunko vRP base**. If your functions are not matching please edit \
vRP. functions from *config/config.lua*

```lua
Config.giveUserReward = function(user_id, price)
    if not user_id then return 0 end;
    vRP.giveMoney { user_id, price }
end

Config.isUserFarmer = function(user_id)
    if not user_id then return 0 end;
    return vRP.hasGroup { user_id, Config.jobCode } or false
end

Config.tryPayment = function(user_id, price)
    if not user_id then return 0 end;
    return vRP.tryPayment { user_id, price }
end


Config.tryGetItem = function(user_id, item, amount)
    if not user_id then return 0 end;
    return vRP.tryGetInventoryItem { user_id, item, amount, true }
end

Config.hirePlayer = function(user_id, hired)
    if not user_id then return 0 end;
    local src = vRP.getUserSource { user_id }
    if not hired then
        if vRP.getUserGroupByType { user_id, 'job' } == 'Somer' then
            vRP.addUserGroup { user_id, Config.jobCode }
            Config.NotifyFunction(Lang.Notify['succes_hired'][1], Lang.Notify['succes_hired'][2], src)
        else
            Config.NotifyFunction(Lang.Notify['has_other_job'][1], Lang.Notify['has_other_job'][2], src)
        end
    else
        vRP.addUserGroup { user_id, 'Somer' }
        Config.NotifyFunction(Lang.Notify['succes_leave_job'][1], Lang.Notify['succes_leave_job'][2], src)
    end
end

Config.hasRequireditems = function(user_id, job)
    if not user_id then return false end;
    if not Config.Minigames[job] then return false end;
    for item, amount in pairs(Config.Minigames[job].requiredItems) do
        if vRP.getInventoryItemAmount { user_id, item } < amount then
            local src = vRP.getUserSource { user_id }
            return Config.NotifyFunction(Lang.Notify['items_mising'][1]:format(amount, vRP.getItemName { item }),
                Lang.Notify['items_mising'][2], src);
        end
    end
    return true;
end

Config.givePlayerItem = function(user_id, item, amount)
    if not user_id then return 0 end;
    if vRP.getInventoryMaxWeight { user_id } >= vRP.getInventoryWeight { user_id } + vRP.getItemWeight { item } * amount then
        vRP.giveInventoryItem { user_id, item, amount, true };
    end
end

Config.givePlayerReward = function(user_id, src, rewardData, requiredItems)
    if not user_id then return 0 end;
    if requiredItems then
        for item, amount in pairs(requiredItems) do
            vRP.tryGetInventoryItem { user_id, item, amount, true }
        end
    end
    if rewardData then
        for item, amount in pairs(rewardData) do
            if vRP.getInventoryMaxWeight { user_id } >= (vRP.getInventoryWeight { user_id } + vRP.getItemWeight { item } * amount) then
                vRP.giveInventoryItem { user_id, item, amount, true };
            else
                return Config.NotifyFunction(Lang.Notify['no_inventory_space'][1],
                    Lang.Notify['no_inventory_space'][2], src);
            end
        end
    end
end

Config.promptFunction = function(user_id, src, message, valueType)
    if not user_id then return 0 end;
    local find, answer = promise.new(), nil;
    vRP.prompt({ src, message, "",
        function(player, value)
            if valueType == "number" then
                value = tonumber(value)
            end
            if value and type(value) == valueType then
                if valueType == "number" then
                    value = math.floor(value);
                end
                answer = value
            end
            find:resolve()
        end })


    Citizen.Await(find);
    return answer;
end

Config.showTextUI = function(message)
    exports['okokTextUI']:Open(message, 'lightred', 'left')
end

Config.HideTextUI = function()
    exports['okokTextUI']:Close();
end

Config.NotifyFunction = function(msg, type, source) 
    if source then
        vRPclient.notify(source, { msg })           -- server side
    else
        vRP.notify({ msg })                         -- client side
    end
end

```

{% endtab %}

{% tab title="QBCore" %}
Functions are made for a basic **QBCore Server base**. If your functions are not matching please edit QBCore.Functions from *config/functions.lua*

```lua
local QBCore = exports['qb-core']:GetCoreObject()

Config.giveUserReward = function(src, price) -- money reward for item sold
    if not src then return 0 end;
    local Player = QBCore.Functions.GetPlayer(src)
    return Player.Functions.AddMoney('cash', price, 'sell farmer item')
end


Config.tryPayment = function(src, price)
    if not src then return 0 end;
    local Player = QBCore.Functions.GetPlayer(src)
    return Player.Functions.RemoveMoney('cash', price, 'buy farmer item');
end


Config.tryGetItem = function(src, item, amount)
    if not src then return 0 end;
    return 	exports['qb-inventory']:RemoveItem(src, item,amount, false, 'Farmer Job Seller')
end

Config.givePlayerItem = function(source, item, amount)
    if not source then return 0 end;
    exports['qb-inventory']:AddItem(source, item, amount, false, false, 'Farmer Job Buyer')
end


Config.hasRequireditems = function(src, job)
    local Player = QBCore.Functions.GetPlayer(src)
    if not Player then return 0 end;
    if not Config.Minigames[job] then return false end;
    for item, amount in pairs(Config.Minigames[job].requiredItems) do
        local itemD = Player.Functions.GetItemByName(item)
        if not itemD then return false end;
        if  itemD.amount < amount then
            return Config.NotifyFunction(Lang.Notify['items_mising'][1]:format(amount,itemD.label),
                Lang.Notify['items_mising'][2], src);
        end
    end
    return true;
end


Config.givePlayerReward = function( src, rewardData, requiredItems)
    local Player = QBCore.Functions.GetPlayer(src)
    if not Player then return 0 end;
    if requiredItems then
        for item, amount in pairs(requiredItems) do
            exports['qb-inventory']:AddItem(src, item, amount, false, false, 'Farmer Job Reward')
        end
    end
    if rewardData then
        for item, amount in pairs(rewardData) do
            if exports['qb-inventory']:AddItem(src, item, amount, false, false, 'Farmer Job Reward') then

            else
                return Config.NotifyFunction(Lang.Notify['no_inventory_space'][1],
                    Lang.Notify['no_inventory_space'][2], src);
            end
        end
    end
end


Config.showTextUI = function(message)
    exports['axr_hudv1']:showTextUI('E','Farmer Job',message);
end

Config.HideTextUI = function()
    exports['axr_hudv1']:closeTextUI();
end

Config.NotifyFunction = function(msg, type, source) 
    if source then
        TriggerClientEvent('QBCore:Notify', source,msg, type -- server side
    else
        QBCore.Functions.Notify(msg,type) -- client side
    end
end

```

{% endtab %}

{% tab title="ESX" %}

{% endtab %}
{% endtabs %}


---

# 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://axero-scripts.gitbook.io/axr-documentation/resources/axr_farmer/functions.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.
