Difference between revisions of "IsVehicleTaxiLightOn"

From Multi Theft Auto: Wiki
Jump to: navigation, search
(Example)
m
 
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
__NOTOC__  
 
__NOTOC__  
[[Category:Needs_Example]]
 
 
{{Server client function}}
 
{{Server client function}}
This function will get the taxi light state of a taxi (vehicle ID's 420 and 438)
+
This function will get the taxi light state of a taxi (vehicle IDs 420 and 438)
  
 
==Syntax==  
 
==Syntax==  
Line 8: Line 7:
 
bool isVehicleTaxiLightOn ( vehicle taxi )               
 
bool isVehicleTaxiLightOn ( vehicle taxi )               
 
</syntaxhighlight>  
 
</syntaxhighlight>  
 
+
{{OOP||[[vehicle]]:isTaxiLightOn|taxiLightOn|setVehicleTaxiLightOn}}
 
===Required Arguments===  
 
===Required Arguments===  
 
*'''taxi:''' The vehicle element of the taxi that you wish to get the light state of.
 
*'''taxi:''' The vehicle element of the taxi that you wish to get the light state of.
Line 17: Line 16:
 
==Example==
 
==Example==
 
<section name="Client" class="client" show="true">
 
<section name="Client" class="client" show="true">
 +
This example binds the 'o' key to a function that toggles the taxi's light on and off, if you're in a taxi.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
function myfunction()
+
function toggleTaxiLight()
local player = getLocalPlayer()
+
  local thePlayer = getLocalPlayer()
local vehicle = getPlayerOccupiedVehicle(player)
+
  if isPedInVehicle(thePlayer) then
if player == getVehicleOccupant(vehicle, 0) then -- if is a driver
+
      local theVehicle = getPedOccupiedVehicle(thePlayer)
local lights = getVehicleTaxiLightOn(vehicle) -- getting vehicle lights state
+
      if thePlayer == getVehicleOccupant(theVehicle, 0) then -- if is a driver
local id = getElementModel(vehicle) -- getting vehicle model
+
local id = getElementModel(theVehicle) -- getting vehicle model
if ((id == 420) or (id== 438) then -- if is a taxi
+
if ((id == 420) or (id == 438)) then -- if is a taxi
setVehicleTaxiLightOn(vehicle, not lights) -- switch lights
+
    local lights = isVehicleTaxiLightOn(theVehicle) -- getting vehicle lights state
end
+
    setVehicleTaxiLightOn(theVehicle, not lights) -- switch lights
end
+
end
 +
      end
 +
  end
 
end
 
end
 
+
bindKey("o", "down", toggleTaxiLight) -- binding the function
bind("o", "down", myfunction) -- binding the function
 
 
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
</section>
 
</section>

Latest revision as of 23:01, 2 August 2016

This function will get the taxi light state of a taxi (vehicle IDs 420 and 438)

Syntax

bool isVehicleTaxiLightOn ( vehicle taxi )              

OOP Syntax Help! I don't understand this!

Method: vehicle:isTaxiLightOn(...)
Variable: .taxiLightOn
Counterpart: setVehicleTaxiLightOn

Required Arguments

  • taxi: The vehicle element of the taxi that you wish to get the light state of.

Returns

Returns true if the light is on, false otherwise.

Example

Click to collapse [-]
Client

This example binds the 'o' key to a function that toggles the taxi's light on and off, if you're in a taxi.

function toggleTaxiLight()
   local thePlayer = getLocalPlayer()
   if isPedInVehicle(thePlayer) then
      local theVehicle = getPedOccupiedVehicle(thePlayer)
      if thePlayer == getVehicleOccupant(theVehicle, 0) then -- if is a driver
	 local id = getElementModel(theVehicle) -- getting vehicle model
	 if ((id == 420) or (id == 438)) then -- if is a taxi
	    local lights = isVehicleTaxiLightOn(theVehicle) -- getting vehicle lights state
	    setVehicleTaxiLightOn(theVehicle, not lights) -- switch lights
	 end
      end	
   end
end
bindKey("o", "down", toggleTaxiLight) -- binding the function

See Also

FROM VERSION 1.6 r7485 ONWARDS
FROM VERSION 1.6 r7485 ONWARDS