SetVehicleTaxiLightOn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Removed needs checking, according to mantis this issue is resolved.)
(Replaced code example with something less messy)
 
(One intermediate revision by one other user not shown)
Line 7: Line 7:
bool setVehicleTaxiLightOn ( vehicle taxi, bool LightState )               
bool setVehicleTaxiLightOn ( vehicle taxi, bool LightState )               
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[vehicle]]:setTaxiLightOn|taxiLightOn|isVehicleTaxiLightOn}}
===Required Arguments===  
===Required Arguments===  
*'''taxi:''' The vehicle element of the taxi that you wish to turn the light on.
*'''taxi:''' The vehicle element of the taxi that you wish to turn the light on.
Line 16: Line 16:


==Example==
==Example==
This example sets the taxi light on when the player presses "o" in a taxi.
This example allows the driver of a taxi to toggle on/off taxi light with a command
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerJoin" , getRootElement ( ) ,
function toggleTaxiLight()
function ( )
local vehicle = getPedOccupiedVehicle(localPlayer)
  bindKey ( source , "o", "down",
if vehicle and getVehicleController(vehicle) == localPlayer then
    function ( thePlayer )
local vehModel = getElementModel(vehicle)
      if ( isPedInVehicle ( thePlayer ) ) then --is in vehicle or not?
if (vehModel) == 420 or (vehModel) == 438 then
        local vehicle = getPedOccupiedVehicle ( thePlayer ) --getting player's occupied vehicle
setVehicleTaxiLightOn (vehicle, not isVehicleTaxiLightOn(vehicle))
        if ( getVehicleController ( vehicle ) == thePlayer ) then --is driver or not?
else
          local id = getElementModel ( vehicle ) --getting vehicle's model
outputChatBox ("You're not in a Taxi!", 255, 0, 0, true)
          if ( ( id == 420 ) or ( id == 438 ) ) then --is a taxi?
end
            setVehicleTaxiLightOn ( vehicle, not isVehicleTaxiLightOn ( vehicle ) ) --changing taxi light on/off
end  
          end
end
        end
addCommandHandler("taxilight",toggleTaxiLight)
      end
  end)
end )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{vehicle functions}}
{{vehicle functions}}

Latest revision as of 02:25, 1 August 2018

This function will set the taxi light on in a taxi (vehicle ID's 420 and 438)

Syntax

bool setVehicleTaxiLightOn ( vehicle taxi, bool LightState )              

OOP Syntax Help! I don't understand this!

Method: vehicle:setTaxiLightOn(...)
Variable: .taxiLightOn
Counterpart: isVehicleTaxiLightOn


Required Arguments

  • taxi: The vehicle element of the taxi that you wish to turn the light on.
  • LightState: whether the light is on. True for on, False for off.

Returns

Returns true if the state was successfully set, false otherwise.

Example

This example allows the driver of a taxi to toggle on/off taxi light with a command

function toggleTaxiLight()
	local vehicle = getPedOccupiedVehicle(localPlayer)
		if vehicle and getVehicleController(vehicle) == localPlayer then
		local vehModel = getElementModel(vehicle)
			if (vehModel) == 420 or (vehModel) == 438 then
			setVehicleTaxiLightOn (vehicle, not isVehicleTaxiLightOn(vehicle))
		else
			outputChatBox ("You're not in a Taxi!", 255, 0, 0, true)
		end
	end 
end
addCommandHandler("taxilight",toggleTaxiLight)

See Also