GetVehicleSirens: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Forgot one little detail)
(Fixed →‎Example: and improved its readability)
Line 29: Line 29:
==Example==
==Example==
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
This example returns the siren properties when the player presses g. (Returns nil for some reason)
This example returns the siren properties when the player presses G.
<syntaxhighlight lang="lua">addEventHandler("onVehicleEnter",root,function(player,seat)
<syntaxhighlight lang="lua">addEventHandler("onVehicleEnter", root, function(player, seat)
   if(player)and(seat==0)then
   if seat == 0 then -- If a player starts driving a vehicle...
       addVehicleSirens(source,1,1)
      -- ... customize the vehicle sirens and bind a key to ouput info about them to the driver
       setVehicleSirens(source,1,0,0,0,100,0,100,255,122)
       addVehicleSirens(source, 1, 1)
       bindKey(player,"g","up",getSiren,source)
       setVehicleSirens(source, 1, 0, 0, 0, 100, 0, 100, 255, 122)
       bindKey(player, "z", "up", outputSirenInfoToPlayer, source)
   end
   end
end)
end)


function getSiren(player,button,state,vehicle)
function outputSirenInfoToPlayer(player, _, _, vehicle)
  -- Get vehicle's siren data and output it to the player in the chatbox
   local sirenData = getVehicleSirens(vehicle)
   local sirenData = getVehicleSirens(vehicle)
   outputChatBox("Here's the properties of your vehicle sirens: Red,Green,Blue: "..tostring(sirenData[1][0])..","..tostring(sirenData[1][1])..","..tostring(sirenData[1][2])..", X,Y,Z: "..tostring(sirenData[1][3])..","..tostring(sirenData[1][4])..","..tostring(sirenData[1][5])..", minAlpha: "..tostring(sirenData[1][6])..".",player)
   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
end


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

Revision as of 10:29, 6 August 2015

This function get the properties of a vehicles 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 on

Returns

If the vehicle its 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 G.

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

This template will be deleted.

See Also