SetTrainTrack: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(rewrite example)
Line 16: Line 16:


==Example==
==Example==
This server-side script allows the player to change the track of their train.
<syntaxhighlight lang="lua">
addCommandHandler("trackies",
function (player, _, track)
local theVehicle = getPedOccupiedVehicle(player)
if not theVehicle then
outputChatBox("You are not in a vehicle!")
return
end


<syntaxhighlight lang="lua">
if getVehicleType(theVehicle) == "Train" then
addCommandHandler("setTrain",
setTrainTrack(theVehicle, track)
function (cmd,train)
else
local thePlayer = getLocalPlayer()
outputChatBox("You are not in a train!")
local theVehicle = getPedOccupiedVehicle(thePlayer)
local cc = getElementModel(theVehicle)
if cc == 449 or cc == 537 or cc == 538 or cc == 570 or cc == 569 or cc == 590 then
setTrainTrack(theVehicle, train)
end
end
end)
end
)
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 20:30, 4 December 2015

Sets the track of a train

Syntax

bool setTrainTrack ( vehicle train, int track )

OOP Syntax Help! I don't understand this!

Method: vehicle:setTrack(...)
Variable: .track
Counterpart: getTrainTrack


Required Arguments

  • train: the train of which to set the track
  • track: the track where you want to set the train. It can be 0, 1, 2 or 3.

Returns

Returns true if the track was set to the train, false otherwise.

Example

This server-side script allows the player to change the track of their train.

addCommandHandler("trackies",
	function (player, _, track)
		local theVehicle = getPedOccupiedVehicle(player)
		if not theVehicle then
			outputChatBox("You are not in a vehicle!")
			return
		end

		if getVehicleType(theVehicle) == "Train" then
			setTrainTrack(theVehicle, track)
		else
			outputChatBox("You are not in a train!")
		end
	end
)

See Also