IsTrainDerailed: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Making the example actually work and improving quality)
Line 17: Line 17:
==Example==
==Example==
<section name="Example" class="server" show="true">
<section name="Example" class="server" show="true">
This example lets a player check if the train their driving has derailed.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function checkDerailed(player)
function checkDerailed(thePlayer)
     if isPedInVehicle(player) and getVehicleType(getPedOccupiedVehicle(player) then --is the player in a vehicle and is it a train?
    local theTrain = getPedOccupiedVehicle(thePlayer)
         if isTrainDerailed(getPedOccupiedVehicle(player)) then --is the train derailed?
     if ( theTrain and getVehicleType(theTrain) == "Train" ) then --is the player in a vehicle and is it a train?
             outputChatBox("Your train is derailed", player) --outputs a message
         if ( isTrainDerailed(theTrain) ) then --is the train derailed?
             outputChatBox("Your train is derailed", thePlayer, 255, 255, 0) --outputs a message
        else
            outputChatBox("Your train is not derailed", thePlayer, 0, 255, 0) --outputs a message
         end
         end
     end
     end

Revision as of 16:15, 12 October 2011

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

Syntax

bool isTrainDerailed ( vehicle vehicleToCheck )              

Required Arguments

  • vehicleToCheck: The vehicle that you wish to check is derailed.

Returns

Returns true if the train is derailed, false if the train is still on the rails

Example

Click to collapse [-]
Example

This example lets a player check if the train their driving has derailed.

function checkDerailed(thePlayer)
    local theTrain = getPedOccupiedVehicle(thePlayer)
    if ( theTrain and getVehicleType(theTrain) == "Train" ) then --is the player in a vehicle and is it a train?
        if ( isTrainDerailed(theTrain) ) then --is the train derailed?
            outputChatBox("Your train is derailed", thePlayer, 255, 255, 0) --outputs a message
        else
            outputChatBox("Your train is not derailed", thePlayer, 0, 255, 0) --outputs a message
        end
    end
end
addCommandHandler("checkTrain", checkDerailed) --adds the command handler

See Also