IsTrainDerailable: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Example added)
(PROPER example added)
Line 15: Line 15:


==Example==
==Example==
This example outputs to the player if the train which he's entered is derrailable or not
This example warns the player if their train can be derailed.
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
trainModels = { 449, 537, 538, 570, 569, 590 }
local function playerVehicleEnter()
lp = getLocalPlayer()
local localVehicle = getPedOccupiedVehicle(localPlayer)
function playerEntered(theVehicle)
if not isElement(localVehicle) then return end -- In case getPedOccupiedVehicle() does not return a valid vehicle, for whatever reason
for i,v in ipairs(trainModels) do
if getElementModel(theVehicle) == v then
if getVehicleType(localVehicle) == "Train" then
if isTrainDerailable(theVehicle) then
if isTrainDerailable(localVehicle) then
outputChatBox("Warning: this train could be derailed.")
outputChatBox("* Warning: this train could derail!", 255, 0, 0)
return
else
outputChatBox("This train is safe.")
end
end
end
end
end
end
end
 
addEventHandler("onClientPlayerVehicleEnter", localPlayer, playerVehicleEnter)
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), playerEntered)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 04:04, 15 May 2012

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

Syntax

bool isTrainDerailable ( vehicle vehicleToCheck )              

Required Arguments

  • vehicleToCheck: The vehicle you wish to check.

Returns

Returns true if the train is derailable, false otherwise.

Example

This example warns the player if their train can be derailed.

Click to collapse [-]
Client
local function playerVehicleEnter()
	local localVehicle = getPedOccupiedVehicle(localPlayer)
	if not isElement(localVehicle) then return end -- In case getPedOccupiedVehicle() does not return a valid vehicle, for whatever reason
	
	if getVehicleType(localVehicle) == "Train" then
		if isTrainDerailable(localVehicle) then
			outputChatBox("* Warning: this train could derail!", 255, 0, 0)
		end
	end
end
addEventHandler("onClientPlayerVehicleEnter", localPlayer, playerVehicleEnter)

See Also