IsVehicleWindowOpen: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Bad example (return nil when the player seat = 0))
Line 23: Line 23:


== Example ==
== Example ==
With this example, you can use /Window_vehicle to open, or close if it is open, the window of the local player's current seat.
This example opens the vehicle windows when the local player use /openwindow <window number>.
<syntaxhighlight lang="lua">table = { 4, 2, 5, 3 }
<syntaxhighlight lang="lua">function openVehicleWindow (cmd,number)
 
  if (isPedInVehicle (localPlayer)) then
addCommandHandler ("Window_vehicle", function (  )
      local vehicle = getPedOccupiedVehicle(localPlayer)  
  if ( isPedInVehicle ( localPlayer ) ) then
      if number and tonumber(number) then
local vehicle = getPedOccupiedVehicle( localPlayer )  
if tonumber(number) > 0 and tonumber(number) < 7 then
local window = getPedOccupiedVehicleSeat( localPlayer )
    setVehicleWindowOpen(vehicle,tonumber(number), not isVehicleWindowOpen( vehicle, tonumber(number)))
setVehicleWindowOpen( vehicle, table[window], not isVehicleWindowOpen( vehicle, table[window] ) )
end
      end
      end
    end
  end
)</syntaxhighlight>
end
addCommandHandler ("openwindow",openVehicleWindow)</syntaxhighlight>


== See also ==
== See also ==
{{Client vehicle functions}}
{{Client vehicle functions}}

Revision as of 00:48, 30 July 2016

This function gets the vehicle window state.

Syntax

bool isVehicleWindowOpen ( vehicle theVehicle, int window )

Required arguments

  • theVehicle: The vehicle that you wish to get the window state.
  • window: An integer representing a vehicle window. It can be:
    • 0: motorbike shield
    • 1: rear window
    • 2: right front window
    • 3: right back window
    • 4: left front (driver) window
    • 5: left back window
    • 6: windshield

Returns

This function returns a boolean which represents window open state.

Example

This example opens the vehicle windows when the local player use /openwindow <window number>.

function openVehicleWindow (cmd,number)
   if (isPedInVehicle (localPlayer)) then
      local vehicle = getPedOccupiedVehicle(localPlayer) 
      if number and tonumber(number) then
	 if tonumber(number) > 0 and tonumber(number) < 7 then
	    setVehicleWindowOpen(vehicle,tonumber(number), not isVehicleWindowOpen( vehicle, tonumber(number)))
	 end
      end
   end
end
addCommandHandler ("openwindow",openVehicleWindow)

See also