This commit is contained in:
Luke committed 2023-06-04 15:15:21 +02:00
1 parent 3cebaf7fa5
commit b5eba8423f
229 files changed
+6238 -10690

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
When ox_core is imported into a resource it will create the `player` global.
If `player` is nil, then the client has not yet selected a character and spawned.
**Example:**
```lua
print(json.encode(player, { indent = true }))
```
- player?: `table`
- name: `string`
- firstname: `string`
- lastname: `string`
- userid: `number`
- charid: `number`
- groups: `table`
- gender: `string`
+38
View File
@@ -0,0 +1,38 @@
---
title: Callbacks
---
### ox:getStatus
```lua
lib.callback.await('ox:getStatus', delay, targetId, statusName)
```
- delay: `number`
- targetId: `number`
- The server id for the player to get statuses for.
- statusName?: `string`
- The name of the status (i.e. hunger). Can be omitted to return all statuses.
### ox:getLicense
```lua
lib.callback.await('ox:getLicense', delay, licenseName, targetId)
```
- delay: `number`
- licenseName: `string`
- The name of the license to get data for. Can be omitted to return all licenses.
- targetId?: `number`
- The server id to get license data for, defaulting to the current player.
### ox:getNearbyVehicles
```lua
lib.callback.register('ox:getNearbyVehicles', function(radius)
```
Returns an array of vehicle netids within a given radius of the player's location.
- radius?: `number`
- The radius from the player's location to return vehicles.
+55
View File
@@ -0,0 +1,55 @@
---
title: Events
---
## Client events
### ox:playerLoaded
Triggered once the player has selected a character and spawned.
```lua
AddEventHandler('ox:playerLoaded', function(data) end)
```
### ox:playerLogout
Triggered when the player enters character selection if they were previously playing a character.
```lua
AddEventHandler('ox:playerLogout', function() end)
```
### ox:statusTick
Triggered every 1000ms interval, when status values are updated internally.
```lua
AddEventHandler('ox:statusTick', function(statuses) end)
```
## Networked events
### ox:setGroup
Triggered when the player's grade in a group is modified on the server with `player.setGroup`.
```lua
RegisterNetEvent('ox:setGroup', function(group, grade) end)
```
### ox:licenseAdded
Triggered when the player has been granted a license.
```lua
RegisterNetEvent('ox:licenseAdded', function(name) end)
```
### ox:licenseRemoved
Triggered when the player's license is revoked.
```lua
RegisterNetEvent('ox:licenseRemoved', function(name) end)
```
+89
View File
@@ -0,0 +1,89 @@
import { Tabs, Tab } from 'nextra-theme-docs';
## Ox.GetPlayer
Return an instance of OxPlayer for the given player source.
<Tabs items={['Lua', 'JS']}>
<Tab>
```lua
local player = Ox.GetPlayer(source)
print(json.encode(player, { indent = true }))
```
</Tab>
<Tab>
```ts
import { GetPlayer } from '@overextended/ox_core/server';
const player = GetPlayer(source);
console.log(JSON.stringify(player));
```
</Tab>
</Tabs>
## Ox.GetPlayerByFilter
Return the first OxPlayer that matches the filter properties.
<Tabs items={['Lua', 'JS']}>
<Tab>
```lua
local filter = { phoneNumber = '556-560-6609' }
local player = Ox.GetPlayerByFilter(filter)
print(json.encode(player, { indent = true }))
```
</Tab>
<Tab>
```ts
import { GetPlayerByFilter } from '@overextended/ox_core/server';
const filter = { phoneNumber: '556-560-6609' };
const player = GetPlayerByFilter(filter);
console.log(JSON.stringify(player));
```
</Tab>
</Tabs>
## Ox.GetPlayers
Returns an array containing all players. Methods will not be applied if the first argument is false.
Players can be filtered to only return players that match the given properties, or groups.
<Tabs items={['Lua', 'JS']}>
<Tab>
```lua
-- Get an array containing all players in the police or sheriff groups, with grade 3 or higher.
local filter = { groups = {['sheriff'] = 3, ['police'] = 3} })
local players = Ox.GetPlayers(usemetatable, filter)
for i = 1, #players do
local player = players[i]
print(json.encode(player, { indent = true }))
end
```
</Tab>
<Tab>
```ts
import { GetPlayers } from '@overextended/ox_core/server';
// Get an array containing all players in the police or sheriff groups, with grade 3 or higher.
const filter = { groups: { sheriff: 3, police: 3 } })
const players = GetPlayers(useclass, filter);
for (let i = 0; i < players.length; i++) {
const player = players[i];
console.log(JSON.stringify(player));
}
```
</Tab>
</Tabs>
+71
View File
@@ -0,0 +1,71 @@
---
title: Events
---
## Server events
### ox:playerLoaded
Triggered after a player has selected a character.
```lua
AddEventHandler('ox:playerLoaded', function(source, userid, charid) end)
```
### ox:setGroup
Triggered when a player's grade in a group is modified with `player.setGroup`.
```lua
AddEventHandler('ox:setGroup', function(source, group, grade) end)
```
### ox:playerLogout
Triggered when a player logs out from their current character or disconnects from the server.
```lua
AddEventHandler('ox:playerLogout', function(source, userid, charid) end)
```
### ox:characterDeleted
Triggered when a player has deleted a character.
```lua
AddEventHandler('ox:characterDeleted', function(source, userid, charid) end)
```
### ox:licenseAdded
Triggered when a player has been granted a license.
```lua
AddEventHandler('ox:licenseAdded', function(source, name) end)
```
### ox:licenseRemoved
Triggered when a player's license is revoked.
```lua
AddEventHandler('ox:licenseRemoved', function(source, name) end)
```
## Networked events
### ox:playerDeath
Triggered on player death and revival.
```lua
RegisterNetEvent('ox:playerDeath', function(isDead) end)
```
### ox:setPlayerInService
Can be triggered to set a player as "in service" for a specific group they are a member of.
```lua
RegisterNetEvent('ox:setPlayerInService', function(group) end)
```
+181
View File
@@ -0,0 +1,181 @@
---
title: Methods
---
import { Tabs, Tab } from 'nextra-theme-docs';
These functions are inherited from the [Player class](../Server/).
## player.set
Update the player's metadata, optionally syncing it with the client.
```lua
player.set(key, value, replicated)
```
- key: `string`
- value: `any`
- replicated?: `boolean`
## player.get
Get a value from the player's metadata, or omit the argument to get all metadata.
```lua
player.get(key)
```
- key?: `string`
## player.getState
Return the player's statebag.
```lua
player.getState()
```
## player.getCoords
Return the player's position.
```lua
player.getCoords()
```
## player.setGroup
Updates the player's grade for the given group. Any value below 1 will remove the group from the player.
```lua
player.setGroup(group, grade)
```
- group: `string`
- grade?: `number`
## player.getGroup
Returns the player's current grade for a given group.
```lua
player.getGroup()
```
## player.getGroups
Returns an object of all groups the player is in, with the current grade as the value.
```lua
player.getGroups()
```
## player.hasGroup
Check if the player is a member of a given group, and returns the matching group name and grade.
The filter can be a string, array, or object where key is the group, and value is the minimum grade.
```lua
player.hasGroup(filter)
```
- filter: `string | string[] | { [string]: number }`
## player.setStatus
Set the current value for a status (i.e. hunger, thirst).
```lua
player.setStatus(name, value)
```
- name: string
- value: number
## player.addStatus
Add the given amount to the total value for a status (i.e. hunger, thirst).
```lua
player.addStatus(name, value)
```
- name: string
- value: number
## player.removeStatus
Remove the given amount from the total value for a status (i.e. hunger, thirst).
```lua
player.removeStatus(name, value)
```
- name: string
- value: number
## player.getLicenses
Get all licenses for the player.
```lua
player.getLicenses()
```
## player.getLicense
Get the license of the given name for the player, as an object containing license information.
```lua
player.getLicense(name)
```
- name: string
## player.addLicense
Grants a license to the player and triggers 'ox:licenseAdded' on the server and client.
```lua
player.addLicense(name)
```
- name: string
## player.removeLicense
Revokes a license from the player and triggers 'ox:licenseRemoved' on the server and client.
```lua
player.removeLicense(name)
```
- name: string
## player.getPlayersInScope
Return an array of all player id's inside the player's scope.
```lua
player.getPlayersInScope()
```
## player.isPlayerInScope
Check if the given source is inside the player's scope.
```lua
player.isPlayerInScope(target)
```
- target: `number`
## player.triggerScopedEvent
```lua
player.triggerScopedEvent(eventName, ...)
```
- eventName: `string`
- ...?: `any[]`
+54
View File
@@ -0,0 +1,54 @@
---
title: Server
sidebar_position: 1
---
## Ox.GetVehicle
Return an instance of OxVehicle for the given entity.
```lua
local vehicle = Ox.GetVehicle(entity)
print(json.encode(vehicle, { indent = true }))
```
## Ox.GetVehicles
Returns an array containing all vehicles. Methods will not be applied if the first argument is false.
```lua
local vehicles = Ox.GetVehicles(usemetatable)
for i = 1, #vehicles do
local vehicle = vehicles[i]
print(json.encode(vehicle, { indent = true }))
end
```
## Ox.CreateVehicle
Spawns a vehicle and returns the instance of OxVehicle.
If the first argument is a number, it will attempt to spawn a vehicle from the database with a matching id.
```lua
local vehicleId = MySQL.scalar.await('SELECT id FROM vehicles WHERE owner = ? LIMIT 1', { player.charid })
if vehicleId then
local coords = player.getCoords()
local vehicle = Ox.CreateVehicle(vehicleId, vector3(coords.x, coords.y + 1.0, coords.z) , GetEntityHeading(player.ped))
if vehicle then
print(json.encode(vehicle, { indent = true }))
end
end
```
If the first argument is a table and the owner property is a number, or nil, the vehicle will be added to the database.
Setting the owner as false creates a non-persistent vehicle.
```lua
local vehicle = Ox.CreateVehicle({
model = 'sultanrs',
owner = player.charid,
}, player.getCoords(), GetEntityHeading(player.ped))
```
@@ -0,0 +1,14 @@
---
title: Callbacks
---
### ox:getNearbyVehicles
Get all vehicles within range of the target player.
```lua
lib.callback.await('ox:getNearbyVehicles', playerId, radius)
```
- playerId: `number`
- radius?: `number`
+96
View File
@@ -0,0 +1,96 @@
---
title: Methods
---
These functions are inherited from the [Vehicle class](../Server/).
## vehicle.set
Sets the vehicle's metadata for key to the given value.
```lua
vehicle.set(key, value)
```
- key: `string`
- value: `any`
## vehicle.get
Get a value from the vehicles's metadata, or omit the argument to get all metadata.
```lua
vehicle.get(key)
```
- key?: `string`
## vehicle.getState
Return the vehicle's statebag.
```lua
vehicle.getState()
```
## vehicle.getCoords
Return the vehicle's position.
```lua
vehicle.getCoords()
```
## vehicle.despawn
Despawns the vehicle but doesn't save it or update the stored value.
## vehicle.delete
Remove the vehicle from the database and despawns the entity.
```lua
vehicle.delete()
```
## vehicle.setStored
Updates the vehicle's "stored" value and optionally despawns it.
```lua
vehicle.setStored(value, despawn)
```
- value?: `string`
- despawn?: `boolean`
## vehicle.setOwner
Sets the vehicle's owner, matching a charid or nil to set it as unowned.
```lua
vehicle.setOwner(owner)
```
- owner?: `number`
## vehicle.setGroup
Sets the vehicle's group, which can be used for garage restrictions, unowned group vehicles, etc.
```lua
vehicle.setGroup(group)
```
- group?: `string`
## vehicle.setPlate
Sets the vehicle's plate, used in the database to ensure uniqueness. Does not necessarily match the plate property (i.e. fake plates).
Plate is always formatted to 8 characters.
```lua
vehicle.setPlate(plate)
```
- plate: `string`
+7
View File
@@ -0,0 +1,7 @@
label: Ox Core
collapsible: true
collapsed: true
link:
type: generated-index
description: An experimental framework for FiveM. Limited support and breaking changes guaranteed.
position: 4
+46
View File
@@ -0,0 +1,46 @@
# Concepts
We'll try to explain some technical but core concepts used in ox_core here.
## Classes
Lua doesn't have support for true classes, but rather prototype-based inheritance.
A prototype can hold its own variables and methods, which another object (an instance) can reference or call.
```lua
-- OxPlayer will hold all inherited variables and methods for instances of it.
local OxPlayer = {}
-- Sets the "index metamethod" of OxPlayer to reference itself.
-- This is how instances will know to look up the table.
OxPlayer.__index = OxPlayer
-- Set a new metatable on the table passed to the function.
-- The important code here is { __index = OxPlayer }.
function OxPlayer.new(player)
return setmetatable(player, OxPlayer)
end
-- Using the `:` syntax will pass the object as the first parameter.
function OxPlayer:getUsername()
return self.username
end
-- Create our instance of OxPlayer.
local player = OxPlayer.new({
username = 'Bob the Builder'
})
-- This is the same as OxPlayer.getUsername(player).
local username = player:getUsername()
-- 'Bob the Builder'
print(username)
```
When using the imported classes in your resources you can treat the methods as if you are calling a regular function.
```lua
local player = Ox.GetPlayer(playerId)
print(player.getUsername())
```