vRP

Default vRP framework installation (axr_octastore/server/framework/vrp.lua)

Server

if Config.Framework ~= 'vrp' then
    return
end

local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")
local vRP = Proxy.getInterface("vRP")
local vRPclient = Tunnel.getInterface("vRP", "axr_octastore")

Framework = {}

---@param identifier integer
---@return boolean
Framework.canAccesMenu = function(identifier)
    if identifier then
        -- your custom functions to open menu (coma status/handcuff etc)
        return true;
    end
    return false;
end

---@param source integer
---@return integer
Framework.getPlayerIdentifier = function(source)
    return vRP.getUserId { source };
end

---@param identifier integer
---@return integer
Framework.getIdentifierSource = function(identifier)
    return vRP.getUserSource { identifier };
end

---@param identifier integer
---@return table (keep the specific format)
Framework.getPlayerIdentity = function(identifier)
    local response = promise.new();
    vRP.getUserIdentity({ identifier, function(identity)
        if identifier then
            response.resolve({
                firstname = identity.firstname,
                secondname = identity.name,
                phone_numner = identity.phoneNumber or 'unknown',
            })
        else
            response.resolve(nil)
        end
    end })
    Citizen.Await(response);
    return response.value;
end

---@param identifier integer
---@param price integer
---@return boolean
Framework.tryPaymentPlan = function(identifier, price)
    if identifier then
        return vRP.tryBankPayment { identifier, price };
    end
    return false;
end


---@param identifier integer
---@param price integer
---@return boolean
Framework.tryPayProductsOnline = function(identifier, price)
    if identifier then
        return vRP.tryBankPayment { identifier, price };
    end
    return false;
end

---@param identifier integer
---@param amount integer
---@return boolean
Framework.paySeller = function(identifier, amount)
    if identifier then
        local sellerSource = Framework.getIdentifierSource(identifier);
        if sellerSource then
            vRP.giveBankMoney({ identifier, amount });
        else
            exports[Config.Sql]:execute('UPDATE vrp_users SET bankMoney = bankMoney + @amount WHERE id = identifier', {
                identifier = identifier,
                amount = amount
            })
        end
    end
end

---@param item string
---@param callback function
Framework.createItem = function(item, callback)
    if Config.Inventory == 'vrp' then
        vRP.defInventoryItem({ Config.item, 'OctaStore Tablet', 'OctaStore Tablet for marketplace', function()
            local choices = {};
            choices['Use'] = function(player, choice)
                local user_id = vRP.getUserId({ player })
                if user_id then
                    callback(user_id);
                end
            end
            return choices;
        end, 0.01 })
    elseif Config.Inventory == 'axr_inventory' then
        exports.axr_inventory:createItem(item, 'OctaStore Tablet', 'OctaStore Tablet for marketplace', 0.01, 'all',
            function(user_id, player, item, itemData)
                callback(user_id);
            end)
    else
        print('ERRROR: Inventory type not found')
    end
end

---@param identifier integer
---@param item string
---@param amount integer?nil
---@return boolean
Framework.hasItem = function(identifier, item, amount)
    if Config.Inventory == 'vrp' then
        if amount ~= nil then
            return (vRP.getInventoryItemAmount({ identifier, item }) >= amount);
        else
            return (vRP.getInventoryItemAmount({ identifier, item }) > 0);
        end
    elseif Config.Inventory == 'axr_inventory' then
        if amount ~= nil then
            return (exports.axr_inventory:getPlayerItemAmount(identifier, item) >= amount);
        else
            return exports.axr_inventory:hasPlayerItem(identifier, item)
        end
    else
        print('ERRROR: Inventory type not found')
    end
    return false;
end


---@param identifier integer
---@return table?nil
Framework.getPlayerItems = function(identifier)
    if Config.Inventory == 'vrp' then
        local data = vRP.getUserDataTable({ identifier })
        if data then
            local inventory = data.inventory;
            local items = {};
            for k, v in pairs(inventory) do
                local amount = vRP.getInventoryItemAmount({ identifier, k })
                if amount > 0 and not Config.blacklistedItems[k] then
                    items[k] = {
                        amount = amount,
                        img = exports.axr_octastore:getItemImagePath(k),
                        name = vRP.getItemName({ k })
                    }
                end
            end
            return items;
        end
    elseif Config.Inventory == 'axr_inventory' then
        local inventory = exports.axr_inventory:getPlayerInventory(identifier);
        local items = {};
        if inventory then
            for k, v in pairs(inventory.backpack) do
                if v and not Config.blacklistedItems[v.item] then
                    items[v.item] = {
                        amount = v.amount,
                        img = exports.axr_octastore:getItemImagePath(v.item),
                        name = v.name
                    }
                end
            end
            for k, v in pairs(inventory.pocket) do
                if v and not Config.blacklistedItems[v.item] then
                    items[v.item] = {
                        amount = v.amount,
                        img = exports.axr_octastore:getItemImagePath(v.item),
                        name = v.name
                    }
                end
            end
            for k, v in pairs(inventory.fastSlots) do
                if v and not Config.blacklistedItems[v.item] then
                    items[v.item] = {
                        amount = v.amount,
                        img = exports.axr_octastore:getItemImagePath(v.istem),
                        name = v.name
                    }
                end
            end
        end
        return items;
    else
        print('ERRROR: Please edit your custom getPlayerItems function (server/framework/vrp.lua)')
    end
