BlowVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(12 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server client function}}
This function will blow up a vehicle. This will cause an explosion and will kill the driver and any passengers inside it.
This function will blow up a vehicle. This will cause an explosion and will kill the driver and any passengers inside it.


==Syntax==  
==Syntax==  
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool blowVehicle ( vehicle vehicleToBlow, [ bool explode=true ] )            
bool blowVehicle ( vehicle vehicleToBlow, [ bool explode=true ] )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[vehicle]]:blow|blown|isVehicleBlown}}
===Required Arguments===  
===Required Arguments===  
*'''vehicleToBlow:''' The vehicle that you wish to blow up.
*'''vehicleToBlow:''' the vehicle that you wish to blow up.
 
===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
*'''explode:''' If this argument is ''true'' then the vehicle will explode, otherwise it will just be blown up silently.
*'''explode:''' if this argument is ''true'' then the vehicle will explode, otherwise it will just be blown up silently.
 
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool blowVehicle ( vehicle vehicleToBlow )
</syntaxhighlight>
{{OOP||[[vehicle]]:blow}}
===Required Arguments===
*'''vehicleToBlow:''' the vehicle that you wish to blow up.
</section>
===Returns===
===Returns===
Returns ''true'' if the vehicle was blown up, ''false'' if invalid arguments were passed to the function.
Returns ''true'' if the vehicle was blown up, ''false'' if invalid arguments were passed to the function.


==Example==  
==Example==  
<section name="Example 1: Server and client" class="both" show="true">
This example will blow up every vehicle in the game.
This example will blow up every vehicle in the game.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
vehicles = getElementsByType ( "vehicle" )
vehicles = getElementsByType ( "vehicle" )
for vehicleKey, vehicleValue in vehicles do
for vehicleKey, vehicleValue in ipairs(vehicles) do
blowVehicle ( vehicleValue )
blowVehicle ( vehicleValue )
end
end
Line 28: Line 38:
It is worth noting that the same could be achieved with the following:
It is worth noting that the same could be achieved with the following:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
root = getRootElement ()
blowVehicle ( root ) -- root (getRootElement) is a built in MTA variable and therefore we do not have to define it.
blowVehicle ( root )
</syntaxhighlight>
</section>
 
<section name="Example 2: Server" class="server" show="true">
This example will blow a player's vehicle when he enters the car, like a carbomb.
<syntaxhighlight lang="lua">
riggedVehicle = createVehicle(445, 0, 0, 5)
function blowVehicleEnter ( thePlayer, seat, jacked )
--ENGINE START BOMB.
if seat == 0 then --check if the seat the player got into was id 0 - i.e. driver seat
blowVehicle ( source ) --if it was, toast him
end
end
addEventHandler ( "onVehicleEnter", riggedVehicle, blowVehicleEnter ) --trigger the function when a certain vehicle is entered
</syntaxhighlight>
</section>
 
==Client Class Example==
'''Heads up!''' Client classes only work on '''MTA 1.4''', therefore we highly recommend you to visit [[Client_Scripting_Classes|Client Scripting Classes]] first.
<section name="Example 1: Client" class="client" show="true">
This script will create an Infernus at the center (0, 0, 3) of San Andreas upon execution.
<syntaxhighlight lang="lua">
addEventHandler( "onClientResourceStart", resourceRoot,
    function()
        infernus = Vehicle.create( 411, Vector3( 0, 0, 3 ) ); -- Create an Infernus and spawn it at the middle of SA.
        infernus:setColor( 0, 0, 0 ); -- Set its color to black.
    end)
addCommandHandler( "blowinfernus",
    function()
        if not infernus.blown then -- Check if the Infernus is blown up or not.
            infernus:blow();
        else -- Ouch, it's blown up, let's output an error to the client.
            outputChatBox( "The Infernus has already been blown up by you.", 255, 0, 0, false );
        end
    end)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Vehicle_Functions}}
{{Vehicle_functions}}

Latest revision as of 22:33, 18 December 2014

This function will blow up a vehicle. This will cause an explosion and will kill the driver and any passengers inside it.

Syntax

Click to collapse [-]
Server
bool blowVehicle ( vehicle vehicleToBlow, [ bool explode=true ] )

OOP Syntax Help! I don't understand this!

Method: vehicle:blow(...)
Variable: .blown
Counterpart: isVehicleBlown


Required Arguments

  • vehicleToBlow: the vehicle that you wish to blow up.

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.

  • explode: if this argument is true then the vehicle will explode, otherwise it will just be blown up silently.
Click to collapse [-]
Client
bool blowVehicle ( vehicle vehicleToBlow )

OOP Syntax Help! I don't understand this!

Method: vehicle:blow(...)


Required Arguments

  • vehicleToBlow: the vehicle that you wish to blow up.

Returns

Returns true if the vehicle was blown up, false if invalid arguments were passed to the function.

Example

Click to collapse [-]
Example 1: Server and client

This example will blow up every vehicle in the game.

vehicles = getElementsByType ( "vehicle" )
for vehicleKey, vehicleValue in ipairs(vehicles) do
	blowVehicle ( vehicleValue )
end

It is worth noting that the same could be achieved with the following:

blowVehicle ( root ) -- root (getRootElement) is a built in MTA variable and therefore we do not have to define it.
Click to collapse [-]
Example 2: Server

This example will blow a player's vehicle when he enters the car, like a carbomb.

riggedVehicle = createVehicle(445, 0, 0, 5)
function blowVehicleEnter ( thePlayer, seat, jacked )
	--ENGINE START BOMB. 
	if seat == 0 then --check if the seat the player got into was id 0 - i.e. driver seat
		blowVehicle ( source ) --if it was, toast him
	end
end
addEventHandler ( "onVehicleEnter", riggedVehicle, blowVehicleEnter ) --trigger the function when a certain vehicle is entered

Client Class Example

Heads up! Client classes only work on MTA 1.4, therefore we highly recommend you to visit Client Scripting Classes first.

Click to collapse [-]
Example 1: Client

This script will create an Infernus at the center (0, 0, 3) of San Andreas upon execution.

addEventHandler( "onClientResourceStart", resourceRoot,
    function()
        infernus = Vehicle.create( 411, Vector3( 0, 0, 3 ) ); -- Create an Infernus and spawn it at the middle of SA.
        infernus:setColor( 0, 0, 0 ); -- Set its color to black.
    end)
	
addCommandHandler( "blowinfernus",
    function()
        if not infernus.blown then -- Check if the Infernus is blown up or not.
            infernus:blow();
        else -- Ouch, it's blown up, let's output an error to the client.
            outputChatBox( "The Infernus has already been blown up by you.", 255, 0, 0, false );
        end
    end)

See Also