SpawnVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Undo revision 17632 by Syytuvanaema (Talk))
 
(8 intermediate revisions by 8 users not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool spawnVehicle ( vehicle theVehicle, float x, float y, float z, float rx, float ry, float rz )
bool spawnVehicle ( vehicle theVehicle, float x, float y, float z [, float rx, float ry, float rz ] )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[vehicle]]:spawn}}
===Required Arguments===  
===Required Arguments===  
*'''theVehicle:''' The vehicle you wish to spawn
*'''theVehicle:''' The vehicle you wish to spawn
Line 13: Line 13:
*'''y:''' The x position you wish to spawn the vehicle at
*'''y:''' The x position you wish to spawn the vehicle at
*'''z:''' The x position you wish to spawn the vehicle at
*'''z:''' The x position you wish to spawn the vehicle at
===Optional Arguments===
{{OptionalArg}}
*'''rx:''' The x rotation you wish to spawn the vehicle at
*'''rx:''' The x rotation you wish to spawn the vehicle at
*'''ry:''' The y rotation you wish to spawn the vehicle at
*'''ry:''' The y rotation you wish to spawn the vehicle at
Line 21: Line 24:


==Example==
==Example==
NEEDS CHECKING
<section name="Server" class="server" show="true">
<section name="Example: Server" class="server" show="true">
With this feature, we spawn vehicle
This script spawns a car 5 units to the right of player.
<syntaxhighlight lang="lua">function myCommandHandler(thePlayer, command)
<syntaxhighlight lang="lua">
local x, y, z = getElementPosition(thePlayer)
function spawncar( source, commandName, carid )
local RaceVehicle = createVehicle ( 411, 0, 0, 0 )  
if ( isPlayerInVehicle ( source ) == false ) then
local spawnVeh = spawnVehicle ( RaceVehicle, x+3, y+3, z )
local x, y, z = getElementPosition ( source )
if spawnVeh then outputChatBox("Vehicle was spawned", thePlayer) else outputChatBox("Error",thePlayer) end
local rotZ = getPlayerRotation ( source )
x = x + ( ( math.cos ( math.rad ( rotZ ) ) ) * 5 )
y = y + ( ( math.sin ( math.rad ( rotZ ) ) ) * 5 )
if ( spawnVehicle ( carid, x, y, z, 0, 0, rotZ ) ) then
outputChatBox ( "You spawned a car!", source, 0, 255, 0, true )
else
outputChatBox ( "Failed to spawn a car!", source, 0, 255, 0, true )
end
end
end
end
addCommandHandler ( "car", spawncar )
 
addCommandHandler("spawnvehicle", myCommandHandler)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


==Related scripting functions==
==Related scripting functions==
{{Vehicle functions}}
{{Vehicle_functions|server}}
[[Category:Element Types]]

Latest revision as of 23:05, 6 September 2024

Spawns a vehicle at any given position and rotation

Syntax

bool spawnVehicle ( vehicle theVehicle, float x, float y, float z [, float rx, float ry, float rz ] )

OOP Syntax Help! I don't understand this!

Method: vehicle:spawn(...)


Required Arguments

  • theVehicle: The vehicle you wish to spawn
  • x: The x position you wish to spawn the vehicle at
  • y: The x position you wish to spawn the vehicle at
  • z: The x position you wish to spawn the vehicle at

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • rx: The x rotation you wish to spawn the vehicle at
  • ry: The y rotation you wish to spawn the vehicle at
  • rz: The z rotation you wish to spawn the vehicle at

Returns

Returns true if the vehicle spawned successfully, false if the passed argument does not exist or is not a vehicle.

Example

Click to collapse [-]
Server

With this feature, we spawn vehicle

function myCommandHandler(thePlayer, command)
	local x, y, z = getElementPosition(thePlayer)
	local RaceVehicle = createVehicle ( 411, 0, 0, 0 ) 
	local spawnVeh = spawnVehicle ( RaceVehicle, x+3, y+3, z )	
	if spawnVeh	then	outputChatBox("Vehicle was spawned", thePlayer)	else	outputChatBox("Error",thePlayer)	end
end

addCommandHandler("spawnvehicle", myCommandHandler)

Related scripting functions