GetElementDimension: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 14: Line 14:


==Example==
==Example==
This example makes it so that all vehicles with drivers are in dimension 1 while all other vehicles are in dimension 0. This would have the effect of making on-foot players invisible to drivers, and vice versa. It'd also make entering a vehicle as passenger after the driver has entered impossible, as the vehicle would appear to vanish to any on foot players.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerEnterVehicle", root, "onPlayerEnterVehicle" )
addEventHandler ( "onPlayerEnterVehicle", root, "onPlayerEnterVehicle" )
function onPlayerEnterVehicle ( theVehicle, seat, jacked )
function onPlayerEnterVehicle ( theVehicle, seat, jacked )
   if ( getElementDimension ( source ) == 0 ) then -- if the player is in dimension 0
   if ( getElementDimension ( source ) == 0 and seat == 0 ) then -- if the player is in dimension 0 and is entering the driver seat
     setElementDimension ( source, 1 ) -- set his dimension to 1
     setElementDimension ( source, 1 ) -- set his dimension to 1
     setElementDimension ( theVehicle, 1 ) -- set his vehicle's dimension to 1 aswell
     setElementDimension ( theVehicle, 1 ) -- set his vehicle's dimension to 1 aswell
Line 25: Line 26:
addEventHandler ( "onPlayerExitVehicle", root, "onPlayerExitVehicle" )
addEventHandler ( "onPlayerExitVehicle", root, "onPlayerExitVehicle" )
function onPlayerExitVehicle ( theVehicle, seat, jacker )
function onPlayerExitVehicle ( theVehicle, seat, jacker )
   if ( getElementDimension ( source ) == 1 ) then -- if the player is in dimension 1
   if ( getElementDimension ( source ) == 1 and seat == 0 ) then -- if the player is in dimension 1 and was in the driver's seat
     setElementDimension ( source, 0 ) -- set his dimension back to 0
     setElementDimension ( source, 0 ) -- set his dimension back to 0
     setElementDimension ( theVehicle, 0 ) -- set his vehicle's dimension back to 0 aswell
     setElementDimension ( theVehicle, 0 ) -- set his vehicle's dimension back to 0 aswell

Revision as of 02:09, 8 October 2006

This function allows you to retrieve the dimension of any element. The dimension determines what/who the element is visible to.

Syntax

int getElementDimension ( element theElement )

Required Arguments

  • theElement: The element in which you'd like to retrieve the dimension of.

Returns

Returns an integer for the dimension if 'theElement' is valid, 'false' otherwise.

Example

This example makes it so that all vehicles with drivers are in dimension 1 while all other vehicles are in dimension 0. This would have the effect of making on-foot players invisible to drivers, and vice versa. It'd also make entering a vehicle as passenger after the driver has entered impossible, as the vehicle would appear to vanish to any on foot players.

addEventHandler ( "onPlayerEnterVehicle", root, "onPlayerEnterVehicle" )
function onPlayerEnterVehicle ( theVehicle, seat, jacked )
  if ( getElementDimension ( source ) == 0 and seat == 0 ) then -- if the player is in dimension 0 and is entering the driver seat
    setElementDimension ( source, 1 ) -- set his dimension to 1
    setElementDimension ( theVehicle, 1 ) -- set his vehicle's dimension to 1 aswell
  end
end

addEventHandler ( "onPlayerExitVehicle", root, "onPlayerExitVehicle" )
function onPlayerExitVehicle ( theVehicle, seat, jacker )
  if ( getElementDimension ( source ) == 1 and seat == 0 ) then -- if the player is in dimension 1 and was in the driver's seat
    setElementDimension ( source, 0 ) -- set his dimension back to 0
    setElementDimension ( theVehicle, 0 ) -- set his vehicle's dimension back to 0 aswell
  end
end

See Also

Shared