SetVehicleOverrideLights: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (OOP)
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function changes the overriding lights setting on a vehicle, possible values are: 1 (No override), 2 (Force off), 3 (Force on)
{{Server client function}}
This function changes the light overriding setting on a vehicle.
 
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool setVehicleOverrideLights ( vehicle theVehicle, int Value )</syntaxhighlight>
<syntaxhighlight lang="lua">bool setVehicleOverrideLights ( vehicle theVehicle, int value )</syntaxhighlight>
 
{{OOP||[[vehicle]]:setOverrideLights|overrideLights|getVehicleOverrideLights}}
===Required Arguments===
===Required Arguments===
*'''theVehicle''': The [[vehicle]] you wish to change the override lights setting of.
*'''theVehicle''': The [[vehicle]] you wish to change the override lights setting of.
*'''Value''': A whole number representing 1 of the 3 settings (0,1,2)
*'''value''': A whole number representing the state of the lights:
** '''0''': No override, lights are set to default.
** '''1''': Lights are forced off.
** '''2''': Lights are forced on.


==Returns==
==Returns==
Returns 'true' if the vehicle's lights settings was changed. Otherwise 'false'.
Returns ''true'' if the vehicle's lights setting was changed. Otherwise ''false''.


==Example==
==Example==
This example will toggle the car lights on and off for a player's vehicle
<section name="Example 1" class="server" show="true">
This example will toggle the car lights on and off for a player's vehicle by using a "vehiclelights" command.
<syntaxhighlight lang="lua">
function consoleVehicleLights ( source )
if isPedInVehicle(source) then -- checks is the player in vehicle if yes, then:
      playerVehicle = getPedOccupiedVehicle ( source )                -- get the player's vehicle
      if ( playerVehicle ) then                                        -- if he was in one
          if ( getVehicleOverrideLights ( playerVehicle ) ~= 2 ) then  -- if the current state isn't 'force on'
              setVehicleOverrideLights ( playerVehicle, 2 )            -- force the lights on
          else
              setVehicleOverrideLights ( playerVehicle, 1 )            -- otherwise, force the lights off
          end
      end
  end
end
addCommandHandler ( "vehiclelights", consoleVehicleLights )
</syntaxhighlight>
</section>
<section name="Example 2" class="client" show="true">
This example will toggle the car lights on and off for a player's vehicle by using a "vehiclelights" command.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler ( "vehiclelights", "vehicleLights" )
function consoleVehicleLights ()
function vehicleLights ( source )
if isPedInVehicle(getLocalPlayer()) then -- checks is the player in vehicle if yes, then:
  vehicle = getPlayerOccupiedVehicle ( source ) -- get the player's vehicle
      playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() )      -- get the local player's vehicle
  if ( vehicle ) then -- if he was in one
      if ( playerVehicle ) then                                       -- if he was in one
    if ( getVehicleOverrideLights ( vehicle ) ~= 2 ) then -- if the current state isnt 'force on'
          if ( getVehicleOverrideLights ( playerVehicle ) ~= 2 ) then -- if the current state isn't 'force on'
      setVehicleOverrideLights ( vehicle, 2 ) -- force the lights on
              setVehicleOverrideLights ( playerVehicle, 2 )           -- force the lights on
    else
          else
      setVehicleOverrideLights ( vehicle, 1 ) -- otherwise, force the lights off
              setVehicleOverrideLights ( playerVehicle, 1 )           -- otherwise, force the lights off
    end
          end
  end
      end
  end
end
end
addCommandHandler ( "vehiclelights", consoleVehicleLights )
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Latest revision as of 19:19, 4 June 2017

This function changes the light overriding setting on a vehicle.

Syntax

bool setVehicleOverrideLights ( vehicle theVehicle, int value )

OOP Syntax Help! I don't understand this!

Method: vehicle:setOverrideLights(...)
Variable: .overrideLights
Counterpart: getVehicleOverrideLights


Required Arguments

  • theVehicle: The vehicle you wish to change the override lights setting of.
  • value: A whole number representing the state of the lights:
    • 0: No override, lights are set to default.
    • 1: Lights are forced off.
    • 2: Lights are forced on.

Returns

Returns true if the vehicle's lights setting was changed. Otherwise false.

Example

Click to collapse [-]
Example 1

This example will toggle the car lights on and off for a player's vehicle by using a "vehiclelights" command.

function consoleVehicleLights ( source )
 if isPedInVehicle(source) then -- checks is the player in vehicle if yes, then:
       playerVehicle = getPedOccupiedVehicle ( source )                 -- get the player's vehicle
       if ( playerVehicle ) then                                        -- if he was in one
           if ( getVehicleOverrideLights ( playerVehicle ) ~= 2 ) then  -- if the current state isn't 'force on'
               setVehicleOverrideLights ( playerVehicle, 2 )            -- force the lights on
           else
               setVehicleOverrideLights ( playerVehicle, 1 )            -- otherwise, force the lights off
           end
       end
   end
end
addCommandHandler ( "vehiclelights", consoleVehicleLights )
Click to collapse [-]
Example 2

This example will toggle the car lights on and off for a player's vehicle by using a "vehiclelights" command.

function consoleVehicleLights ()
 if isPedInVehicle(getLocalPlayer()) then -- checks is the player in vehicle if yes, then: 
       playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() )       -- get the local player's vehicle
       if ( playerVehicle ) then                                        -- if he was in one
           if ( getVehicleOverrideLights ( playerVehicle ) ~= 2 ) then  -- if the current state isn't 'force on'
               setVehicleOverrideLights ( playerVehicle, 2 )            -- force the lights on
           else
               setVehicleOverrideLights ( playerVehicle, 1 )            -- otherwise, force the lights off
           end
       end
   end
end
addCommandHandler ( "vehiclelights", consoleVehicleLights )

See Also