# 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/functions.lua*

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


Config.getOwnedVehicle = function() -- from client side
    --##### EDIT FUNCTION FOR YOUR OWN GAMEMODE BASE (default vRP dunko) #####--
    local ok, vtype, vname, plate, entity = vRP.getNearestOwnedVehicle({ 5 })
    return ok, vname, entity;
end

Config.getNearestPlayer = function(user_id, src) -- from server side
    if user_id and src then
        local target = promise.new();
        vRPclient.getNearestPlayer(src, { 3 }, function(nplayer)
            if nplayer then
                local target_id = vRP.getUserId { nplayer };
                if target_id then
                    target:resolve(target_id);
                end
                target:resolve(nil);
            else
                target:resolve(nil);
            end
        end)
        Citizen.Await(target);
        return target.value;
    end
end

Config.getNearestPlayers = function() -- from client side
    local players = vRP.getNearestPlayers({ 3 });
    return players;
end

Config.getPlayerRoleplayName = function(user_id, source)           -- for server side
    local find, fullname = promise.new(), nil;                     -- dont edit
    vRP.getUserIdentity({ user_id, function(identity)              -- edit your identity function for your own server
        if identity then
            fullname = identity.firstname .. " " .. identity.name; -- edit table keys for your own function
            find:resolve()                                         -- dont edit
        end
    end })

    -- dont edit below
    Citizen.Await(find)
    return fullname
end

Config.getPlayerCashMoney = function(user_id, source) -- for server side
    if user_id then
        return vRP.getMoney { user_id }
    end
    return 0;
end

Config.canUseFastSlots = function() -- for client side
    if not vRP.isInComa() and not vRP.isHandcuffed() then
        return true;
    end
end

Config.weaponAcces = function(weapon) -- from client side
    if vRP.isInComa {} or vRP.isHandcuffed {} then
        return false;
    end
    return true;
end

Config.getTrunkItems = function(user_id, vehicle) -- from server side
    local vehData = exports[Config.Sql]:executeSync(
        'SELECT trunk FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle',
        { user_id = user_id, vehicle = vehicle })
    if vehData and #vehData == 1 then
        return json.decode(vehData[1].trunk);
    end
end

Config.getGloveboxItems = function(user_id, vehicle) -- from server side
    local vehData = exports[Config.Sql]:executeSync(
        'SELECT glovebox FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle',
        { user_id = user_id, vehicle = vehicle })
    if vehData and #vehData == 1 then
        return json.decode(vehData[1].glovebox);
    end
end

Config.request = function(user_id, src, message) -- from server side
    if not user_id then return 0 end;
    local find, answer = promise.new(), nil;
    vRP.request({ src, message, 20,
        function(player, ok)
            answer = ok or false
            find:resolve()
        end })


    Citizen.Await(find);
    return answer;
end

Config.hasChestPermission = function(user_id, chestData)
    if user_id and chestData then
        if chestData.faction then
            return vRP.isUserInFaction { user_id, chestData.faction };
        end
        if chestData.group then
            return vRP.hasGroup { user_id, chestData.group };
        end
        if chestData.permission then
            return vRP.hasPermission { user_id, chestData.permission };
        end
        return true;
    end
end

Config.progressBar = function(text, time) -- from client side (time in miliseconds | seconds * 1000)
    exports["rprogress"]:Start(text, time);
end

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


Config.HideStaticNotify = function(msg)
    exports['axr_hudv1']:hideTextUI();
end

Config.drawMarker = function(marker, coords, r, g, b)
    DrawMarker(marker, coords - vector3(0, 0, 0.95), 0, 0, 0,
        0, 0, -100, 1.2001, 1.2001, 1.2001, r, g, b, 100,
        0, 1, 0, 0)
end



-- onUse item functions

Config.drinkWater = function(user_id, source, item, varyThirst) -- from server side
    if user_id and source then
        if Items[item] then
            vRP.varyHunger({ user_id, varyThirst })
            local seq = {
                { "mp_player_intdrink", "intro_bottle", 1 },
                { "mp_player_intdrink", "loop_bottle",  1 },
                { "mp_player_intdrink", "outro_bottle", 1 }
            }
            vRPclient.notify(source, { "Bei " .. Items[item].name .. ".", 'info' })
            vRPclient.playAnim(source, { true, seq, false })
            exports.axr_inventory:removePlayerItem(user_id, item, 1, true, 'Drinking')
        end
    end
end

Config.eatFood = function(user_id, source, item, varyHunger) -- from server side
    if user_id and source then
        if Items[item] then
            vRP.varyHunger({ user_id, varyHunger })
            local seq = {
                { "mp_player_intdrink", "intro_bottle", 1 },
                { "mp_player_intdrink", "loop_bottle",  1 },
                { "mp_player_intdrink", "outro_bottle", 1 }
            }
            vRPclient.notify(source, { "Mananci " .. Items[item].name .. ".", 'info' })
            vRPclient.playAnim(source, { true, seq, false })
            exports.axr_inventory:removePlayerItem(user_id, item, 1, true, 'Eating')
        end
    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
Config = {}

Config.getPlayerMoney = function(user_id)
    if user_id then
        local playerMoney = {
            cash = vRP.getMoney { user_id },
            bank = vRP.getBankMoney { user_id },
        }
        return playerMoney;
    end
end

Config.getPlayerSurvival = function(user_id)
    if user_id then
        local vitals = {
            food = math.ceil(100 - vRP.getHunger { user_id }),
            drink = math.ceil(100 - vRP.getThirst { user_id }),
        }
        return vitals;
    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_inventory/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.
