AddVehicleSirens: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Number in the start of variable name looks not cool)
(Added a new and working example)
 
(One intermediate revision by one other user not shown)
Line 7: Line 7:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool addVehicleSirens ( vehicle theVehicle, int sirenCount, int sirenType [, bool flag360 = false, bool checkLosFlag = true, bool useRandomiser flag = true, bool silentFlag = false ] )
bool addVehicleSirens ( vehicle theVehicle, int sirenCount, int sirenType [, bool flag360 = false, bool checkLosFlag = true, bool useRandomiser = true, bool silentFlag = false ] )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[vehicle]]:addSirens}}
{{OOP||[[vehicle]]:addSirens}}
Line 22: Line 22:


===Returns===
===Returns===
Returns ''true'' if sirens were successfully added to the vehicle, ''false'' otherwise.  
Returns ''true'' if sirens were successfully added to the vehicle, ''false'' otherwise.


==Example==
==Example==
This example adds a vehicle siren on entering a vehicle and removes a vehicle siren on exiting. (TESTED!)
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">addEventHandler("onVehicleEnter", root, function(player, seat)
This example adds a siren for the vehicle, then sets two custom sirens at the top of the vehicle. And then removes the siren when getting out the vehicle.
   if (player) and (seat == 0) then
<syntaxhighlight lang="lua">
       addVehicleSirens(source, 1, 2)
addEventHandler('onPlayerVehicleEnter', root, function(vehicle, seat)
   if (seat == 0) then
       addVehicleSirens(vehicle, 2, 2)
      setVehicleSirens(vehicle, 1, -0.3, 0, 0.8, 0, 0, 255, 255, 255)
      setVehicleSirens(vehicle, 2, 0.3, 0, 0.8, 255, 0, 0, 255, 255)
      -- You can also make the sirens flash immediately with 'setVehicleSirensOn(vehicle, true)'
   end
   end
end)
end)


addEventHandler("onVehicleExit", root, function(player, seat)
addEventHandler('onPlayerVehicleExit', root, function(vehicle, seat)
   if (player) and (seat == 0) then
   removeVehicleSirens(vehicle)
      removeVehicleSirens(source)
  end
end)
end)
</syntaxhighlight>
</syntaxhighlight>
</section>


==Requirements==
==Requirements==

Latest revision as of 10:54, 11 October 2021

This function adds sirens to a vehicle.

Syntax

bool addVehicleSirens ( vehicle theVehicle, int sirenCount, int sirenType [, bool flag360 = false, bool checkLosFlag = true, bool useRandomiser = true, bool silentFlag = false ] )

OOP Syntax Help! I don't understand this!

Method: vehicle:addSirens(...)


Required Arguments

  • theVehicle: The vehicle to add sirens
  • sirenCount: The amount of siren points on the vehicle (8 maximum)
  • sirenType: An integer between 1 and 6 (1: invisible, 2: single, 3+: dual)

Optional Arguments

  • flag360: Visible from all directions (applies to single type only)
  • checkLosFlag: Check line of sight between camera and light so it won't draw if blocked
  • useRandomiser: Randomise the light order, false for sequential
  • silentFlag: If you want the siren to be silent set this to true

Returns

Returns true if sirens were successfully added to the vehicle, false otherwise.

Example

Click to collapse [-]
Server

This example adds a siren for the vehicle, then sets two custom sirens at the top of the vehicle. And then removes the siren when getting out the vehicle.

addEventHandler('onPlayerVehicleEnter', root, function(vehicle, seat)
   if (seat == 0) then
      addVehicleSirens(vehicle, 2, 2)
      setVehicleSirens(vehicle, 1, -0.3, 0, 0.8, 0, 0, 255, 255, 255)
      setVehicleSirens(vehicle, 2, 0.3, 0, 0.8, 255, 0, 0, 255, 255)
      -- You can also make the sirens flash immediately with 'setVehicleSirensOn(vehicle, true)'
   end
end)

addEventHandler('onPlayerVehicleExit', root, function(vehicle, seat)
   removeVehicleSirens(vehicle)
end)

Requirements

Minimum server version 1.3.0-9.03968
Minimum client version n/a

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.3.0-9.03968" />

See Also