SetTrainDerailable: Difference between revisions
Jump to navigation
Jump to search
Cazomino05 (talk | contribs) m (void -> bool) |
Dutchman101 (talk | contribs) (added another example) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | {{Server client function}} | ||
This function will set a train or tram as derailable. This is, if it can derail when it goes above the maximum speed. | This function will set a train or tram as derailable. This is, if it can derail when it goes above the maximum speed. | ||
Line 7: | Line 6: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool setTrainDerailable ( vehicle derailableVehicle, bool derailable ) | bool setTrainDerailable ( vehicle derailableVehicle, bool derailable ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[vehicle]]:setDerailable|derailable|isTrainDerailable}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''derailableVehicle:''' The vehicle that you wish to set derailable. | *'''derailableVehicle:''' The vehicle that you wish to set derailable. | ||
Line 17: | Line 16: | ||
==Example== | ==Example== | ||
<section name=" | <section name="Client" class="client" show="true"> | ||
This example will allow players to toggle derailability of the train they are driving | |||
<syntaxhighlight lang="lua"> | |||
function derailToggle() | |||
local vehicle = getPedOccupiedVehicle(localPlayer) | |||
if not vehicle then return end | |||
if getVehicleType(vehicle) == "Train" and getVehicleController(vehicle) == localPlayer then | |||
setTrainDerailable(vehicle, not isTrainDerailable(vehicle)) | |||
outputChatBox("Derailing for this train has been toggled!") | |||
end | |||
end | |||
addCommandHandler("togglederail", derailToggle) | |||
</syntaxhighlight> | |||
</section> | |||
<section name="Server" class="server" show="true"> | |||
This example will make a train east of LS station which can not be derailed, and start moving it. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | function makeTrain(source) | ||
local myTrain = createVehicle(537,1995,-1949,13) -- This will make a freight train just east of the LS train station | |||
setTrainDerailable(myTrain, false) -- myTrain can not be derailed now | |||
outputChatBox("A freight train has been created for you.", source, 255, 255, 0) -- Just a simple message for the player | |||
warpPedIntoVehicle(source, myTrain) -- This will warp you to inside the train | |||
setTrainSpeed(myTrain, 1) -- Set the train speed to 1 - 100mph, 160kmh | |||
end | |||
addCommandHandler("trainmeup", makeTrain) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Latest revision as of 12:48, 11 February 2021
This function will set a train or tram as derailable. This is, if it can derail when it goes above the maximum speed.
Syntax
bool setTrainDerailable ( vehicle derailableVehicle, bool derailable )
OOP Syntax Help! I don't understand this!
- Method: vehicle:setDerailable(...)
- Variable: .derailable
- Counterpart: isTrainDerailable
Required Arguments
- derailableVehicle: The vehicle that you wish to set derailable.
- derailable: whether the train or tram is derailable. True as derailable, False as non-derailable.
Returns
Returns true if the state was successfully set, false otherwise.
Example
Click to collapse [-]
ClientThis example will allow players to toggle derailability of the train they are driving
function derailToggle() local vehicle = getPedOccupiedVehicle(localPlayer) if not vehicle then return end if getVehicleType(vehicle) == "Train" and getVehicleController(vehicle) == localPlayer then setTrainDerailable(vehicle, not isTrainDerailable(vehicle)) outputChatBox("Derailing for this train has been toggled!") end end addCommandHandler("togglederail", derailToggle)
Click to collapse [-]
ServerThis example will make a train east of LS station which can not be derailed, and start moving it.
function makeTrain(source) local myTrain = createVehicle(537,1995,-1949,13) -- This will make a freight train just east of the LS train station setTrainDerailable(myTrain, false) -- myTrain can not be derailed now outputChatBox("A freight train has been created for you.", source, 255, 255, 0) -- Just a simple message for the player warpPedIntoVehicle(source, myTrain) -- This will warp you to inside the train setTrainSpeed(myTrain, 1) -- Set the train speed to 1 - 100mph, 160kmh end addCommandHandler("trainmeup", makeTrain)
See Also
- addVehicleUpgrade
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getTrainTrack
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- getVehicleOccupant
- getVehicleOccupants
- getVehicleOverrideLights
- getVehiclePaintjob
- getVehiclePanelState
- getVehiclePlateText
- getVehicleSirenParams
- getVehicleSirens
- getVehicleSirensOn
- getVehicleTowedByVehicle
- getVehicleTowingVehicle
- getVehicleTurretPosition
- getVehicleType
- getVehicleUpgradeOnSlot
- getVehicleUpgradeSlotName
- getVehicleUpgrades
- getVehicleVariant
- getVehicleWheelStates
- isTrainDerailable
- isTrainDerailed
- isVehicleBlown
- isVehicleDamageProof
- isVehicleFuelTankExplodable
- isVehicleLocked
- isVehicleOnGround
- isVehicleTaxiLightOn
- removeVehicleUpgrade
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setTrainTrack
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates