API
Functions, exports and events the Yecoyz scripts and your own resources can use.
A resource uses Core by loading the import file in its fxmanifest.lua:
shared_script '@yecoyz_core/import.lua'
dependency 'yecoyz_core'That gives the resource a global Core. Every function below is available as Core.<Name>(...). You can also call it as an export, exports.yecoyz_core:<Name>(...), if your resource doesn't load the import.
Core.Framework -- 'esx' | 'qbox' | 'qb' | 'standalone'
Core.GetIdentifier(source) -- any function below, called as Core.<Name>(...)Server functions
| Function | Returns |
|---|---|
GetFramework() / GetInventory() |
'esx', 'qb', 'qbox', 'standalone' / 'ox_inventory', 'framework' |
GetObject() |
The ESX or QBCore object (nil on Qbox; use exports.qbx_core) |
GetPlayer(source) |
The framework's player object |
GetPlayerFromIdentifier(id) / GetSourceFromIdentifier(id) |
Player object / server id of an online character |
IsPlayerLoaded(source) |
A character is loaded |
GetIdentifier(source) |
Character id: ESX identifier, QBCore / Qbox citizenid, standalone license |
GetAccountIdentifier(source) |
The account the characters belong to (ESX license without prefix, QB license:...) |
GetLicense(source) |
license:... |
GetPlayers() |
Server ids of every loaded player |
GetCharacter(source) |
{ firstname, lastname, dob, sex, phone, nationality }, with sex 0 male / 1 female |
GetName(source) / GetFullName(source) |
first, last / 'First Last' (falls back to the player name) |
GetJob(source) |
{ name, label, grade, gradeName, gradeLabel, salary, onDuty, isBoss } |
HasJob(source, jobs, minGrade) |
jobs: 'police', { 'police', 'sheriff' } or { police = 2 } (minimum grade) |
GetJobs() / GetJobLabel(job, grade) |
All jobs / jobLabel, gradeLabel |
GetPlayersByJob(job, onDutyOnly) |
Server ids |
SetJob(source, job, grade) / SetDuty(source, onDuty) |
true on success |
GetMoney(source, account) |
Accounts: 'cash' (default), 'bank', or any framework account |
AddMoney(source, amount, account, reason) |
true on success |
RemoveMoney(source, amount, account, reason) |
false if the player doesn't have enough |
GetItemCount(source, item, metadata) |
ox_inventory, otherwise the framework inventory |
HasItem(source, item, count, metadata) |
item can be a list: true if they have any of them |
CanCarryItem / AddItem / RemoveItem (source, item, count, metadata) |
RemoveItem only removes when the player has enough |
RegisterUsableItem(item, fn(source, data)) |
Framework usable item (ox_inventory items are set in its item data) |
Notify(source, message, type, duration, title) |
type: 'info', 'success', 'error' or 'warning' |
HasPermission(source, permission) |
Ace, or the ESX group / QBCore permission |
Login(source, identifier, data) / Logout(source) |
For multicharacter: ESX identifier is the prefix (char1), QB / Qbox the citizenid |
Client functions
| Function | Returns |
|---|---|
GetFramework() / GetInventory() / GetObject() |
Same as the server |
IsPlayerLoaded() |
A character is loaded |
GetPlayerData() |
The framework's raw player data |
GetIdentifier(), GetJob(), HasJob(jobs, minGrade) |
Same shapes as the server |
GetCharacter(), GetName(), GetFullName(), GetSex() |
GetSex(): 0 male / 1 female |
GetMoney(account), GetItemCount(item), HasItem(item, count) |
From the player data or ox_inventory. Do the real checks on the server. |
Notify(message, type, duration, title) |
ox_lib, the framework, or the GTA feed (Config.Notify) |
DisableSpawnManager() |
Turns off spawnmanager's auto spawn |
Events
Use these instead of esx:playerLoaded, QBCore:Client:OnPlayerLoaded and the rest. They fire the same way on every framework.
Core.OnPlayerLoaded(function(source) end) -- server; the client gets no arguments
Core.OnPlayerUnloaded(function(source) end) -- server; the client gets no arguments
Core.OnJobUpdated(function(source, job, lastJob) end) -- server; client: function(job)The event names are yecoyz_core:server:playerLoaded, :playerUnloaded, :jobUpdated, and the same names with client.
Callbacks
Callbacks replace lib.callback. Names are global across resources, so prefix them with the resource name, for example yecoyz_duty:getHistory.
-- server
Core.Callback.Register('yecoyz_duty:getHistory', function(source, filter)
return MySQL.query.await('...'), os.time() -- any number of values, nil included
end)
-- client
local history, now = Core.Callback.Await('yecoyz_duty:getHistory', 'week')
Core.Callback.Trigger('yecoyz_duty:getHistory', function(history, now) end, 'week')The other direction works the same, with the player as the second argument:
-- client
Core.Callback.Register('yecoyz_radar:getPlate', function() return GetVehicleNumberPlateText(...) end)
-- server
local plate = Core.Callback.Await('yecoyz_radar:getPlate', source)
Core.Callback.Trigger('yecoyz_radar:getPlate', source, function(plate) end)| Server | Client | |
|---|---|---|
| Register | Register(name, fn(source, ...)) |
Register(name, fn(...)) |
| Await | Await(name, source, ...) |
Await(name, ...) |
| Trigger | Trigger(name, source, cb, ...) |
Trigger(name, cb, ...) |
Awaitmust run in a thread. Event handlers, commands, NUI callbacks andCreateThreadall are.- No answer within
Core.Callback.Timeoutms (10000 by default, per resource) givesniland a console warning. That usually means the callback isn't registered on the other side. - A handler that errors prints the error and answers with no values right away, so the caller doesn't wait for the timeout.
- On the server, only the player who was asked can answer. Pending requests to a player who leaves end with
nil. - Registering a name again replaces the handler.
Core.Callback.Unregister(name)andCore.Callback.IsRegistered(name)are there too.