GetVehicleSirens: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Grammar fixes)
 
(15 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{New feature/item|4.0120|1.4|3966|
__NOTOC__
__NOTOC__
{{Server client function}}
{{Server client function}}
This function get the properties of a vehicles sirens.
{{New feature/item|3.0130|1.3.0|3968|
This function gets the properties of a vehicle's sirens.
}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
getVehicleSirens ( vehicle theVehicle )
table getVehicleSirens ( vehicle theVehicle )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||[[vehicle]]:getSirens|sirens|setVehicleSirens}}
===Required Arguments===  
===Required Arguments===  
*'''theVehicle:''' The vehicle to get siren information on
*'''theVehicle:''' The vehicle to get siren information of.


===Returns===
===Returns===
Returns a ''table'' with sub tables containing the properties of the siren point in the following order:
If the vehicle is invalid, it returns ''false''. Otherwise, returns a ''table'' with sub tables containing the properties of each siren point in the following manner:
 
Red, Green, Blue, Alpha, x, y, z, minAlpha or returns false on failure. Example:


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
sirenData = {
[float]  SirenData[sirenPoint].x
[1] = { Red, Green, Blue, Alpha, x, y, z, minAlpha },
[float]   SirenData[sirenPoint].y
[2] = { Red, Green, Blue, Alpha, x, y, z, minAlpha },
[float]  SirenData[sirenPoint].z
[3] = { Red, Green, Blue, Alpha, x, y, z, minAlpha },
[int]    SirenData[sirenPoint].Red
[4] = { Red, Green, Blue, Alpha, x, y, z, minAlpha },
[int]    SirenData[sirenPoint].Green
}
[int]    SirenData[sirenPoint].Blue
[int]    SirenData[sirenPoint].Alpha
[int]    SirenData[sirenPoint].Min_Alpha
</syntaxhighlight>
</syntaxhighlight>


==Example==
==Example==
{{Example}}
<section name="Server" class="server" show="true">
}}
This example returns the siren properties when the player presses Z.
<syntaxhighlight lang="lua">addEventHandler("onVehicleEnter", root, function(player, seat)
  if seat == 0 then -- If a player starts driving a vehicle...
      -- ... customize the vehicle sirens and bind a key to ouput info about them to the driver
      addVehicleSirens(source, 1, 1)
      setVehicleSirens(source, 1, 0, 0, 0, 100, 0, 100, 255, 122)
      bindKey(player, "z", "up", outputSirenInfoToPlayer, source)
  end
end)
 
function outputSirenInfoToPlayer(player, _, _, vehicle)
  -- Get vehicle's siren data and output it to the player in the chatbox
  local sirenData = getVehicleSirens(vehicle)
  outputChatBox("These are the properties of your vehicle's siren:", player, 0, 255, 0)
  outputChatBox("RGB siren colour: " .. sirenData[1].Red .. ", " .. sirenData[1].Green .. ", " .. sirenData[1].Blue .. ".", player)
  outputChatBox("Maximum alpha (during bad visibility conditions): " .. sirenData[1].Alpha .. ", minimum alpha (during good visibility conditions): " .. sirenData[1].Min_Alpha .. ".", player)
  outputChatBox("Siren light position: " .. sirenData[1].x .. ", " .. sirenData[1].y .. ", " .. sirenData[1].z .. ".", player)
end
 
addEventHandler("onVehicleStartExit", root, function(player, seat)
  if seat == 0 then -- If a player stops driving a vehicle...
      -- ... remove vehicle's sirens and unbind the key
      removeVehicleSirens(source)
      unbindKey(player, "z", "up", outputSirenInfoToPlayer)
  end
end)
</syntaxhighlight>
</section>


==Requirements==
==Requirements==
{{Requirements|1.4-3966|1.4-3966|}}
{{Requirements|1.3.0-9.03968|1.3.0-9.03968|}}


==See Also==
==See Also==
{{Vehicle_functions}}
{{Vehicle_functions}}
[[Category:Needs_Example]]

Latest revision as of 10:35, 6 August 2015

This function gets the properties of a vehicle's sirens.

Syntax

table getVehicleSirens ( vehicle theVehicle )

OOP Syntax Help! I don't understand this!

Method: vehicle:getSirens(...)
Variable: .sirens
Counterpart: setVehicleSirens


Required Arguments

  • theVehicle: The vehicle to get siren information of.

Returns

If the vehicle is invalid, it returns false. Otherwise, returns a table with sub tables containing the properties of each siren point in the following manner:

[float]   SirenData[sirenPoint].x
[float]   SirenData[sirenPoint].y
[float]   SirenData[sirenPoint].z
[int]     SirenData[sirenPoint].Red
[int]     SirenData[sirenPoint].Green
[int]     SirenData[sirenPoint].Blue
[int]     SirenData[sirenPoint].Alpha
[int]     SirenData[sirenPoint].Min_Alpha

Example

Click to collapse [-]
Server

This example returns the siren properties when the player presses Z.

addEventHandler("onVehicleEnter", root, function(player, seat)
   if seat == 0 then -- If a player starts driving a vehicle...
      -- ... customize the vehicle sirens and bind a key to ouput info about them to the driver
      addVehicleSirens(source, 1, 1)
      setVehicleSirens(source, 1, 0, 0, 0, 100, 0, 100, 255, 122)
      bindKey(player, "z", "up", outputSirenInfoToPlayer, source)
   end
end)

function outputSirenInfoToPlayer(player, _, _, vehicle)
   -- Get vehicle's siren data and output it to the player in the chatbox
   local sirenData = getVehicleSirens(vehicle)
   outputChatBox("These are the properties of your vehicle's siren:", player, 0, 255, 0)
   outputChatBox("RGB siren colour: " .. sirenData[1].Red .. ", " .. sirenData[1].Green .. ", " .. sirenData[1].Blue .. ".", player)
   outputChatBox("Maximum alpha (during bad visibility conditions): " .. sirenData[1].Alpha .. ", minimum alpha (during good visibility conditions): " .. sirenData[1].Min_Alpha .. ".", player)
   outputChatBox("Siren light position: " .. sirenData[1].x .. ", " .. sirenData[1].y .. ", " .. sirenData[1].z .. ".", player)
end

addEventHandler("onVehicleStartExit", root, function(player, seat)
   if seat == 0 then -- If a player stops driving a vehicle...
      -- ... remove vehicle's sirens and unbind the key
      removeVehicleSirens(source)
      unbindKey(player, "z", "up", outputSirenInfoToPlayer)
   end
end)

Requirements

Minimum server version 1.3.0-9.03968
Minimum client version 1.3.0-9.03968

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" client="1.3.0-9.03968" />

See Also

Shared