Resource:Spawnmanager/createSpawnpoint: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server function}} This function creates a spawnpoint. ==Syntax== <syntaxhighlight lang="lua"> spawnpoint createSpawnpoint ( float x, float y, float z, [ float rotation = 0, int skin = 0, ...)
 
 
(5 intermediate revisions by 2 users not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
spawnpoint createSpawnpoint ( float x, float y, float z, [ float rotation = 0, int skin = 0,  int interior, int dimension ] )
spawnpoint createSpawnpoint ( float x, float y, float z, [ float rotation = 0, int skin = 0,  int interior = 0, int dimension = 0 ] )
</syntaxhighlight>  
</syntaxhighlight>  


Line 11: Line 11:
*'''x''': A floating point number representing the X coordinate on the map.
*'''x''': A floating point number representing the X coordinate on the map.
*'''y''': A floating point number representing the Y coordinate on the map.
*'''y''': A floating point number representing the Y coordinate on the map.
*'''z''': A floating point number representing the Z coordinate on the map.  
*'''z''': A floating point number representing the Z coordinate on the map.
 
===Optional Arguments===
*'''rotation:''' A floating point number representing the spawn's rotation about the Z axis in degrees.
*'''rotation:''' A floating point number representing the spawn's rotation about the Z axis in degrees.
*'''skin:''' An integer representing the skin ID (see [[Character_Skins|character skins]]).
*'''skin:''' An integer representing the skin ID (see [[Character_Skins|character skins]]).
*'''interior:''' An integer representing the interior in which the spawnpoint spawns players.
*'''dimension:''' An integer representing the diimension in which the spawnpoint spawns players.


===Returns===
===Returns===
Returns the [[spawnpoint]] element if creation was successful, ''false'' otherwise.
Returns the spawnpoint element if creation was successful, ''false'' otherwise.


==Example==  
==Example==  
This function lets the player create a new spawnpoint where he stands, with the skin of his choice.
This function lets the player create a new spawnpoint where he stands, with the skin of his choice.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function createSP( source, command, skin )
local spawnpointsTable = { }
      local x, y, z = getElementPosition( source ) --Get the players location
      local rot = getPlayerRotation( source ) --Get the players rotation
function createSpawnpointCmd(player,cmd,arg1)
      local theSpawnpoint = call(getResourceFromName("spawnmanager", "createSpawnpoint", x, y, z, rot, skin ) --Create the spawnpoint.
    local x, y, z = getElementPosition(player)
      if ( theSpawnpoint ) then
    local rot = getPlayerRotation(player)
            outputConsole ( "Spawnpoint created.", source ) --notify the player if it was successful
    local int = getElementInterior(player)
      end
    local dim = getElementDimension(player)
    local skin = getElementModel(player)
 
    local spawnpoint = exports.spawnmanager:createSpawnpoint(x, y, z, rot, skin, int, dim)
 
    if spawnpoint then
        table.insert(spawnpointsTable, spawnpoint)
        outputChatBox("Created Spawn Point", player)
    else
        outputChatBox("Failed to create Spawn Point", player)
    end
end
end
addCommandHandler( "mark", createSP )
addCommandHandler("mark",createSpawnpointCmd)
</syntaxhighlight>
</syntaxhighlight>
==See Also==
{{Spawnpoint functions}}

Latest revision as of 00:58, 19 April 2016

This function creates a spawnpoint.

Syntax

spawnpoint createSpawnpoint ( float x, float y, float z, [ float rotation = 0, int skin = 0,  int interior = 0, int dimension = 0 ] )

Required Arguments

  • x: A floating point number representing the X coordinate on the map.
  • y: A floating point number representing the Y coordinate on the map.
  • z: A floating point number representing the Z coordinate on the map.
  • rotation: A floating point number representing the spawn's rotation about the Z axis in degrees.
  • skin: An integer representing the skin ID (see character skins).
  • interior: An integer representing the interior in which the spawnpoint spawns players.
  • dimension: An integer representing the diimension in which the spawnpoint spawns players.

Returns

Returns the spawnpoint element if creation was successful, false otherwise.

Example

This function lets the player create a new spawnpoint where he stands, with the skin of his choice.

local spawnpointsTable = { }
 
function createSpawnpointCmd(player,cmd,arg1)
    local x, y, z = getElementPosition(player)
    local rot = getPlayerRotation(player)
    local int = getElementInterior(player)
    local dim = getElementDimension(player)
    local skin = getElementModel(player)
   
    local spawnpoint = exports.spawnmanager:createSpawnpoint(x, y, z, rot, skin, int, dim)
   
    if spawnpoint then
        table.insert(spawnpointsTable, spawnpoint)
         outputChatBox("Created Spawn Point", player)
    else
         outputChatBox("Failed to create Spawn Point", player)
    end
end
addCommandHandler("mark",createSpawnpointCmd)