add js/ts versions of methods

This commit is contained in:
Luke committed 2022-07-13 21:34:22 +02:00
1 parent 26e93458ef
commit aeb90c297f
4 files changed
+162 -1

No files matched your search

+34
View File
@@ -3,19 +3,39 @@ title: Server
sidebar_position: 1 sidebar_position: 1
--- ---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
## Ox.GetPlayer ## Ox.GetPlayer
Return an instance of CPlayer for the given player source. Return an instance of CPlayer for the given player source.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local player = Ox.GetPlayer(source) local player = Ox.GetPlayer(source)
print(json.encode(player, { indent = true })) print(json.encode(player, { indent = true }))
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
import { GetPlayer } from '@overextended/ox_core/server'
const player = GetPlayer(source)
console.log(JSON.stringify(player, null, 2))
```
</TabItem>
</Tabs>
## Ox.GetPlayers ## Ox.GetPlayers
Returns an array containing all players. Methods will not be applied if the first argument is false. Returns an array containing all players. Methods will not be applied if the first argument is false.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local players = Ox.GetPlayers(usemetatable) local players = Ox.GetPlayers(usemetatable)
@@ -24,3 +44,17 @@ for i = 1, #players do
print(json.encode(player, { indent = true })) print(json.encode(player, { indent = true }))
end end
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
import { GetPlayers } from '@overextended/ox_core/server'
const players = GetPlayers()
for (let i = 0; i < players.length; i++) {
const player = players[i]
console.log(JSON.stringify(player, null, 2))
}
```
</TabItem>
</Tabs>
+102
View File
@@ -2,70 +2,172 @@
title: Methods title: Methods
--- ---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
These functions are inherited by instances of CPlayer. These functions are inherited by instances of CPlayer.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local player = Ox.GetPlayer(source) local player = Ox.GetPlayer(source)
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
import { GetPlayer } from '@overextended/ox_core/server'
const player = GetPlayer(source)
```
</TabItem>
</Tabs>
## player.set ## player.set
Sets the player's metadata for key to the given value. Sets the player's metadata for key to the given value.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local key, value = 'iq', 300 local key, value = 'iq', 300
player.set(key, value) player.set(key, value)
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const [key, value] = ['iq', 300]
player.set(key, value)
```
</TabItem>
</Tabs>
## player.get ## player.get
Return the player's metadata. Sending an argument will retrieve a specific metadata key. Return the player's metadata. Sending an argument will retrieve a specific metadata key.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local data = player.get() local data = player.get()
local iq = player.get('iq') local iq = player.get('iq')
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const data = player.get()
const iq = player.get('iq')
```
</TabItem>
</Tabs>
## player.getCoords ## player.getCoords
Return the player's world position. The value will be cached for future calls, so send true for the first argument to update it. Return the player's world position. The value will be cached for future calls, so send true for the first argument to update it.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local coords = player.getCoords(update) local coords = player.getCoords(update)
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const coords = player.getCoords(update)
```
</TabItem>
</Tabs>
## player.setGroup ## player.setGroup
Updates the player's grade for the given group. A value of 0 will remove the player Updates the player's grade for the given group. A value of 0 will remove the player
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local group, grade = 'police', 3 local group, grade = 'police', 3
player.setGroup(group, grade) player.setGroup(group, grade)
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const [group, grade] = ['police', 3]
player.setGroup(group, grade)
```
</TabItem>
</Tabs>
## player.hasGroup ## player.hasGroup
Check if the player is a member of a given group, and returns the matching group name and grade. 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. The filter can be a string, array, or object where key is the group, and value is the minimum grade.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local filter = { police = 0, sheriff = 0 } local filter = { police = 0, sheriff = 0 }
local group, grade = player.hasGroup(filter) local group, grade = player.hasGroup(filter)
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const filter = { police: 0, sheriff: 0 }
const [group, grade] = player.hasGroup(filter)
```
</TabItem>
</Tabs>
## player.isPlayerInScope ## player.isPlayerInScope
Check if the given source is inside the player's scope. Check if the given source is inside the player's scope.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local target = 2 local target = 2
local inScope = player.isPlayerInScope(target) local inScope = player.isPlayerInScope(target)
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const target = 2
const inScope = player.isPlayerInScope(target)
```
</TabItem>
</Tabs>
## player.triggerScopedEvent ## player.triggerScopedEvent
Trigger a client event for all players in the player's scope. Trigger a client event for all players in the player's scope.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
player.triggerScopedEvent(eventName, ...) player.triggerScopedEvent(eventName, ...)
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
player.triggerScopedEvent(eventName, ...)
```
</TabItem>
</Tabs>
+24
View File
@@ -5,6 +5,8 @@ sidebar_position: 1
import Tabs from '@theme/Tabs'; import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem'; import TabItem from '@theme/TabItem';
import IconButton from '@site/src/components/IconButton';
import { FaNpm } from 'react-icons/fa';
:::caution :::caution
@@ -66,3 +68,25 @@ pnpm build
| Name | Default | Replicated | | Name | Default | Replicated |
|------|------------|---------| |------|------------|---------|
| ox:primaryIdentifier | fivem | false | ox:primaryIdentifier | fivem | false
## Importing the core functions
<Tabs>
<TabItem value='lua' label='Lua'>
Functions are imported by simply adding the import files to the fxmanifest.
**Client:**
`@ox_core/imports/client.lua`
**Server:**
`@ox_core/imports/server.lua`
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
If in case you want to write resources in JS/TS you will need to insteall our node client and server wrapper package,
which will allow you to use the core's functions with full type and intellisense support.
<a href='https://www.npmjs.com/package/@overextended/ox_core'>
<IconButton style={{marginTop: '0.7rem'}} side='left' icon={<FaNpm/>}>Package</IconButton>
</a>
</TabItem>
</Tabs>
+2 -1
View File
@@ -1,7 +1,8 @@
import React from 'react'; import React from 'react';
interface Props { interface Props {
icon: Element; icon: React.ReactNode;
children: React.ReactNode;
side: 'left' | 'right'; side: 'left' | 'right';
style?: React.CSSProperties; style?: React.CSSProperties;
} }