Accueil › Documentation › Installation · origen_inventory

Installation · origen_inventory

Suis les étapes ci-dessous pour installer origen_inventory sur ton serveur.


1. Ajoute la ressource à ton serveur

Copie le dossier origen_inventory dans ton répertoire de ressources et ajoute-le à ton server.cfg.

L’ordre des ensure est important : toutes les dépendances doivent tourner avant origen_inventory.

cfg
# server.cfg
 
ensure oxmysql
ensure ox_lib
ensure qb-core            # or es_extended / qbx_core
 
# Optional integrations
ensure qs-smartphone-pro  # or lb-phone
ensure origen_clothing    # only if you use Clothes-As-Item
 
ensure origen_inventory

Ne démarre jamais origen_inventory avant oxmysql et le cœur de ton framework. Sans eux, le pilote de base de données et la couche de bridge ne s’initialiseront pas et les inventaires ne se chargeront pas.


2. Remplace ton ancien inventaire

Si tu migres depuis une autre ressource d’inventaire, tu dois la supprimer (ou la désactiver) avant de démarrer origen_inventory. Il ne peut y avoir qu’un seul fournisseur d’inventaire actif à la fois.

Si d’autres scripts dépendent des exports de qb-inventory ou ox_inventory, ouvre fxmanifest.lua et décommente la ligne provide correspondante pour que ces appels d’exports soient résolus vers origen_inventory :

lua
-- Uncomment if you have old scripts that use qb-inventory
-- provide 'qb-inventory'
 
-- Uncomment if you have qbx_core installed
-- provide 'ox_inventory'

3. Importe le schéma SQL

Importe le fichier origen_inventory.sql dans ta base de données. Il crée les quatre tables nécessaires à la ressource : gloveboxitems, stashitems, trunkitems, origen_customitems et origen_inventory_equipped_clothes.

sql
CREATE TABLE IF NOT EXISTS `gloveboxitems` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `plate` VARCHAR(255) NOT NULL COLLATE 'latin1_swedish_ci',
    `items` LONGTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
    `label` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    `slots` INT(11) NULL DEFAULT NULL,
    `personal` VARCHAR(255) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    `weight` INT(11) NULL DEFAULT NULL,
    `job` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    PRIMARY KEY (`plate`) USING BTREE,
    INDEX `id` (`id`) USING BTREE
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=152;
 
CREATE TABLE IF NOT EXISTS `stashitems` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `stash` VARCHAR(255) NOT NULL COLLATE 'latin1_swedish_ci',
    `items` LONGTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
    `label` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    `slots` INT(11) NULL DEFAULT NULL,
    `job` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    `personal` VARCHAR(255) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    `weight` INT(11) NULL DEFAULT NULL,
    PRIMARY KEY (`stash`) USING BTREE,
    INDEX `id` (`id`) USING BTREE
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1;
 
CREATE TABLE IF NOT EXISTS `trunkitems` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `plate` VARCHAR(255) NOT NULL COLLATE 'latin1_swedish_ci',
    `items` LONGTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
    `label` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    `personal` VARCHAR(255) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    `weight` INT(11) NULL DEFAULT NULL,
    `slots` INT(11) NULL DEFAULT NULL,
    `job` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_swedish_ci',
    PRIMARY KEY (`plate`) USING BTREE,
    INDEX `id` (`id`) USING BTREE
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1;
 
DROP TABLE IF EXISTS `origen_customitems`;
CREATE TABLE `origen_customitems` (
    `name` VARCHAR(100) NOT NULL COLLATE 'utf8mb4_unicode_ci',
    `label` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
    `weight` INT(11) NOT NULL DEFAULT '0',
    `type` VARCHAR(50) NOT NULL DEFAULT 'item' COLLATE 'utf8mb4_unicode_ci',
    `image` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
    `description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
    `unique` TINYINT(1) NOT NULL DEFAULT '0',
    `rarity` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
    `stack` TINYINT(1) NOT NULL DEFAULT '0',
    `close` TINYINT(1) NOT NULL DEFAULT '1',
    `server` LONGTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
    `client` LONGTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
    `decay` INT(11) NULL DEFAULT NULL,
    `buttons` LONGTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
    PRIMARY KEY (`name`) USING BTREE,
    CONSTRAINT `server` CHECK (json_valid(`server`)),
    CONSTRAINT `client` CHECK (json_valid(`client`)),
    CONSTRAINT `buttons` CHECK (json_valid(`buttons`))
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;
 
CREATE TABLE IF NOT EXISTS `origen_inventory_equipped_clothes` (
    `identifier` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_unicode_ci',
    `data` LONGTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
    `last_updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`identifier`) USING BTREE,
    CONSTRAINT `data_json` CHECK (json_valid(`data`))
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;

