Kivo Spawn Exports and Integration
Exports
Section titled “Exports”Both exports are client side. They are declared in fxmanifest.lua.
openSpawnUI
Section titled “openSpawnUI”Opens the spawn selector.
exports['kivo-spawn']:openSpawnUI()| Side | Client |
| Parameters | None |
| Returns | Nothing |
The selector can be opened again later, even after the player has already spawned once. While it is open, the player’s character is hidden and frozen. If the selector is already open, the call is ignored.
Example: open the selector from your own command or event, for instance after a custom respawn:
RegisterCommand('choosespawn', function() exports['kivo-spawn']:openSpawnUI()end, false)isMenuOpen
Section titled “isMenuOpen”Tells you whether the selector is open right now.
local open = exports['kivo-spawn']:isMenuOpen()| Side | Client |
| Parameters | None |
| Returns | boolean, true while the selector is open |
Example: pause your own HUD while the selector is on screen.
CreateThread(function() while true do if exports['kivo-spawn']:isMenuOpen() then -- hide your HUD here end Wait(500) endend)Hand-off event
Section titled “Hand-off event”Kivo Multichar tells Kivo Spawn to open with this client event. It is fired from Multichar’s open file shared/spawnbridge.lua.
TriggerEvent('kivo:client:readyForSpawn', spawnCoords, isNew, isDemoServer)| Argument | Type | Description |
|---|---|---|
spawnCoords |
vector4 |
The character’s last known position (or Multichar’s Config.defaultSpawn). |
isNew |
boolean |
true for a brand-new character. With Config.newCharSkipSelector = true the selector is skipped and the player goes to Kivo Spawn’s Config.defaultSpawn. With false the selector opens with no Last Location card. Multichar always sends false. |
isDemoServer |
boolean |
true in demo server mode (Multichar’s Config.demoServer). Kivo Spawn then skips its framework lookups. |
Notes:
- Fade the screen out before you fire it. Kivo Multichar does this. After the event, Kivo Spawn waits a few seconds on a black screen before the selector appears.
- Kivo Spawn listens for this event only when Kivo Multichar is running. Without Multichar, Kivo Spawn opens on its own, so there is no need to fire it.
Spawn functions
Section titled “Spawn functions”A spawn function lets one location compute where the player ends up. Add your functions to shared/spawnfunctions/demo.lua and reference them by name in Config.spawnlocations.
A function receives the location (already normalised) as its first argument and returns the spawn to apply. Return a table in the same shape. Start from SpawnFunctions.default so every field is filled in.
-- shared/spawnfunctions/demo.luaSpawnFunctions.hospital = function(spawnData) local spawn = SpawnFunctions.default(spawnData) if not spawn then return nil end
spawn.coords.w = 90.0 -- change the heading return spawnend-- config.lua{ id = 'hospital', coords = vector4(298.0, -584.0, 43.3, 70.0), name = 'Pillbox Hill', description = 'Start near the hospital.', spawnfunction = 'hospital',},Pick one of several positions at random:
SpawnFunctions.randomPier = function(spawnData) local spawn = SpawnFunctions.default(spawnData) if not spawn then return nil end
local options = { { x = -1850.0, y = -1230.0, z = 13.0, w = 140.0 }, { x = -1862.0, y = -1220.0, z = 13.0, w = 120.0 }, } spawn.coords = options[math.random(#options)] return spawnendRules:
- The function runs on the server. Do not call client only natives in it.
- Use the function’s name as text in
spawnfunction. - The returned table must have
coordswithx,yandz.wis the heading and defaults to0.0. Ifcoordsis missing, the spawn is not applied and the player stays on the selector.
Adapting to another framework
Section titled “Adapting to another framework”shared/framework/framework.lua finds the framework and exposes three helpers used by the resource:
| Function | Returns |
|---|---|
Framework.GetPlayer(source) |
A table with source, identifier, name, isLoggedIn and raw, or nil when the player is not loaded. |
Framework.GetIdentifier(source) |
The player’s identifier: the citizen id on QBX and QBCore, the character identifier on ESX. Falls back to the Rockstar identifier. |
Framework.GetPlayerName(source) |
The name shown for the player. |
Kivo Spawn opens automatically after the player is loaded for ESX, QBCore and QBX. For another framework, add detection and a player lookup to that file, then open the selector yourself from your framework’s player loaded event.
Add this at the end of the detectFramework function in shared/framework/framework.lua:
if GetResourceState('my_core') == 'started' then -- placeholder resource name Framework.Name = 'MyCore' returnendAdd this branch in getRawPlayer, before the final generic return:
if Framework.Name == 'MyCore' then local player = exports['my_core']:GetPlayer(source) -- placeholder export if not player then return nil end
return { source = source, identifier = player.identifier, name = player.fullName, isLoggedIn = true, raw = player, }endOpen the selector from your framework’s client event (in your own resource, or any client script):
RegisterNetEvent('my_core:client:playerLoaded', function() -- placeholder event exports['kivo-spawn']:openSpawnUI()end)my_core, GetPlayer, fullName and the event name are placeholders. Replace them with the real names from your framework.
Using Kivo Spawn with another multicharacter script
Section titled “Using Kivo Spawn with another multicharacter script”With a multicharacter script other than Kivo Multichar, Kivo Spawn runs in its own mode. It opens when your framework reports the character as loaded.
- Remove the other script’s own spawn selector step so only Kivo Spawn places the player.
- If the selector does not open by itself, call
exports['kivo-spawn']:openSpawnUI()from the moment your multicharacter script finishes logging the character in. - Test with a new and a returning character.
Replacing Kivo Spawn
Section titled “Replacing Kivo Spawn”To use a different spawn selector with Kivo Multichar, change Multichar’s Config.spawnSelector and its spawn bridge. See Replace the spawn selector.
