IsTrainDerailable: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ Category:Needs_Example {{Server client function}} This function will check if a train or tram is derailable. ==Syntax== <syntaxhighlight lang="lua"> bool isTrainDerailable ( vehicle vehi...)
 
No edit summary
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
[[Category:Needs_Example]]
{{Server client function}}
{{Server client function}}
This function will check if a train or tram is derailable.
This function will check if a train or tram is derailable.
Line 8: Line 7:
bool isTrainDerailable ( vehicle vehicleToCheck )               
bool isTrainDerailable ( vehicle vehicleToCheck )               
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[vehicle]]:isDerailable|derailable|setTrainDerailable}}
===Required Arguments===  
===Required Arguments===  
*'''vehicleToCheck:''' The vehicle you wish to check.
*'''vehicleToCheck:''' The vehicle you wish to check.


===Returns===
===Returns===
Returns ''true'' if the train is derailable, ''false'' otherwise.
Returns ''true'' if the train is derailable, ''false'' otherwise.


==Example==
==Example==
<section name="Example" class="server" show="true">
This example warns the player if their train can be derailed.
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- TODO
local function playerVehicleEnter()
local localVehicle = getPedOccupiedVehicle(localPlayer)
if not isElement(localVehicle) then return end -- In case getPedOccupiedVehicle() does not return a valid vehicle, for whatever reason
if getVehicleType(localVehicle) == "Train" then
if isTrainDerailable(localVehicle) then
outputChatBox("* Warning: this train could derail!", 255, 0, 0)
end
end
end
addEventHandler("onClientPlayerVehicleEnter", localPlayer, playerVehicleEnter)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


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

Latest revision as of 22:34, 18 December 2014

This function will check if a train or tram is derailable.

Syntax

bool isTrainDerailable ( vehicle vehicleToCheck )              

OOP Syntax Help! I don't understand this!

Method: vehicle:isDerailable(...)
Variable: .derailable
Counterpart: setTrainDerailable


Required Arguments

  • vehicleToCheck: The vehicle you wish to check.

Returns

Returns true if the train is derailable, false otherwise.

Example

This example warns the player if their train can be derailed.

Click to collapse [-]
Client
local function playerVehicleEnter()
	local localVehicle = getPedOccupiedVehicle(localPlayer)
	if not isElement(localVehicle) then return end -- In case getPedOccupiedVehicle() does not return a valid vehicle, for whatever reason
	
	if getVehicleType(localVehicle) == "Train" then
		if isTrainDerailable(localVehicle) then
			outputChatBox("* Warning: this train could derail!", 255, 0, 0)
		end
	end
end
addEventHandler("onClientPlayerVehicleEnter", localPlayer, playerVehicleEnter)

See Also