Framework Class
A powerfull library to build a script compatible with all Frameworks. The module architecture is based on a folder structure, with one folder per framework. With this structure, the data from one framework can't intefere with date from another one.
INFO
The framework is automatically detected once the module is started based on resource in the server.
TIP
If you have a custom framework, you can overwrite methods by added the one you want edit inside _custom/FrameworkClass.lua
file.
List of compatible frameworks
- VORP
- RedEM:RP old
- RedEM:RP 2023 (reboot)
- QBR
- QR
- RSG
- RPX
Configuration Variables (Convars)
Convar | Side | Type | Default | Description |
---|---|---|---|---|
jo_libs:framework | Shared | String | false | Force the framework |
jo.framework Methods
jo.framework:addItemInInventory()
Adds a specific item to a custom inventory with optional metadata and wait parameter
Syntax
jo.framework:addItemInInventory(source, invId, item, quantity, metadata, needWait)
Parameters
source
: integer
The source ID of the player
invId
: string
The unique ID of the inventory
item
: string
The name of the item
quantity
: integer
The quantity of the item
metadata
: table Optional
The metadata of the item
needWait
: boolean Optional
If need to wait after the SQL insertion
default:false
Example
local source = 1
local id = "locker:sheriff"
local item = "mdt_report"
local quantity = 1
local metadata = { id = 321 }
jo.framework:addItemInInventory(source, id, item, quantity, metadata)
jo.framework:addMoney()
Adds money to a player
Syntax
jo.framework:addMoney(source, amount, moneyType)
Parameters
source
: integer
The source ID of the player
amount
: number
The amount of money to add
moneyType
: integer Optional
0
: dollar,1
: gold,2
: rol
default:0
Return Value
Type : boolean
Return
true
if the money is successfully added
Example
local source = 1
local amount = 10.5
local moneyType = 0
local isAdded = jo.framework:addMoney(source,amount,moneyType)
print(isAdded)
jo.framework:canUseItem()
Checks if a player has the required quantity of a specific item in their inventory and optionally removes it
Syntax
jo.framework:canUseItem(source, item, amount, meta, remove)
Parameters
source
: integer
The source ID of the player
item
: string
The name of the item need to use
amount
: integer
The quantity of the item
meta
: table Optional
The metadata of the item
remove
: boolean Optional
If the item has to be removed
default:false
Return Value
Type : boolean
Return
true
if the player has enough quantity of the item
Example
local source = 1
local item = "water"
local amount = 1
local canUseWater = jo.framework:canUseItem(source, item, amount, nil, nil)
print(canUseWater)
jo.framework:canUserBuy()
Checks if a player has sufficient funds of a specified currency type
Syntax
jo.framework:canUserBuy(source, amount, moneyType, removeIfCan)
Parameters
source
: integer
The source ID of the player
amount
: number
The amount of money the player needs to have
moneyType
: integer Optional
0
: dollar,1
: gold,2
: rol
default:1
removeIfCan
: boolean Optional
Remove the money if the player has enough
default:false
Return Value
Type : boolean
Return
true
if the player has more money than the amount
Example
local price = 103
local source = 1
print(jo.framework:canUserBuy(source, 103))
-- Expected output : true if the player has more than $103
jo.framework:createInventory()
Creates a custom inventory with configurable slots, weight limits, and item restrictions
Syntax
jo.framework:createInventory(invName, name, invConfig)
Parameters
invName
: string
Unique id of the inventory
name
: string
Label of the inventory
invConfig
: table
Configuration of the inventory
invConfig.maxSlots
: integer - Max slot of the inventory
invConfig.maxWeight
: float - Max weight of the inventory
invConfig.acceptWeapons
: boolean - Whether the inventory accepts weapons Optional
invConfig.shared
: boolean - If the inventory is shared between players Optional
invConfig.ignoreStackLimit
: boolean - If the inventory can overcoming stack limits Optional
invConfig.whitelist
: table - Restrict the list of items that can be put in the inventory Optional
invConfig.whitelistˌ_x_ˌitem
: string - Name of the whitelisted item
invConfig.whitelistˌ_x_ˌlimit
: integer - Stack limit of this item
Example
local id = "locker:sheriff"
local label = "Sheriff's locker"
local definition = {
maxSlots = 100,
maxWeight = 1000.0,
acceptWeapons = false,
shared = true,
whitelist = {
{ item = "mdt_report", limit = 1000 }
}
}
jo.framework:createInventory(id, label, definition)
jo.framework:get()
Returns the name of the current active framework being used
Syntax
jo.framework:get()
Return Value
Type : string
Return the name of the current framework :
"VORP"
or"RedEM"
or"RedEM2023"
or"qbr"
or"rsg"
or"qr"
or"rpx"
Example
local frameworkName = jo.framework:get()
print(frameworkName)
jo.framework:getItemsFromInventory()
Retrieves all items from a specific inventory with their quantities and metadata
Syntax
jo.framework:getItemsFromInventory(invId)
Parameters
invId
: string
The unique ID of the inventory
Return Value
Type : table
Return the list of items with structure :
item.amount
: integer - The amount of the item
item.id
: integer - The id of the itemitem.item
: string - The name of the itemitem.metadata
: table - The metadata of the item
Example
local source = 1
local id = "locker:sheriff"
local items = jo.framework:getItemsFromInventory(source, id)
for key, item in pairs(items) do
print(item.item)
end
jo.framework:getJob()
Returns the current job assigned to a player
Syntax
jo.framework:getJob(source)
Parameters
source
: integer
The source ID of the player
Return Value
Type : string
Return the job name of the player
Example
local source = 1
print(jo.framework:getJob(source))
jo.framework:getRPName()
Returns the roleplay name (first and last name) of the player
Syntax
jo.framework:getRPName(source)
Parameters
source
: integer
The source ID of the player
Return Value
Type : string
Return the formatted first and last name of the player
Example
local source = 1
print(jo.framework:getRPName(source))
jo.framework:getUser()
Retrieves a player's full UserClass object containing all player data and methods
Syntax
jo.framework:getUser(source)
Parameters
source
: integer
The source ID of the player
Return Value
Type : UserClass
Return a User class object containing player data and methods
Example
local source = 1
local user = jo.framework:getUser(source)
print(user:getRPName())
jo.framework:getUserClothes()
Retrieves a player's clothing data with standardized category names
Syntax
jo.framework:getUserClothes(source)
Parameters
source
: integer
The source ID of the player
Return Value
Type : table
Return the list of clothes with standardized categories and properties
Example
local source = 1
local clothes = jo.framework:getUserClothes(source)
print(json.encode(clothes))
jo.framework:getUserIdentifiers()
Retrieves all identifiers associated with a player
Shortcut for jo.framework.UserClass:getIdentifiers() method
Syntax
jo.framework:getUserIdentifiers(source)
Parameters
source
: integer
The source ID of the player
Return Value
Type : table
Return the player's identifiers
identifiers.identifier
- Unique identifier of the player
identifiers.charid
- Unique id of the player
Example
local source = 1
local identifiers = jo.framework:getUserIdentifiers(source)
print(identifiers.charid)
jo.framework:getUserSkin()
Retrieves a player's skin data with standardized properties and formatting
Syntax
jo.framework:getUserSkin(source)
Parameters
source
: integer
The source ID of the player
Return Value
Type : table
Return the skin data
Example
local source = 1
local skin = jo.framework:getUserSkin(source)
print(json.encode(skin))
jo.framework:giveItem()
Adds an item to a player's inventory with optional metadata
Syntax
jo.framework:giveItem(source, item, quantity, meta)
Parameters
source
: integer
The source ID of the player
item
: string
The name of the item
quantity
: integer
The amount of the item to give
meta
: table Optional
The metadata of the item
Return Value
Type : boolean
Return
true
if the item is successfully given
Example
local source = 1
local item = "water"
local amount = 1
local itemGave = jo.framework:giveItem(source, item, amount)
print(itemGave)
jo.framework:is()
Compares the current framework with a specified framework name
Syntax
jo.framework:is(name)
Parameters
name
: string
The name of the framework to check against
Supported frameworks :
"VORP"
or"RedEM"
or"RedEM2023"
or"qbr"
or"rsg"
or"qr"
or"rpx"
Return Value
Type : boolean
Return
true
if the current framework matches the name
Example
local isVORP = jo.framework:is('VORP')
print(isVORP)
jo.framework:onCharacterSelected()
Callback when a character is selected
Syntax
jo.framework:onCharacterSelected(cb)
Parameters
cb
: function
The callback function triggered when the character is selected
Example
jo.framework:onCharacterSelected(function(source)
print('A new player select his character', source)
end)
jo.framework:openInventory()
Opens a specific inventory
Syntax
jo.framework:openInventory(source, invName)
Parameters
source
: integer
The source ID of the player
invName
: string
The unique ID of the inventory
Example
local source = 1
local id = "locker:sheriff"
jo.framework:openInventory(source, id)
jo.framework:registerUseItem()
Registers an item as usable and attaches a callback function that executes when the item is used
Syntax
jo.framework:registerUseItem(item, closeAfterUsed, callback)
Parameters
item
: string
The name of the item
closeAfterUsed
: boolean Optional
If the inventory needs to be closed after using the item
default:true
callback
: function
The function fired after use the item
1st argument: source
2nd argument: metadata of the item
Example
jo.framework:registerUseItem('water', true, function(source, metadata)
TriggerServerEvent('drinkWater', source)
jo.framework:removeItem(source, 'water', 1, metadata)
end)
jo.framework:removeInventory()
Removes an inventory from the server cache, useful for reloading inventory data from the database
Syntax
jo.framework:removeInventory(invName)
Parameters
invName
: string
Unique id of the inventory
Example
local id = "locker:sheriff"
jo.framework:removeInventory(id)
jo.framework:removeItem()
Removes an item from a player's inventory if they have enough quantity
Syntax
jo.framework:removeItem(source, item, quantity, meta)
Parameters
source
: integer
The source ID of the player
item
: string
The name of the item to remove
quantity
: integer
The quantity of the item to remove
meta
: table Optional
The metadata of the item
Return Value
Type : boolean
Return
true
if the item is successfully removed
Example
local source = 1
local item = "water"
local quantity = 2
local meta = {}
local isRemoved = jo.framework:removeItem(source, item, quantity, meta)
print(isRemoved)
jo.framework:removeMoney()
Removes money from a player's account
Syntax
jo.framework:removeMoney(source, amount, moneyType)
Parameters
source
: integer
The source ID of the player
amount
: number
The amount of money to remove
moneyType
: integer Optional
0
: dollar,1
: gold,2
: rol
default:0
Return Value
Type : boolean
Return
true
if the money is successfully removed
Example
local source = 1
local amount = 10.5
local moneyType = 0
local isRemoved = jo.framework:removeMoney(source, amount, moneyType)
print(isRemoved)
jo.framework:revertClothes()
Converts standardized clothing data back to framework-specific format
Syntax
jo.framework:revertClothes(standard)
Parameters
standard
: table
The standardized clothes data
Return Value
Type : table
Return clothes data with framework-specific keys
Example
local clothes = {hats = {hash = 0x123455}}
local frameworkData = jo.framework:revertClothes(clothes)
log(frameworkData)
jo.framework:revertSkin()
Converts standardized skin data back to framework-specific format
Syntax
jo.framework:revertSkin(standard)
Parameters
standard
: table
The standardized skin data
Return Value
Type : table
Return skin data with framework-specific keys
Example
local skin = {headIndex = 1, skinTone = 2}
local frameworkSkin = jo.framework:revertSkin(skin)
log(frameworkSkin)
jo.framework:standardizeClothes()
Converts framework-specific clothing data to a standardized format
Syntax
jo.framework:standardizeClothes(clothes)
Parameters
clothes
: table
The framework-specific clothes data
Return Value
Type : table
Return clothes data with standardized keys and structure
Example
local clothes = { Hat = 0x12345}
local standard = jo.framework:standardizeClothes(clothes)
log(standard)
-- Expected output: `{hat = {hash = 0x12345}}`
jo.framework:standardizeSkin()
Converts framework-specific skin data to a standardized format
Syntax
jo.framework:standardizeSkin(skin)
Parameters
skin
: table
The framework-specific skin data
Return Value
Type : table
Return skin data with standardized keys for components, overlays, and expressions
Example
local skin = { eyes = 0x1234}
local standard = jo.framework:standardizeSkin(skin)
log(standard)
-- Expected output: `{eyesIndex: 2}`
jo.framework:updateUserClothes()
Save new clothes.
The function has two ways to work:
- With 2 arguments to save multiple clothes
- With 3 arguments to save one piece of clothing
Syntax
jo.framework:updateUserClothes(source, _clothes, value)
Parameters
source
: integer
The source ID of the player
_clothes
: table
The list of clothes to apply or the category name
value
: table Optional
The clothing data if updating a single category
Example
local source = 1
local clothes = {
pants = { hash = 2450348132 },
boots = { hash = 3596743543 }
}
jo.framework:updateUserClothes(source, clothes)
-- OR --
local source = 1
local category = pants
local clothes = { hash = 2450348132 }
jo.framework:updateUserClothes(source, category, clothes)
jo.framework:updateUserSkin()
Save new skin values.
The function has two ways to work:
- With 3 arguments to save multiple skin data
- With 4 arguments to save only one skin data
Syntax
jo.framework:updateUserSkin(...)
Parameters
source
: integer
The source ID of the player
skinData
: table
The list of skin data with category for key and skin data for value
category
: string
The category of the skin data
data
: table
The skin data
overwrite
: boolean Optional
If
true
, the new value overwrites the previous skin. Else, it's merged
Example
local source = 1
local skin = {
head = 394785690,
torso = 345823423
}
local overwrite = false
jo.framework:updateUserSkin(source, skin, overwrite)
-- OR --
local source = 1
local category = "head"
local data = 394785690
local overwrite = false
jo.framework:updateUserSkin(source, category, data, overwrite)
UserClass Methods
Documentation for the User