GetVehicleSirens: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 29: Line 29:
==Example==
==Example==
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
This example returns the siren properties when the player presses g. (Returns nil for some reason)
addEventHandler("onVehicleEnter",root,function(player,seat)
<syntaxhighlight lang="lua">addEventHandler("onVehicleEnter",root,function(player,seat)
   if(player)and(seat==0)then
   if(player)and(seat==0)then
      vehicle = getPedOccupiedVehicle(player)
       addVehicleSirens(source,1,1)
       addVehicleSirens(vehicle,1,1)
       setVehicleSirens(source,1,0,0,0,100,0,100,255,122)
       setVehicleSirens(vehicle,1,0,0,0,100,0,100,255,122)
       bindKey(player,"g","up",getSiren,source)
       bindKey(player,"g","up",getSiren,vehicle)
   end
   end
end)
end)


function getSiren(player,button,state,vehicle)
function getSiren(player,button,state,vehicle)
   local sirenData = getVehicleSiren(vehicle)
   local sirenData = getVehicleSirens(vehicle)
   outputChatBox("Here's the properties of your vehicle sirens: Red,Green,Blue: "..sirenData[1][0]..","..sirenData[1][1]..","..sirenData[1][2]..", X,Y,Z: "..sirenData[1][3]..","..sirenData[1][4]..","..sirenData[1][5]..", minAlpha: "..sirenData[1][6]..".",player)
   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)
end
end


addEventHandler("onVehicleExit",root,function(player,seat)
addEventHandler("onVehicleExit",root,function(player,seat)
   if(player)and(seat==0)then
   if(player)and(seat==0)then
      vehicle = getPedOccupiedVehicle(player)
       removeVehicleSirens(source)
       removeVehicleSirens(vehicle)
       unbindKey(player,"g","up",getSiren)
       unbindKey(player,"g","up",getSiren)
   end
   end

Revision as of 17:25, 20 April 2012

ADDED/UPDATED IN VERSION 1.4 r3966:

This function get the properties of a vehicles sirens.

Syntax

table getVehicleSirens ( vehicle theVehicle )

Required Arguments

  • theVehicle: The vehicle to get siren information on

Returns

Returns a table with sub tables containing the properties of the siren point in the following order:

Red, Green, Blue, Alpha, x, y, z, minAlpha or returns false on failure. Example:

sirenData = {
[1] = { Red, Green, Blue, Alpha, x, y, z, minAlpha },
[2] = { Red, Green, Blue, Alpha, x, y, z, minAlpha },
[3] = { Red, Green, Blue, Alpha, x, y, z, minAlpha },
[4] = { Red, Green, Blue, Alpha, x, y, z, minAlpha },
}

Example

Click to collapse [-]
Server

This example returns the siren properties when the player presses g. (Returns nil for some reason)

addEventHandler("onVehicleEnter",root,function(player,seat)
   if(player)and(seat==0)then
      addVehicleSirens(source,1,1)
      setVehicleSirens(source,1,0,0,0,100,0,100,255,122)
      bindKey(player,"g","up",getSiren,source)
   end
end)

function getSiren(player,button,state,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)
end

addEventHandler("onVehicleExit",root,function(player,seat)
   if(player)and(seat==0)then
      removeVehicleSirens(source)
      unbindKey(player,"g","up",getSiren)
   end
end)

Requirements

Minimum server version 1.4-3966
Minimum client version 1.4-3966

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.4-3966" client="1.4-3966" />

See Also