origen_customitems est supprimée puis recréée par le fichier d’import. Si tu as déjà des objets personnalisés enregistrés, sauvegarde-les avant de relancer le SQL.


4. Objets

origen_inventory fournit son propre dictionnaire d’objets (config/items.lua et config/weapons.lua). Quand tu remplaces ton ancien inventaire :


5. Configuration du bridge ESX

Cette étape n’est nécessaire que si tu utilises ESX (es_extended). Les utilisateurs de QBCore et QBX peuvent passer directement à l’étape 6.

origen_inventory fournit deux fichiers d’override à placer dans es_extended pour que le framework délègue tous les appels d’inventaire à origen_inventory plutôt qu’à son inventaire intégré.

Où placer les fichiers

Copie les deux fichiers du dossier bridge/esx/overrides/ de origen_inventory dans ta ressource es_extended :

Fichier source (dans origen_inventory) Destination (dans es_extended)
bridge/esx/overrides/origeninventory.lua es_extended/overrides/origeninventory.lua
bridge/esx/overrides/origeninventory_player.lua es_extended/overrides/origeninventory_player.lua

Assure-toi ensuite que les deux fichiers sont déclarés dans es_extended/fxmanifest.lua sous server_scripts :

lua
-- es_extended/fxmanifest.lua
server_scripts {
  -- ... existing entries ...
  'overrides/origeninventory.lua',
  'overrides/origeninventory_player.lua',
}

Rôle de chaque fichier

origeninventory.lua — remplace les fonctions d’objets et d’objets utilisables d’ESX pour que les appels à ESX.GetItemLabel, ESX.RegisterUsableItem et ESX.UseItem soient redirigés vers origen_inventory au lieu du dictionnaire ESX par défaut. Il gère aussi l’argent de départ des comptes et les objets de départ de l’inventaire pour les nouveaux personnages.

lua
if Config.CustomInventory ~= "origen_inventory" then return end
 
MySQL.ready(function()
    TriggerEvent("__cfx_export_origen_inventory_Items", function(ref)
        if ref then
            ESX.Items = exports.origen_inventory:Items()
        end
    end)
end)
 
---@diagnostic disable-next-line: duplicate-set-field
ESX.GetItemLabel = function(itemName)
    local item = exports.origen_inventory:Items(itemName)
    if item then
        return item.label
    end
 
    print(('[^3WARNING^7] Attemting to get invalid Item -> ^5%s^7'):format(itemName))
end
 
---@diagnostic disable-next-line: duplicate-set-field
function ESX.RegisterUsableItem(item, cb)
    Core.UsableItemsCallbacks[item] = cb
    exports.origen_inventory:CreateUseableItem(item, cb)
end
 
---@diagnostic disable-next-line: duplicate-set-field
function ESX.UseItem(source, item, ...)
    local src, itm = source, item
    if type(src) == 'string' then item = src source = itm end
 
    if ESX.Items[item] then
        return exports['origen_inventory']:UseItem(item, source, ...)
    else
        print(('[^3WARNING^7] Item ^5"%s"^7 was used but does not exist!'):format(item))
    end
end
 
exports("GetUseablesItems", function()
    return Core.UsableItemsCallbacks
end)
 
function setPlayerInventory(playerId, xPlayer, inventory, isNew)
    if isNew then
        local shared = json.decode(GetConvar("inventory:accounts", '"money"'))
 
        for i = 1, #shared do
            local name = shared[i]
            local account = Config.StartingAccountMoney[name]
            if account then
                exports.origen_inventory:AddItem(playerId, name, account)
            end
        end
 
        if Config.StartingInventoryItems and type(Config.StartingInventoryItems) == "table" then
            for item, count in pairs(Config.StartingInventoryItems) do
                exports.origen_inventory:AddItem(playerId, item, count)
            end
        end
    end
