IsTrainChainEngine: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Server client function}} __NOTOC__ {{New items|3.0140|1.4| This function checks if a train is a chain engine (moves the rest of the chain's trains) or no...")
 
m (A little grammar correction at →‎Example)
Line 25: Line 25:
         outputChatBox("Your train " .. (isTrainChainEngine(train) and "is" or "isn't") .. " a chain engine.", player, 255, 128, 0)
         outputChatBox("Your train " .. (isTrainChainEngine(train) and "is" or "isn't") .. " a chain engine.", player, 255, 128, 0)
     else
     else
         outputChatBox("You need to be in a train for using this command.", player, 255, 0, 0)
         outputChatBox("You need to be in a train to use this command.", player, 255, 0, 0)
     end
     end
end
end

Revision as of 10:33, 25 June 2014

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

Syntax

bool isTrainChainEngine( vehicle theTrain )   

Arguments

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

Returns

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

Example

Click to collapse [-]
Server

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(player)
    if isPedInVehicle(player) and getVehicleType(getPedOccupiedVehicle(player)) == "Train" then
        local train = getPedOccupiedVehicle(player)
        outputChatBox("Your train " .. (isTrainChainEngine(train) and "is" or "isn't") .. " a chain engine.", player, 255, 128, 0)
    else
        outputChatBox("You need to be in a train to use this command.", player, 255, 0, 0)
    end
end
addCommandHandler("isthistrainachainengine", checkTrainChainEngine)

See also