IsTrainChainEngine: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(add oop syntax)
Line 9: Line 9:
bool isTrainChainEngine ( vehicle theTrain )   
bool isTrainChainEngine ( vehicle theTrain )   
</syntaxhighlight>  
</syntaxhighlight>  
 
{{New feature/item|3.0141|1.4.1|6946|{{OOP||[[Element/Vehicle|vehicle]]:isTrainChainEngine|trainChainEngine}}}}
===Arguments===  
===Arguments===  
*'''theTrain:''' a [[Element/Vehicle|train]] to check if it's a chain engine or not.
*'''theTrain:''' a [[Element/Vehicle|train]] to check if it's a chain engine or not.


===Returns===
===Returns===
Returns ''true'' if a [[Element/Vehicle|train]] was passed to the function and if it's a chain engine. Returns ''false'' otherwise.
* ''true'' if a [[Element/Vehicle|train]] was passed to the function and if it's a chain engine.
* ''false'' otherwise.


==Example==
==Example==

Revision as of 10:59, 24 November 2014

This function checks if a train is a chain engine (moves the rest of the chain's carriages) or not.

Syntax

bool isTrainChainEngine ( vehicle theTrain )   

OOP Syntax Help! I don't understand this!

Method: vehicle:isTrainChainEngine(...)
Variable: .trainChainEngine

Arguments

  • theTrain: a train to check if it's a chain engine or not.

Returns

  • true if a train was passed to the function and if it's a chain engine.
  • false otherwise.

Example

The next code snippet adds a /isthistrainachainengine, which checks if the train occupied by the player who types the command is a chain engine or not.

function checkTrainChainEngine()
    if isPedInVehicle(localPlayer) and getVehicleType(getPedOccupiedVehicle(localPlayer)) == "Train" then
        local train = getPedOccupiedVehicle(localPlayer)
        outputChatBox("Your train " .. (isTrainChainEngine(train) and "is" or "isn't") .. " a chain engine.", 255, 128, 0)
    else
        outputChatBox("You need to be in a train to use this command.", 255, 0, 0)
    end
end
addCommandHandler("isthistrainachainengine", checkTrainChainEngine)

See also