Difference between revisions of "SetElementDimension"

From Multi Theft Auto: Wiki
 
 
(22 intermediate revisions by 14 users not shown)
Line 1: Line 1:
 +
{{Server client function}}
 
__NOTOC__
 
__NOTOC__
This function allows you to set the dimension of any element. The dimension determines what/who the element is visible to.
+
This function allows you to set the [[dimension]] of any element. The dimension determines what/who the element is visible to.
  
 
==Syntax==
 
==Syntax==
Line 6: Line 7:
 
bool setElementDimension ( element theElement, int dimension )
 
bool setElementDimension ( element theElement, int dimension )
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
{{OOP||[[element]]:setDimension|dimension|getElementDimension}}
  
 
===Required Arguments===
 
===Required Arguments===
 
*'''theElement:''' The element in which you'd like to set the dimension of.
 
*'''theElement:''' The element in which you'd like to set the dimension of.
*'''dimension:''' An integer representing the dimension ID
+
*'''dimension:''' An integer representing the dimension ID. {{New feature/item|3.0154|1.5.3|11199|You can also use '''-1''' to make the element visible in all dimensions (only valid to objects).}} Valid values are 0 to 65535.
  
 
===Returns===
 
===Returns===
Returns 'true' if 'theElement' and 'dimension' is valid, 'false' otherwise.
+
Returns ''true'' if '''theElement''' and '''dimension''' are valid, ''false'' otherwise.
 +
Also returns false if '''theElement''' is a player and it's not alive.
  
 
==Example==
 
==Example==
 +
<section name="Server" class="server" show="true">
 +
In this example the player's dimension is set to ID 1 when they enter a vehicle, and set back to dimension 0 when they exit the vehicle.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
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 ) then   -- if the player is in dimension 0
    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 as well
  end
+
      end
 
end
 
end
 +
addEventHandler ( "onPlayerVehicleEnter", root, onPlayerEnterVehicle )
  
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 ) then   -- if the player is in dimension 1
    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 as well
  end
+
      end
 
end
 
end
 +
addEventHandler ( "onPlayerVehicleExit", root, onPlayerExitVehicle )
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</section>
 +
==Requirements==
 +
If you want to use the -1 dimension parameter.
 +
{{Requirements|1.5.4|1.5.4|}}
  
 
==See Also==
 
==See Also==
 
{{Element functions}}
 
{{Element functions}}
 +
 +
[[hu:setElementDimension]]
 +
[[de:setElementDimension]]

Latest revision as of 21:24, 8 December 2018

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

Syntax

bool setElementDimension ( element theElement, int dimension )

OOP Syntax Help! I don't understand this!

Method: element:setDimension(...)
Variable: .dimension
Counterpart: getElementDimension

Required Arguments

  • theElement: The element in which you'd like to set the dimension of.
  • dimension: An integer representing the dimension ID. You can also use -1 to make the element visible in all dimensions (only valid to objects). Valid values are 0 to 65535.

Returns

Returns true if theElement and dimension are valid, false otherwise. Also returns false if theElement is a player and it's not alive.

Example

Click to collapse [-]
Server

In this example the player's dimension is set to ID 1 when they enter a vehicle, and set back to dimension 0 when they exit the vehicle.

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

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

Requirements

If you want to use the -1 dimension parameter.

Minimum supported server 1.5.4
Minimum supported client 1.5.4

Note: Using this function 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.5.4" client="1.5.4" />

See Also