From fd5ccc4964db306b2e47336192a2fa791d55f52a Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Tue, 1 Mar 2022 21:09:18 +1100 Subject: [PATCH] Basic docs for all of ox_lib --- docs/ox_lib/Client/cache.md | 14 ++++++ docs/ox_lib/Client/callback.md | 27 +++++++++++ docs/ox_lib/Client/disableControls.md | 24 ++++++++++ docs/ox_lib/Client/streaming.md | 39 ++++++++++++++++ docs/ox_lib/Client/vehicleProperties.md | 29 ++++++++++++ docs/ox_lib/Imports/Client/disableControls.md | 21 --------- .../Imports/Client/lib.callback/await.md | 14 ------ .../Imports/Client/lib.callback/index.md | 16 ------- docs/ox_lib/Imports/index.md | 5 -- docs/ox_lib/Server/acl.md | 46 +++++++++++++++++++ .../addCommand.md} | 4 +- .../register.md => Server/callback.md} | 8 +--- docs/ox_lib/Server/version.md | 12 +++++ docs/ox_lib/Shared/version.md | 11 +++++ 14 files changed, 206 insertions(+), 64 deletions(-) create mode 100644 docs/ox_lib/Client/cache.md create mode 100644 docs/ox_lib/Client/callback.md create mode 100644 docs/ox_lib/Client/disableControls.md create mode 100644 docs/ox_lib/Client/streaming.md create mode 100644 docs/ox_lib/Client/vehicleProperties.md delete mode 100644 docs/ox_lib/Imports/Client/disableControls.md delete mode 100644 docs/ox_lib/Imports/Client/lib.callback/await.md delete mode 100644 docs/ox_lib/Imports/Client/lib.callback/index.md delete mode 100644 docs/ox_lib/Imports/index.md create mode 100644 docs/ox_lib/Server/acl.md rename docs/ox_lib/{Imports/Server/lib.addCommand.md => Server/addCommand.md} (97%) rename docs/ox_lib/{Imports/Server/lib.callback/register.md => Server/callback.md} (84%) create mode 100644 docs/ox_lib/Server/version.md create mode 100644 docs/ox_lib/Shared/version.md diff --git a/docs/ox_lib/Client/cache.md b/docs/ox_lib/Client/cache.md new file mode 100644 index 00000000..078c7556 --- /dev/null +++ b/docs/ox_lib/Client/cache.md @@ -0,0 +1,14 @@ +# Cache + +Caches data related to the player and handling some events or statebags. +An interval runs every 100ms to update data that cannot be checked via handlers. + +Still a work-in-progress and does not have any API or events. +https://github.com/overextended/ox_lib/blob/master/resource/states/client.lua + +## States +```lua +cache.ped = PlayerPedId() +cache.vehicle = GetVehiclePedIsIn(cache.ped, false) +cache.driver = GetPedInVehicleSeat(cache.vehicle, -1) == cache.ped +``` diff --git a/docs/ox_lib/Client/callback.md b/docs/ox_lib/Client/callback.md new file mode 100644 index 00000000..5ae2b21b --- /dev/null +++ b/docs/ox_lib/Client/callback.md @@ -0,0 +1,27 @@ +# Callbacks + +Triggers a registered server callback and registers an event handler for the response. + +### lib.callback +The response is handled in a separate coroutine. +```lua +-- name: string +-- delay: number or false +-- cb: function +lib.callback(name, delay, cb, ...) + +lib.callback('ox_inventory:getItemCount', false, function(count) + print(count) +end, 'water', {type = 'fresh'}) +``` + +### lib.callback.await +The current coroutine is yielded until a response is received. +```lua +-- name: string +-- delay: number or false +lib.callback.await(name, delay, ...) + +local count = lib.callback('ox_inventory:getItemCount', false, 'water', {type = 'fresh'}) +print(count) +``` diff --git a/docs/ox_lib/Client/disableControls.md b/docs/ox_lib/Client/disableControls.md new file mode 100644 index 00000000..2b61b791 --- /dev/null +++ b/docs/ox_lib/Client/disableControls.md @@ -0,0 +1,24 @@ +# Disable Controls + +### lib.disableControls +```lua +lib.disableControls() +``` + +### lib.disableControls:Add +```lua +-- vararg: number +lib.disableControls:Add(...) +``` + +### lib.disableControls:Remove +```lua +-- vararg: number +lib.disableControls:Remove(...) +``` + +### lib.disableControls:Clear +```lua +-- vararg: number +lib.disableControls:Clear(...) +``` diff --git a/docs/ox_lib/Client/streaming.md b/docs/ox_lib/Client/streaming.md new file mode 100644 index 00000000..cb877b64 --- /dev/null +++ b/docs/ox_lib/Client/streaming.md @@ -0,0 +1,39 @@ +# Streaming + +Check if assets exist, such as models, and loads them into memory. +Throws errors for invalid assets and returns false if it could not be loaded. + +### lib.requestAnimDict +```lua +-- dict: string +-- timeout: number [default: 100] +lib.requestAnimDict(dict, timeout) +``` + +### lib.requestAnimSet +```lua +-- set: string +-- timeout: number [default: 100] +lib.requestAnimSet(set, timeout) +``` + +### lib.requestModel +```lua +-- model: string +-- timeout: number [default: 100] +lib.requestModel(model, timeout) +``` + +### lib.requestStreamedTextureDict +```lua +-- dict: string +-- timeout: number [default: 100] +lib.requestStreamedTextureDict(dict, timeout) +``` + +### lib.requestNamedPtfxAsset +```lua +-- fxName: string +-- timeout: number [default: 100] +lib.requestNamedPtfxAsset(fxName, timeout) +``` \ No newline at end of file diff --git a/docs/ox_lib/Client/vehicleProperties.md b/docs/ox_lib/Client/vehicleProperties.md new file mode 100644 index 00000000..9f715d7f --- /dev/null +++ b/docs/ox_lib/Client/vehicleProperties.md @@ -0,0 +1,29 @@ +# Vehicle Properties +Mostly follows the format used by ESX and QBCore, with extra data such as damaged/missing props. +https://github.com/overextended/ox_lib/blob/master/resource/entities/client/vehicleproperties.lua#L5 + +### lib.getVehicleProperties +```lua +-- vehicle: entity +lib.getVehicleProperties(vehicle) + +lib.getVehicleProperties(GetVehiclePedIsUsing(PlayerPedId())) +``` + +### lib.setVehicleProperties +Requires the vehicle to belong to the client. _Do not use NetworkRequestControlOfEntity_. +```lua +-- vehicle: entity +-- props: table +lib.setVehicleProperties(vehicle, props) + +RegisterNetEvent('lualib:setVehicleProperties', function(netid, data) + lib.setVehicleProperties(NetToVeh(netid), data) +end) +``` + +#### Recommended usage +The server should tell the owner of the entity to set properties, using the following trigger. +```lua +TriggerClientEvent('lualib:setVehicleProperties', entityOwner, vehNetId, data) +``` \ No newline at end of file diff --git a/docs/ox_lib/Imports/Client/disableControls.md b/docs/ox_lib/Imports/Client/disableControls.md deleted file mode 100644 index 1569e17b..00000000 --- a/docs/ox_lib/Imports/Client/disableControls.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: lib.disableControls ---- - -```lua -lib.disableControls:Add(...) -lib.disableControls:Remove(...) -lib.disableControls:Clear(...) -lib.disableControls() -``` - -```lua -lib.disableControls:Add(23, 25, 36, 263) - -CreateThread(function() - while true do - Wait(0) - lib.disableControls() - end -end) -``` diff --git a/docs/ox_lib/Imports/Client/lib.callback/await.md b/docs/ox_lib/Imports/Client/lib.callback/await.md deleted file mode 100644 index 49551c71..00000000 --- a/docs/ox_lib/Imports/Client/lib.callback/await.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: lib.callback.await ---- - -```lua --- name: string --- delay: number or false -lib.callback.await(name, delay, ...) -``` - -```lua -local count = lib.callback('ox_inventory:getItemCount', false, 'water', {type = 'fresh'}) -print(count) -``` diff --git a/docs/ox_lib/Imports/Client/lib.callback/index.md b/docs/ox_lib/Imports/Client/lib.callback/index.md deleted file mode 100644 index 0e91d5e6..00000000 --- a/docs/ox_lib/Imports/Client/lib.callback/index.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: lib.callback ---- - -```lua --- name: string --- delay: number or false --- cb: function -lib.callback(name, delay, cb, ...) -``` - -```lua -lib.callback('ox_inventory:getItemCount', false, function(count) - print(count) -end, 'water', {type = 'fresh'}) -``` diff --git a/docs/ox_lib/Imports/index.md b/docs/ox_lib/Imports/index.md deleted file mode 100644 index 10d5be00..00000000 --- a/docs/ox_lib/Imports/index.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Imports ---- - -These functions are loaded into the environment for the invoking resource. \ No newline at end of file diff --git a/docs/ox_lib/Server/acl.md b/docs/ox_lib/Server/acl.md new file mode 100644 index 00000000..183db4b9 --- /dev/null +++ b/docs/ox_lib/Server/acl.md @@ -0,0 +1,46 @@ +# Permissions + +Wrapper around the built-in ACL system. Handles lib.addCommand and ox_groups permissions. +Refer to [Basic Aces & Principals overview/guide](https://forum.cfx.re/t/basic-aces-principals-overview-guide/90917) for more information. + +### lib.addAce +Assigns the ace permission to a principal. Third parameter defaults to 'allow', while false sets the permission to 'deny'. +```lua +-- principal: string +-- ace: string +-- allow: boolean +lib.addAce(principal, ace, allow) + +lib.addAce('group.admin', 'command.say') +``` + +### lib.removeAce +Removes the ace permission from a principal. Third parameter defaults to 'allow', while false sets the permission to 'deny'. +```lua +-- principal: string +-- ace: string +-- allow: boolean +lib.removeAce(principal, ace, allow) + +lib.removeAce('group.admin', 'command.say') +``` + +### lib.addPrincipal +Assigns a principal to a parent principal. Children inherit permissions from the parent. +```lua +-- child: string +-- parent: string +lib.addPrincipal(child, parent) + +lib.addPrincipal('player.1', 'group.moderator') +``` + +### lib.removePrincipal +Removes a principal from a parent principal. +```lua +-- child: string +-- parent: string +lib.removePrincipal(child, parent) + +lib.removePrincipal('player.1', 'group.moderator') +``` diff --git a/docs/ox_lib/Imports/Server/lib.addCommand.md b/docs/ox_lib/Server/addCommand.md similarity index 97% rename from docs/ox_lib/Imports/Server/lib.addCommand.md rename to docs/ox_lib/Server/addCommand.md index 6e9bc6ba..ede83fb1 100644 --- a/docs/ox_lib/Imports/Server/lib.addCommand.md +++ b/docs/ox_lib/Server/addCommand.md @@ -1,3 +1,5 @@ +# Command + ```lua -- principal: string or false -- command: string @@ -5,9 +7,7 @@ -- parameters: table (optional) -- help: string (optional) lib.addCommand(principal, command, callback, parameters, help) -``` -```lua lib.addCommand('group.admin', {'additem', 'giveitem'}, function(source, args) args.item = Items(args.item) if args.item and args.count > 0 then diff --git a/docs/ox_lib/Imports/Server/lib.callback/register.md b/docs/ox_lib/Server/callback.md similarity index 84% rename from docs/ox_lib/Imports/Server/lib.callback/register.md rename to docs/ox_lib/Server/callback.md index 2ef2546f..f52e7143 100644 --- a/docs/ox_lib/Imports/Server/lib.callback/register.md +++ b/docs/ox_lib/Server/callback.md @@ -1,15 +1,11 @@ ---- -id: register -title: lib.callback.register ---- +# Callbacks +### lib.callback.register ```lua -- name: string -- cb: function lib.callback.register(name, cb) -``` -```lua lib.callback.register('ox_inventory:getItemCount', function(source, item, metadata, target) local inventory = target and Inventory(target) or Inventory(source) return (inventory and Inventory.GetItem(inventory, item, metadata, true)) or 0 diff --git a/docs/ox_lib/Server/version.md b/docs/ox_lib/Server/version.md new file mode 100644 index 00000000..6005d05e --- /dev/null +++ b/docs/ox_lib/Server/version.md @@ -0,0 +1,12 @@ +# Version check + +### lib.versionCheck +Compares the resource version to the latest published release on GitHub. +```lua +-- repository: string +lib.versionCheck(repository) + +lib.versionCheck('overextended/ox_lib') +``` + +[Utilises GitHub's release API](https://docs.github.com/en/rest/reference/releases) \ No newline at end of file diff --git a/docs/ox_lib/Shared/version.md b/docs/ox_lib/Shared/version.md new file mode 100644 index 00000000..2cf94e33 --- /dev/null +++ b/docs/ox_lib/Shared/version.md @@ -0,0 +1,11 @@ +# Dependency version + +### lib.checkDependency +Check if a resource is using a specified version or higher, allowing for compatibility checks or throwing errors. +```lua +-- repository: string +-- version: string +lib.versionCheck(repository, version) + +if not lib.checkDependency('ox_lib', '1.5.0') then error() end +```