SetTrainSpeed: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server client function}} Sets the on-track speed of a train. ==Syntax== <syntaxhighlight lang="lua">bool setTrainSpeed ( vehicle train, float speed )</syntaxhighlight> ===Required Arguments=== *'''trai...)
 
(correcting, setSpeed a nil value)
 
(6 intermediate revisions by 4 users not shown)
Line 6: Line 6:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool setTrainSpeed ( vehicle train, float speed )</syntaxhighlight>
<syntaxhighlight lang="lua">bool setTrainSpeed ( vehicle train, float speed )</syntaxhighlight>
 
{{OOP||[[vehicle]]:setTrainSpeed|trainSpeed|getTrainSpeed}}
===Required Arguments===
===Required Arguments===
*'''train:''' the train whose speed to change.
*'''train:''' the train whose speed to change.
Line 13: Line 13:
===Returns===
===Returns===
Returns ''true'' if successful, ''false'' otherwise.
Returns ''true'' if successful, ''false'' otherwise.
==Example==
<section name="Example" 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">
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>
</section>


==See Also==
==See Also==
{{Vehicle functions}}
{{Vehicle functions}}

Latest revision as of 10:33, 5 November 2023

Sets the on-track speed of a train.

Syntax

bool setTrainSpeed ( vehicle train, float speed )

OOP Syntax Help! I don't understand this!

Method: vehicle:setTrainSpeed(...)
Variable: .trainSpeed
Counterpart: getTrainSpeed


Required Arguments

  • train: the train whose speed to change.
  • speed: the new on-track speed of the train. A positive value will make it go clockwise, a negative value counter clockwise.

Returns

Returns true if successful, false otherwise.

Example

Click to collapse [-]
Example

This 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