- Documentation
- Server functions
- spawnPlayer
Function
spawnPlayer
Spawns a player at the given place: position, rotation, skin, interior and dimension.
Syntax
bool spawnPlayer(player player, float x, float y, float z [, float rotation = 0, int skin = 0, int interior = 0, int dimension = 0])Arguments
playerplayer- The player to spawn.
x, y, zfloat- Position in the world. It is worth giving
za few centimetres above the ground. rotationfloat, optional = 0- The direction the player faces, in degrees.
skinint, optional = 0- Character model number.
0is CJ.Not in MTA:SA interiorint, optional = 0- Interior number.
0is the outside world.Not in MTA:SA dimensionint, optional = 0- Dimension. Players in different dimensions cannot see each other.Not in MTA:SA
Differences from MTA:SA
- Arguments in a different colour differ from MTA:SA.
In MTA:SA
spawnPlayer(player thePlayer, float x, float y, float z, int rotation = 0)Returns
true if the player was spawned, or false on a bad argument.
Example
After joining and after every death, the player appears near Grove Street with a random skin from a list.
local SKINS = { 0, 105, 106, 107 }
local function respawn(player)
local skin = SKINS[math.random(#SKINS)]
spawnPlayer(player, 2495.3, -1687.0, 13.5, 0, skin)
end
addEventHandler("onPlayerJoin", root, function()
respawn(source)
end)
addEventHandler("onPlayerWasted", root, function()
-- 3 seconds for the death screen, then back in
setTimer(respawn, 3000, 1, source)
end)
Notes
Good to know. After spawning, the onPlayerSpawn event is triggered. A new player does not appear in the world until a script calls spawnPlayer.