Framework Class
A powerfull library to build a script compatible with all Frameworks.
INFO
The class is automatically initiated when you load the library under the jo.framework
global variable.
TIP
If you have a custom framework, you can overwrite methods by added them in the overwrite-functions.lua file.
Read more about OWFramework.
Syntax
function OWFramework.<MethodName>()
Example
--Overwrite the getUser method
function OWFramework.getUser(source)
return yourFramework:getUser(source)
end
List of compatible frameworks
- VORP
- RedEM:RP old
- RedEM:RP 2023 (reboot)
- QBR
- QR
- RSG
- RPX
jo.framework:addItemInInventory
Add a specific item in a custom inventory
Syntax
jo.framework:addItemInInventory(source,id,item,quantity,metadata,needWait)
Parameters
source
: integer
The source ID of the player
id
: string
The unique ID of the inventory
item
: string
The name of the item
quantity
: integer
The quantity of the item
metadata
: table
The metadata of the item
needWait
: boolean Optional
If the function need to wait the MySQL injected to ending
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:canUseItem()
If the user has enough quantity of a specific item in his inventory
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:createInventory()
Function to create an inventory
Syntax
jo.framework:createInventory(id,label,definition)
Parameters
id
: string
Unique id of the inventory
label
: string
Label of the inventory
definition
: table
definition.maxSlots
: integer - Max slot of the inventorydefinition.maxWeight
: float - Max weight of the inventorydefinition.acceptWeapons
: boolean (default: false) - If the inventory accept weapons Optionaldefinition.shared
: boolean (default: true) - If the inventory is shared between players Optionaldefinition.ignoreStackLimit
: boolean (default: true) - If the inventory can overcoming stack limits Optionaldefinition.whitelist
: table - Restrict the list of item can be put in the inventory Optional
definition.whitelist[..].item
: string - name of the whitelisted itemdefinition.whitelist[..].limit
: string - stack limit of this itemConfiguration of the inventory
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:doesUserCanBuy()
A function to know if a specific user has enough money
Syntax
jo.framework:doesUserCanBuy(source,amount,moneyType)
Parameters
source
: integer
The source ID of the player
amount
: float
The amount of money the player need to have
moneyType
: integer Optional
moneyType = 0 > dollar
moneyType = 1 > gold
moneyType = 2 > rol
default : 1
Return value
Type: boolean
Return
true
if the player has more money thanamount
Example
local price = 103
local source = 1
print(jo.framework:doesUserCanBuy(source,103))
-- Expected output : true if the player has more than $103
jo.framework:get()
Get the framework name
Syntax
jo.framework:get()
Return value
Type: string
Return the name of the framework
Example
local frameworkName = jo.framework:get()
print(frameworkName)
jo.framework:getJob()
Return the playe rjob
Syntax
jo.framework:getJob(source)
Parameters
source
: integer
The source ID of the player
Return value
Type: string
Return the job name
Example
local source = 1
print(jo.framework:getJob(source))
jo.framework:getRPName()
Return the first & last name of tha player
Syntax
jo.framework:getRPName(source)
Parameters
source
: integer
The source ID of the player
Return value
Type: string
Return the first & last name of a player
Example
local source = 1
print(jo.framework:getRPName(source))
jo.framework:getUserIdentifiers()
Shortcut for User:getIdentifiers() method
Syntax
jo.framework:getUserIdentifiers(source)
Parameters
source
: integer
The source ID of the player
Return value
Type: table
Return the same value than User:getIdentifiers() method
Example
local source = 1
local identifiers = jo.framework:getUserIdentifiers(source)
print(identifiers.charid)
jo.framework:getItemsFromInventory()
Get the list of items included in a custom inventory
Syntax
jo.framework:getItemsFromInventory(source,id)
Parameters
source
: integer
The source ID of the player
id
: string
The unique ID of the inventory
Return value
Type: table
Return the list of items
The item structure:
item.amount
: integer - The amount of the itemitem.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:getUser()
Get the user data
Syntax
jo.framework:getUser(source)
Parameters
source
: integer
The source ID of the player
Return value
type: User
Return a User class
Example
local source = 1
local user = jo.framework:getUser(source)
print(user.data.firstname)
jo.framework:giveItem()
Give an item to the user
Syntax
jo.framework:giveItem(source,item,amount,meta)
Parameters
source
: integer
The source ID of the player
item
: string
The name of the item
amount
: 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 gave
Example
local source = 1
local item = "water"
local amount = 1
local itemGave = jo.framework:giveItem(source,item,amount)
print(itemGave)
jo.framework:is()
Test if the framework is a specific framework
Syntax
jo.framework:is(name)
Parameters
name
: string
The name of the framework
Return value
type: boolean
Return
true
if the framework isname
Example
local isVORP = jo.framework:is('VORP')
print(isVORP)
jo.framework:openInventory()
Open a specific inventory
Syntax
jo.framework:openInventory(source,id)
Parameters
source
: integer
The source ID of the player
id
: string
The unique ID of the inventory
Example
local source = 1
local id = "locker:sheriff"
jo.framework:openInventory(source,id)
jo.framework:registerUseItem()
Register an item has usable and attach a function to it
Syntax
jo.framework:registerUseItem(item,closeAfterUsed,cb)
Parameters
item
: string
The name of the item
closeAfterUsed
: boolean Optional
If the inventory needs to be closed after using the item default: true
cb
: 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()
Remove the inventory from the server cache. Usefull to reload the inventory from the database
Syntax
jo.framework:removeInventory(id)
Parameters
id
: string
Unique id of the inventory
Example
local id = "locker:sheriff"
jo.framework:removeInventory(id)
User class
Go to the User class documentation : link