Files
Jag de4051e62a chore: target, fuel, and doorlock updates (#136)
* chore: ox_target cleaned up

- minor fixes on ox_lib zones

* chore: move get/set fuel amount to shared.mdx file

* chore: Update removeZone input type

https://github.com/overextended/ox_target/commit/021b32d4d52fa58305045177f3dc3c0a969d07e5

* chore: doorlock cleaned up

* add missing export

* reorder textui sections
2023-07-27 11:45:12 +02:00

201 lines
4.2 KiB
Plaintext

import { Tabs, Tab } from 'nextra-theme-docs';
import { Callout } from 'nextra/components';
# Shared
Faster alternative to PolyZone utilising [glm.polygon](https://github.com/citizenfx/lua/blob/luaglm-dev/cfx/EXTENDED.md).
<Callout>
Currently zones only have basic support on the server side. Some features will not work such as `onEnter`, `onExit`,
and `inside`.
</Callout>
## lib.zones.poly
```lua
lib.zones.poly(data)
```
- data: `table`
- points: `vector3[]`
- All z values must match
- thickness?: `number`
- Default: `4`
- onEnter?: `function(self: table)`
- onExit?: `function(self: table)`
- inside?: `function(self: table)`
- debug?: `boolean`
## lib.zones.box
```lua
lib.zones.box(data)
```
- data: `table`
- coords: `vector3`
- size?: `vector3`
- Default: `vec3(2, 2, 2)`
- rotation?: `number`
- Angle in degrees
- Default: `0`
- onEnter?: `function(self: table)`
- onExit?: `function(self: table)`
- inside?: `function(self: table)`
- debug?: `boolean`
## lib.zones.sphere
```lua
lib.zones.sphere(data)
```
- data: `table`
- coords: `vector3`
- radius?: `number`
- Default: `2`
- onEnter?: `function(self: table)`
- onExit?: `function(self: table)`
- inside?: `function(self: table)`
- debug?: `boolean`
## Methods
### remove
Zones can be deleted by using the remove method. The data will not be cleared from the script, and can be used to recreate a zone later.
```lua
local zone = lib.zones.box({...})
zone:remove()
SetTimeout(500, function()
lib.zones.poly(zone)
end)
```
### contains
Tests if a point exists inside the zone, returning a `boolean`.
```lua
local zone = lib.zones.box({...})
if zone:contains(vec3(1, 1, 1)) then
print('point is inside zone!')
end
```
## Usage Examples
```lua
function onEnter(self)
print('entered zone', self.id)
end
function onExit(self)
print('exited zone', self.id)
end
function inside(self)
print('you are inside zone ' .. self.id)
end
local poly = lib.zones.poly({
points = {
vec(413.8, -1026.1, 29),
vec(411.6, -1023.1, 29),
vec(412.2, -1018.0, 29),
vec(417.2, -1016.3, 29),
vec(422.3, -1020.0, 29),
vec(426.8, -1015.9, 29),
vec(431.8, -1013.0, 29),
vec(437.3, -1018.4, 29),
vec(432.4, -1027.2, 29),
vec(424.7, -1023.5, 29),
vec(420.0, -1030.2, 29),
vec(409.8, -1028.4, 29),
},
thickness = 2,
debug = true,
inside = inside,
onEnter = onEnter,
onExit = onExit
})
local sphere = lib.zones.sphere({
coords = vec3(442.5363, -1017.666, 28.65637),
radius = 1,
debug = true,
inside = inside,
onEnter = onEnter,
onExit = onExit
})
local box = lib.zones.box({
coords = vec3(442.5363, -1017.666, 28.65637),
size = vec3(1, 1, 1),
rotation = 45,
debug = true,
inside = inside,
onEnter = onEnter,
onExit = onExit
})
```
## Zone creation script
You can use our builtin zone-creator with `/zone` - with `poly`, `box` or `sphere` as an argument.
Available controls will be displayed on the right side.
Zones will be saved to `ox_lib/created_zones.lua` with your chosen format.
<Tabs items={["function", "array", "ox_target"]}>
<Tab>
```lua
local poly = lib.zones.poly({
name = poly,
points = {
vec(447.9, -998.8, 25.8),
vec(450.3, -998.2, 25.8),
vec(449.9, -995.5, 25.8),
vec(447.2, -995.6, 25.8),
vec(446.3, -997.9, 25.8),
},
thickness = 2,
})
```
</Tab>
<Tab>
```lua
{
name = poly,
points = {
vec(447.9, -998.8, 25.8),
vec(450.3, -998.2, 25.8),
vec(449.9, -995.5, 25.8),
vec(447.2, -995.6, 25.8),
vec(446.3, -997.9, 25.8),
},
thickness = 2,
},
```
</Tab>
<Tab>
```lua
exports.ox_target:addPolyZone({
name = poly,
points = {
vec(447.9, -998.8, 25.8),
vec(450.3, -998.2, 25.8),
vec(449.9, -995.5, 25.8),
vec(447.2, -995.6, 25.8),
vec(446.3, -997.9, 25.8),
},
thickness = 2,
})
```
</Tab>
</Tabs>