OnPlayerSpawn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server event}}
This event is called when a player spawns.
This event is called when a player spawns.


==Syntax==  
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onPlayerSpawn ( spawnpoint theSpawnpoint, team theTeam )
float posX, float posY, float posZ, float spawnRotation, team theTeam, int theSkin, int theInterior, int theDimension
</syntaxhighlight>  
</syntaxhighlight>
 
*'''posX''': the X position the [[player]] spawned at.
*'''posY''': the Y position the [[player]] spawned at.
*'''posZ''': the Z position the [[player]] spawned at.
*'''spawnRotation''': the rotation the [[player]] spawned with.
*'''theTeam''': the [[team]] the [[player]] spawned with.
*'''theSkin''': the [[Character_Skins|skin/model]] the [[player]] spawned with.
*'''theInterior''': the [[interior]] the [[player]] spawned in.
*'''theDimension''': the [[dimension]] the [[player]] spawned in.


==Parameters==
==Source==
*The '''source''' of this event refers to the player who spawned.
The [[event system#Event source|source]] of this event is the [[player]] that just spawned.
*'''theSpawnpoint''':  a [[spawnpoint]] element representing the spawnpoint at which the player was spawned.
*'''theTeam''': a [[team]] element representing the team of the spawnpoint.


==Example==   
==Example==   
Line 16: Line 24:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- when a player spawns,
-- when a player spawns,
function player_Spawn ( inSpawnpoint, inTeam )
function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension )
-- play a frontend sound for him
-- play a frontend sound for him
playSoundFrontEnd ( source, 16 )
playSoundFrontEnd ( source, 16 )
Line 24: Line 32:
</syntaxhighlight>
</syntaxhighlight>


==See also==
<section name="Example 1" class="server" show="true">
{{Event functions}}
This example gives the player a weapon whenever he spawns
<syntaxhighlight lang="lua">
function Spawn()
    giveWeapon(source, 31, 500, true) -- Gives the weapon Ak-47, with 500 ammo and on the hand
end
addEventHandler("onPlayerSpawn", root, Spawn) -- This will exec every time a Player spawn
</syntaxhighlight>
</section>
 
{{See also/Server event|Player events}}

Latest revision as of 03:02, 27 September 2018

This event is called when a player spawns.

Parameters

float posX, float posY, float posZ, float spawnRotation, team theTeam, int theSkin, int theInterior, int theDimension

Source

The source of this event is the player that just spawned.

Example

This example plays a sound when a player spawns.

-- when a player spawns,
function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension )
	-- play a frontend sound for him
	playSoundFrontEnd ( source, 16 )
end
-- add the player_Spawn function as a handler for onPlayerSpawn
addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn )
Click to collapse [-]
Example 1

This example gives the player a weapon whenever he spawns

function Spawn()
    giveWeapon(source, 31, 500, true) -- Gives the weapon Ak-47, with 500 ammo and on the hand
end
addEventHandler("onPlayerSpawn", root, Spawn) -- This will exec every time a Player spawn

See Also

Player events


Event functions

Shared