SpawnVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
 
(22 intermediate revisions by 13 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server function}}
Respawns vehicles to where they were first spawned.
__NOTOC__
Spawns a vehicle at any given position and rotation


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool respawnVehicle ( vehicle thevehicle )
bool spawnVehicle ( vehicle theVehicle, float x, float y, float z [, float rx, float ry, float rz ] )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[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


===Required Arguments===  
===Optional Arguments===  
*'''thevehicle:''' The vehicle you wish to respawn
{{OptionalArg}}
*'''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===
Returns ''true'' if the vehicle respawned successfully, ''false'' if the passed argument does not exist or is not a vehicle.
Returns ''true'' if the vehicle spawned successfully, ''false'' if the passed argument does not exist or is not a vehicle.
 
==Example==
<section name="Server" class="server" show="true">
With this feature, we spawn vehicle
<syntaxhighlight lang="lua">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


==Example==
addCommandHandler("spawnvehicle", myCommandHandler)
<!-- Explain what the example is in a single sentance -->
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
--This line does...
blabhalbalhb --abababa
--This line does this...
mooo
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==Related scripting functions==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Vehicle_functions|server}}
{{Vehicle functions}}
[[Category:Incomplete]]

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