end


---@param identifier integer
---@param items table --{index: {name:'',item:'',amount:''}}
---@return boolean
Framework.hasSpaceForItems = function(identifier, items)
    if identifier then
        if Config.Inventory == 'axr_inventory' then
            local userWeight = exports.axr_inventory:getUserWeight(identifier);
            local userMaxWeight = exports.axr_inventory:getUserMaxWeight(identifier);
            local itemsWeight = 0;
            for index, itemData in pairs(items) do
                itemsWeight = itemsWeight + (exports.axr_inventory:getItemWeight(itemData.item) * itemData.amount)
            end

            return (userMaxWeight >= (userWeight + itemsWeight));
        elseif Config.Inventory == 'vrp' then
            local userWeight = vRP.getInventoryWeight({ identifier });
            local userMaxWeight = vRP.getInventoryMaxWeight({ identifier });
            local itemsWeight = 0;
            for index, itemData in pairs(items) do
                itemsWeight = itemsWeight + (vRP.getItemWeight({ itemData.item }) * itemData.amount)
            end

            return (userMaxWeight >= (userWeight + itemsWeight));
        else
            print('ERRROR: Please edit your custom hasSpaceForItems  function (server/framework/vrp.lua)')
        end
    end
end

---@param identifier integer
---@param item string
---@param amount integer
Framework.giveInventoryItem = function(identifier, item, amount)
    if identifier then
        if Config.Inventory == 'axr_inventory' then
            exports.axr_inventory:givePlayerItem(identifier, item, amount, true);
        elseif Config.Inventory == 'vrp' then
            vRP.giveInventoryItem({ identifier, item, amount, true });
        else
            print('ERRROR: Please edit your custom giveInventoryItem  function (server/framework/vrp.lua)')
        end
    end
end

---@param identifier integer
---@param item string
---@param amount integer
Framework.removeInventoryItem = function(identifier, item, amount)
    if identifier then
        if Config.Inventory == 'axr_inventory' then
            exports.axr_inventory:removePlayerItem(identifier, item, amount, true);
        elseif Config.Inventory == 'vrp' then
            vRP.tryGetInventoryItem({ identifier, item, amount, true });
        else
            print('ERRROR: Please edit your custom removeInventoryItem  function (server/framework/vrp.lua)')
        end
    end
end

---@param item string
---@return string
Framework.getItemName = function(item)
    if item then
        if Config.Inventory == 'axr_inventory' then
            return exports.axr_inventory:getItemName(item);
        elseif Config.Inventory == 'vrp' then
            return vRP.getItemName({ item })
        end
    end
    return 'unknown'
end


---@param identifier integer
---@param lockerItems table  --{index: {name:'',item:'',amount:''}}
Framework.giveLockerItems = function(identifier, lockerItems)
    local source = Framework.getIdentifierSource(identifier);
    if identifier and source then
        if Framework.hasSpaceForItems(identifier, lockerItems) then
            for index, itemData in pairs(lockerItems) do
                Framework.giveInventoryItem(identifier, itemData.item, itemData.amount);
            end
            Framework.notify(source, Lang.notify['receive_locker_product'].message,
                Lang.notify['receive_locker_product'].type)
        else
            Framework.notify(source, Lang.notify['no_inventory_weight'].message, Lang.notify['no_inventory_weight'].type)
        end
    end
end


---@param source integer
---@param notify string
---@param type string
Framework.notify = function(source, notify, type)
    if Config.notifySystem == 'vrp' then
        vRPclient.notify(source, { notify, type })
    else
        print('ERRROR: Please edit your custom notify system (server/framework/vrp.lua)')
    end
end


Framework.playerSpawn = function()
    AddEventHandler('vRP:playerSpawn', function(user_id, source, firstSpawn)
        if firstSpawn then
            if exports.axr_octastore:getPlayerPlan(user_id) > 0 then
                exports.axr_octastore:checkPlayerRemaningTimePlan(user_id);
            end
        end
    end)
end

-- Do not remove this line if you want the plans to expire monthly
Framework.playerSpawn();

Client

if Config.Framework ~= 'vrp' then
    return
end

vRP = Proxy.getInterface("vRP")

Last updated