mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
Since this is being developed alongside other projects, adding a version checker is going to save some time.
2.1 KiB
2.1 KiB
WIP Lua Library
The idea of this resource is to create a set of reusable functions for importing into other resources. Though FiveM has its own system for importing files (which is used to load init), this simplifies declarations and allows you to keep everything as locals rather than polluting the global namespace.
Everyone is free to utilise either the library or code from it so long as the license is respected and adhered to.
- Server Callbacks
- Table utilities
- OxMySQL library
- Native wrappers (animations, spawning, onesync, etc.)
- Iterators
- Exports (for non-runtime critical functions)
To do
- Think of more features
- Improvements to import function?
- Improve table utilities (matches doesn't work properly for hash tables)
- Transfer non-essential code from ox inventory
How to utilise ServerCallbacks
- fxmanifest.lua
fx_version 'cerulean'
game 'gta5'
author 'You'
version '1.0.0'
lua54 'yes'
use_fxv2_oal 'yes'
shared_script '@pe-lualib/init.lua'
files {
'client.lua',
'shared.lua',
}
- client.lua
local ServerCallback = import 'callbacks'
ServerCallback.Async(targetresource, 'eventname', 100, function(result)
print(result) -- 'hello there. general kenobi'
end, 'hello there')
CreateThread(function()
local a, b, c = ServerCallback.Await('test', 'testevent', 100, 'hello there')
print(a, b, c) -- 'hello there. general kenobi', 'two', nil
end)
- server.lua
local ServerCallback = import 'callbacks'
ServerCallback.Register('eventname', function(source, cb, data)
cb(data..'. general kenobi', 'two')
end)