Skip to content

Commit

Permalink
docs: add new exports and player functions (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manason authored Sep 27, 2023
1 parent fbdac29 commit 5d7fec8
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 42 deletions.
3 changes: 2 additions & 1 deletion pages/resources/core/_meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"functions": "Functions",
"events": "Events",
"import": "Import"
"import": "Import",
"player": "Player"
}
4 changes: 2 additions & 2 deletions pages/resources/core/functions/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Callout } from "nextra/components";

# Client

## Module: core
## Exports

<Callout type="info">
called using `QBX.Functions.<FunctionName>`
called using `exports.qbx_core:<FunctionName>`
</Callout>


Expand Down
79 changes: 64 additions & 15 deletions pages/resources/core/functions/server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Callout } from "nextra/components";
## Exports

<Callout type="info">
called using `exports['qbx_core']:<FunctionName>`
called using `exports.qbx_core:<FunctionName>`
</Callout>

### CreateJobs
Expand Down Expand Up @@ -58,12 +58,6 @@ Remove a gang from memory. This is a runtime only change and will not modify fil
---@param origin string reason
```

## Module: core

<Callout type="info">
called using `QBX.Functions.<FunctionName>`
</Callout>

### GetSource

```lua
Expand All @@ -85,13 +79,6 @@ Remove a gang from memory. This is a runtime only change and will not modify fil
---@return Player?
```

### GetOfflinePlayerByCitizenId

```lua
---@param citizenid string
---@return Player?
```

### GetPlayerByPhone

```lua
Expand Down Expand Up @@ -271,6 +258,68 @@ Text box popup for player which dissappears after a set time.
---@param notifyIconColor? string Custom color for the icon chosen before
```

### Login
Login an existing character or create a new one. This is the preferred function for creating characters if the owning player is online.

```lua
---@param source Source
---@param citizenid? string populated for existing characters only
---@param newData? PlayerEntity populated for new characters only
---@return boolean success
```

### GetOfflinePlayer

```lua
---@param citizenid string
---@return Player? if found in storage
```

### Logout
Logs player out of their current character

```lua
---@param source Source
```

### CreatePlayer
Creates a new character and saves in database.

```lua
---@param playerData PlayerData
---@param offline boolean
---@return Player player
```

### Save
Save player info to database

```lua
---@param source Source
```

### SaveOffline
Saves PlayerData to database

```lua
---@param playerData PlayerEntity
```

### DeleteCharacter
Delete a character permanently. This action cannot be undone.

```lua
---@param citizenid string
```

### GenerateUniqueIdentifier
Generate unique values for player identifiers

```lua
---@param type UniqueIdType The type of unique value to generate
---@return string | number UniqueVal unique value generated
```

## Module: utils

<Callout type="info">
Expand Down Expand Up @@ -307,4 +356,4 @@ Check for duplicate license
```lua
---@param license string
---@return boolean
```
```
34 changes: 34 additions & 0 deletions pages/resources/core/functions/shared.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@ import { Callout } from "nextra/components";

# Shared

## Exports

<Callout type="info">
called using `exports.qbx_core:<FunctionName>`
</Callout>

### GetJobs
Returns the jobs table

```lua
---@return table<string, Job>
```

### GetGangs
Returns the gangs table

```lua
---@return table<string, Gang>
```

### GetVehiclesByName
Returns a table mapping vehicle name to vehicle

```lua
---@return table<string, Vehicle>
```

### GetVehiclesByHash
Returns a table mapping vehicle hash to vehicle

```lua
---@return table<number, Vehicle>
```

## Module: utils

<Callout type="info">
Expand Down
24 changes: 0 additions & 24 deletions pages/resources/core/import.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,6 @@ That means you can use it like any other script you have in your own resource.

# Modules

## core
Adds global QBX with slightly different fields depending on if importing on the client or the server

###### client
```lua
QBX.Config -- access global config created in config.lua
QBX.Shared -- access tables of jobs, gangs, locations, etc. https://github.com/Qbox-project/qbx_core/blob/main/shared/main.lua
QBX.Functions -- invoke core functions Ex: 'QBX.Functions.<function name>()'
QBX.IsLoggedIn -- whether the player has finished selecting a character
```

###### server
```lua
QBX.Config -- access global config created in config.lua
QBX.Shared -- access tables of jobs, gangs, locations, etc. https://github.com/Qbox-project/qbx_core/blob/main/shared/main.lua
QBX.Functions -- invoke core functions Ex: 'QBX.Functions.<function name>()'

---@type table<Source, Player>
QBX.Players = {}

---@type table<itemName, table>
QBX.UsableItems = {}
```

## playerdata
Adds global QBX.PlayerData and keeps it updated
https://github.com/Qbox-project/qbx_core/blob/14edd8e082b6579ef30a5e34df29f5a26bc29a21/server/player.lua#L3
Expand Down
102 changes: 102 additions & 0 deletions pages/resources/core/player.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Callout } from "nextra/components";

# Player
```lua
---@field Functions table
---@field PlayerData table
---@field Offline boolean
```

## Functions

<Callout type="info">
called using `player.Functions.<FunctionName>`
</Callout>

### SetJob
```lua
---@param job string name
---@param grade integer
---@return boolean success if job was set
```

### SetGang
```lua
---@param gang string name
---@param grade integer
---@return boolean success if gang was set
```

### SetJobDuty
```lua
---@param onDuty boolean
```

### SetPlayerData
Overwrites a top level key of playerdata with the specified value.

```lua
---@param key string
---@param val any
```

### SetMetaData
Stores a key value pair

```lua
---@param meta string
---@param val any
```

### GetMetaData
Retrieves value in metadata given a key

```lua
---@param meta string
---@return any
```

### AddJobReputation
```lua
---@param amount number
```

### AddMoney
```lua
---@param moneytype MoneyType
---@param amount number
---@param reason? string
---@return boolean success if money was added
```

### RemoveMoney
```lua
---@param moneytype MoneyType
---@param amount number
---@param reason? string
---@return boolean success if money was removed
```

### SetMoney
```lua
---@param moneytype MoneyType
---@param amount number
---@param reason? string
---@return boolean success if money was set
```

### GetMoney
```lua
---@param moneytype MoneyType
---@return boolean | number amount or false if moneytype does not exist
```

### SetCreditCard
Sets owned credit card number. Does not give character any items.

```lua
---@param cardNumber number
```

### Save
Saves character to database

0 comments on commit 5d7fec8

Please sign in to comment.