end

origeninventory_player.lua — injecte Core.PlayerFunctionOverrides.OrigenInventory, qui remplace les méthodes d’inventaire du joueur par défaut (getInventory, addInventoryItem, removeInventoryItem, hasItem, addWeapon, canCarryItem, etc.) par leurs équivalents origen_inventory. Ainsi, tout appel interne d’ESX touchant à l’inventaire du joueur passe par origen_inventory.

lua
------ Dont touch this file unless you know what you are doing
------ This file is used to override the inventory functions
---
---
---- Origen_File_Version - 4
---
---
if Config.CustomInventory ~= "origen_inventory" then return end
 
Core.PlayerFunctionOverrides.OrigenInventory = {
  getInventory = function(self)
    return function(minimal)
      local inventory = exports.origen_inventory:GetPlayerInventory(self.source)
      return inventory
    end
  end,
 
  getLoadout = function(self)
    return function()
      return {}
    end
  end,
 
  getInventoryItem = function(self)
    return function(name, metadata)
      local item = exports.origen_inventory:getItem(self.source, name)
      if not item then
        return {
          count = 0,
        }
      end
      return item
    end
  end,
 
  addInventoryItem = function(self)
    return function(name, count, metadata, slot)
      return exports.origen_inventory:AddItem(self.source, name, count or 1, metadata, slot, true)
    end
  end,
 
  removeInventoryItem = function(self)
    return function(name, count, metadata, slot)
      return exports.origen_inventory:RemoveItem(self.source, name, count or 1, metadata, slot, false)
    end
  end,
 
  setInventoryItem = function(self)
    return function(name, count, metadata)
      return exports.origen_inventory:SetInventoryItems(self.source, name, count, metadata)
    end
  end,
 
  save = function(self)
    return function(inventory)
      Core.SavePlayer(self)
    end
  end,
 
  canCarryItem = function(self)
    return function(name, count, metadata)
      return exports['origen_inventory']:CanCarryItem(self.source, name, count)
    end
  end,
 
  canSwapItem = function(self)
    return function(firstItem, firstItemCount, testItem, testItemCount)
      return true
    end
  end,
 
  setMaxWeight = function(self)
    return function() end
  end,
 
  addWeapon = function(self)
    ---@param weaponName item weapon
    ---@param ammo amount
    return function(weaponName, ammo)
      return exports['origen_inventory']:GiveWeaponToPlayer(self.source, weaponName, ammo)
    end
  end,
 
  addWeaponComponent = function(self)
    return function() end
  end,
 
  addWeaponAmmo = function(self)
    return function() end
  end,
 
  updateWeaponAmmo = function(self)
    return function() end
  end,
 
  setWeaponTint = function(self)
    return function() end
  end,
 
  getWeaponTint = function(self)
    return function() end
  end,
 
  removeWeapon = function(self)
    return function() end
  end,
 
  removeWeaponComponent = function(self)
    return function() end
  end,
 
  removeWeaponAmmo = function(self)
    return function() end
  end,
 
  hasWeaponComponent = function(self)
    return function()
      return false
    end
  end,
 
  hasWeapon = function(self)
    return function()
      return false
    end
  end,
 
  hasItem = function(self)
    return function(name, metadata)
      return exports.origen_inventory:getItem(self.source, name, metadata)
    end
  end,
 
  getWeapon = function(self)
    return function() end
  end,
}

Les deux fichiers se protègent avec if Config.CustomInventory ~= "origen_inventory" then return end : tu peux donc les laisser en place si tu changes un jour d’inventaire, ils ne feront simplement rien.


6. Configure la ressource

Ouvre config.lua, config_sv.lua et les fichiers du dossier config/ et adapte-les à ton serveur. Consulte la page Configuration pour la liste complète des options.

Le minimum à vérifier avant la mise en production :


7. Vérifie l’installation

Après avoir démarré le serveur, connecte-toi avec un joueur et vérifie que :