SpawnPlayer: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (→See Also) |
||
(32 intermediate revisions by 21 users not shown) | |||
Line 1: | Line 1: | ||
{{Server function}} | |||
__NOTOC__ | __NOTOC__ | ||
This function spawns the player at an arbitrary point on the map.<br> | |||
This function spawns the player at an | {{Note|[[setCameraTarget]] must be used to focus on the player. Also, all players have their camera initially faded out after connect. To ensure that the camera is faded in, please do a [[fadeCamera]] after.}} | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool spawnPlayer ( player thePlayer, float x, float y, float z, [ int rotation = 0, int skinID = 0, int interior = 0, int dimension = 0, team theTeam = | bool spawnPlayer ( player thePlayer, float x, float y, float z, [ int rotation = 0, int skinID = 0, int interior = 0, int dimension = 0, team theTeam = getPlayerTeam(thePlayer) ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[player]]:spawn||}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''x:''' The x co-ordinate to spawn the player at | *'''thePlayer:''' The player you want to spawn. | ||
*'''y:''' The y co-ordinate to spawn the player at | *'''x:''' The x co-ordinate to spawn the player at. | ||
*'''z:''' The z co-ordinate to spawn the player at | *'''y:''' The y co-ordinate to spawn the player at. | ||
*'''z:''' The z co-ordinate to spawn the player at. | |||
===Optional Arguments=== | ===Optional Arguments=== | ||
*'''rotation:''' rotation of the player on spawn | *'''rotation:''' rotation of the player on spawn. | ||
*'''skinID:''' | *'''skinID:''' player's skin on spawn. [[Character Skins]] | ||
*'''interior:''' interior the player will spawn into | *'''interior:''' interior the player will spawn into. [[Interior IDs]] | ||
*'''dimension:''' The ID of the [[dimension]] that the player should be in | *'''dimension:''' The ID of the [[dimension]] that the player should be in. | ||
*'''theTeam:''' the team the player will join | *'''theTeam:''' the team the player will join. | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if the player was spawned successfully, ''false'' otherwise. | Returns ''true'' if the player was spawned successfully, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example spawns all the players in the middle of the game map. | This example spawns all the players in the middle of the game map. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- Get a table of all the players | -- Get a table of all the players | ||
players = getElementsByType ( "player" ) | local players = getElementsByType ( "player" ) | ||
-- Go through every player | -- Go through every player | ||
for | for _, player in ipairs(players) do | ||
-- Spawn them at the desired coordinates | -- Spawn them at the desired coordinates | ||
spawnPlayer ( | spawnPlayer ( player, 0.0, 0.0, 5.0, 90.0, 0 ) | ||
fadeCamera ( player, true) | |||
setCameraTarget ( player, player ) | |||
end | |||
</syntaxhighlight> | |||
This example spawns a player '''when he logs in.''' | |||
<syntaxhighlight lang="lua"> | |||
spawnTeam = createTeam ("Teamname", 255, 0, 0) -- Create team to spawn. | |||
function spawnOnLogin (prevA, curA ) | |||
outputChatBox ("Welcome to ...", source, 255, 0, 0, false) | |||
spawnPlayer (source, 0, 0, 5, 0, math.random (0,288), 0, 0, spawnTeam) -- spawns player with random skin | |||
fadeCamera (source, true) | |||
setCameraTarget (source, source) | |||
end | end | ||
addEventHandler("onPlayerLogin", root, spawnOnLogin) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{ | {{Player functions|server}} | ||
[[ru:spawnPlayer]] |
Latest revision as of 22:44, 6 September 2024
This function spawns the player at an arbitrary point on the map.
Syntax
bool spawnPlayer ( player thePlayer, float x, float y, float z, [ int rotation = 0, int skinID = 0, int interior = 0, int dimension = 0, team theTeam = getPlayerTeam(thePlayer) ] )
OOP Syntax Help! I don't understand this!
- Method: player:spawn(...)
Required Arguments
- thePlayer: The player you want to spawn.
- x: The x co-ordinate to spawn the player at.
- y: The y co-ordinate to spawn the player at.
- z: The z co-ordinate to spawn the player at.
Optional Arguments
- rotation: rotation of the player on spawn.
- skinID: player's skin on spawn. Character Skins
- interior: interior the player will spawn into. Interior IDs
- dimension: The ID of the dimension that the player should be in.
- theTeam: the team the player will join.
Returns
Returns true if the player was spawned successfully, false otherwise.
Example
This example spawns all the players in the middle of the game map.
-- Get a table of all the players local players = getElementsByType ( "player" ) -- Go through every player for _, player in ipairs(players) do -- Spawn them at the desired coordinates spawnPlayer ( player, 0.0, 0.0, 5.0, 90.0, 0 ) fadeCamera ( player, true) setCameraTarget ( player, player ) end
This example spawns a player when he logs in.
spawnTeam = createTeam ("Teamname", 255, 0, 0) -- Create team to spawn. function spawnOnLogin (prevA, curA ) outputChatBox ("Welcome to ...", source, 255, 0, 0, false) spawnPlayer (source, 0, 0, 5, 0, math.random (0,288), 0, 0, spawnTeam) -- spawns player with random skin fadeCamera (source, true) setCameraTarget (source, source) end addEventHandler("onPlayerLogin", root, spawnOnLogin)
See Also
- getAlivePlayers
- getDeadPlayers
- getPlayerACInfo
- getPlayerAnnounceValue
- getPlayerCount
- getPlayerIdleTime
- getPlayerIP
- getPlayerVersion
- getRandomPlayer
- isPlayerMuted
- redirectPlayer
- resendPlayerACInfo
- resendPlayerModInfo
- setPlayerAnnounceValue
- setPlayerMuted
- setPlayerScriptDebugLevel
- setPlayerTeam
- setPlayerVoiceBroadcastTo
- setPlayerVoiceIgnoreFrom
- setPlayerWantedLevel
- spawnPlayer
- takePlayerScreenShot
- Shared
- getPlayerTeam
- getPlayerBlurLevel
- setPlayerBlurLevel
- getPlayerSerial
- forcePlayerMap
- getPlayerScriptDebugLevel
- getPlayerFromName
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerMapForced
- isPlayerNametagShowing
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney
- countPlayersInTeam
- getPlayersInTeam
- isVoiceEnabled
- setControlState
- getControlState