Skip to content

Commit

Permalink
Add docs on spawnmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
ekralc committed Apr 1, 2020
1 parent 27f379b commit 5139598
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 13 deletions.
26 changes: 13 additions & 13 deletions content/docs/resources/spawnmanager/_index.md
Expand Up @@ -2,25 +2,25 @@
title: spawnmanager
---

##### TODO

<!--
## About
_Todo._
The spawnmanager is a base resource that handles the spawning of the player. It allows you to choose when and where to spawn the player and also control how they respawn.

Spawnmanager is included and maintained at the [cfx-server-data](https://github.com/citizenfx/cfx-server-data) repository.

Map resources for [mapmanager](../mapmanager) will have their spawnpoints loaded and usable in spawnmanager, as long as they are started *after* spawnmanager.

## Exports

### Client
- todo
### Server
- todo
- [spawnPlayer](./functions/spawnPlayer)
- [addSpawnPoint](./functions/addSpawnPoint)
- [removeSpawnPoint](./functions/removeSpawnPoint)
- [loadSpawns](./functions/loadSpawns)
- [setAutoSpawn](./functions/setAutoSpawn)
- [setAutoSpawnCallback](./functions/setAutoSpawnCallback)
- [forceRespawn](./functions/forceRespawn)

## Events

### Client
- todo
### Server
- todo
-->
- [playerSpawned](./events/playerSpawned)
44 changes: 44 additions & 0 deletions content/docs/resources/spawnmanager/functions/addSpawnPoint.md
@@ -0,0 +1,44 @@
---
title: addSpawnPoint
---

## About
This export allows you to add a spawn point to the spawnmanager and returns an index for that spawnpoint.

## Name
```
addSpawnPoint
```

## Parameters

```
object spawn
```

### Required Arguments

- **spawn**: An object containing the following information:
- **(float) x**: The x coordinate of where the player spawned to.
- **(float) y**: The y coordinate of where the player spawned to.
- **(float) z**: The z coordinate of where the player spawned to.
- **(float) heading**: The heading that the player is facing when spawned.
- **(Hash) model**: The ped model hash the player spawned as.

Examples
--------

##### Lua Example:
```lua
local mySpawnPoint = exports.spawnmanager:addSpawnPoint({
z = 111.5291,
y = 197.7201,
x = 466.8401,
heading = 291.71,
idx = 6,
model = 1631478380
})

-- Spawns the player at the spawn point we just created
exports.spawnmanager:spawnPlayer(mySpawnPoint)
```
25 changes: 25 additions & 0 deletions content/docs/resources/spawnmanager/functions/forceRespawn.md
@@ -0,0 +1,25 @@
---
title: forceRespawn
---

## About
If the auto-spawn flag is enabled, this export instantly and forcefully respawns the player, disregarding the 2 second cooldown.

## Name
```
forceRespawn
```

##### Lua Example:

```lua
Citizen.CreateThread(function()
exports.spawnmanager:setAutoSpawn(true) -- must be true for this to work
while true do
if IsEntityDead(PlayerPedId()) then -- check if the player is dead
exports.spawnmanager:forceRespawn() -- forcefully respawn without a cooldown
end
Citizen.Wait(100)
end
end)
```
42 changes: 42 additions & 0 deletions content/docs/resources/spawnmanager/functions/loadSpawns.md
@@ -0,0 +1,42 @@
---
title: loadSpawns
---

## About
This export loads a set of spawn points into the spawnmanager from a JSON string.

## Name
```
loadSpawns
```

## Parameters

```
string spawnString
```

### Required Arguments

- **spawnString** A normal *spawn* object in JSON format

##### Example

```js
{
'spawns': [
{
z: 111.5291,
y: 197.7201,
x: 466.8401,
heading: 291.71,
idx: 6,
model: 1631478380
}
]
}
```

## Examples

TODO
40 changes: 40 additions & 0 deletions content/docs/resources/spawnmanager/functions/removeSpawnPoint.md
@@ -0,0 +1,40 @@
---
title: removeSpawnPoint
---

## About
This export allows you to remove an existing spawnpoint from the spawnmanager.

## Name
```
removeSpawnPoint
```

## Parameters

```
int spawnIdx
```

### Required Arguments

- **spawnIdx** The index of the spawnpoint to remove.

Examples
--------

##### Lua Example:
```lua
-- Add a new spawnpoint!
local mySpawnPoint = exports.spawnmanager:addSpawnPoint({
z = 111.5291,
y = 197.7201,
x = 466.8401,
heading = 291.71,
idx = 6,
model = 1631478380
})

-- Now let's remove it...
exports.spawnmanager:removeSpawnPoint(mySpawnPoint)
```
30 changes: 30 additions & 0 deletions content/docs/resources/spawnmanager/functions/setAutoSpawn.md
@@ -0,0 +1,30 @@
---
title: setAutoSpawn
---

## About
This export allows you to change the auto-spawning flag.

When this is enabled, players will be automatically spawned after the loading screen. They will also be automatically respawned with a 2 second cooldown. To instantly and forcefully respawn the player without the cooldown, use [forceRespawn](./functions/forceRespawn).

If the auto-spawning flag is disabled, you will have to manually spawn players when they first log in and also manually respawn players when they die, could be useful in an environment where you don't want instant respawn.

## Name
```
setAutoSpawn
```

## Parameters

```
bool enabled
```

### Required Arguments

- **enabled** Whether to enable or disable auto-spawning.

##### Lua Example:
```lua
exports.spawnmanager:setAutoSpawn(true)
```
@@ -0,0 +1,28 @@
---
title: setAutoSpawnCallback
---

## About
This export allows you to choose your own callback for autospawning, instead of using spawnmanager's 'native' [spawnPlayer](https://github.com/citizenfx/cfx-server-data/blob/2bde7889b4593d842e911827a33294211f40de93/resources/%5Bmanagers%5D/spawnmanager/spawnmanager.lua#L207) function.

## Name
```
setAutoSpawnCallback
```

## Parameters

```
function callback
```

### Required Arguments

- **callback** The callback to execute when auto-spawning the player.

##### Lua Example:
```lua
exports.spawnmanager:setAutoSpawnCallback(function()
-- todo fancy spawning stuff
end)
```
41 changes: 41 additions & 0 deletions content/docs/resources/spawnmanager/functions/spawnPlayer.md
@@ -0,0 +1,41 @@
---
title: spawnPlayer
---

## About
This export allows you to choose specifically when or where to spawn a player. You'll most likely want to use this if you've turned off the auto-spawn flag with [setAutoSpawn](./functions/setAutoSpawn).

Once the player has spawned, the [playerSpawned](../../events/playerSpawned) event will be triggered.


## Name
```
spawnPlayer
```

## Parameters

```
int spawnIdx, function callback(object spawn)
```

### Optional Arguments

- `spawnIdx` this can be a spawn point from a map resource registered by [mapmanager](../../../mapmanager), or can be added with [addSpawnPoint](./functions/addSpawnPoint). If this isn't specified, a random spawn point will be picked out of the already registered spawn points (if any).

- `callback` is executed once the player has successfully spawned and passes a `spawn` object as specified in [playerSpawned](../../events/playerSpawned).

## Examples

##### Lua Example:
```lua
-- Spawns the player at a random spawnpoint
exports.spawnmanager:spawnPlayer()
```

```lua
-- Spawns the player at a specific spawnpoint with a callback
exports.spawnmanager:spawnPlayer(1, function(spawn)
TriggerEvent('chat:addMessage', { args = { 'You have spawned! Congrats!' } })
end)
```

0 comments on commit 5139598

Please sign in to comment.