Functions

All editable axr_hudv1 functions

Functions are made for a basic Dunko vRP base. If your functions are not matching please edit vRP. functions from config/config.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

Last updated