Squirrel/Server/Functions/Objects/Pos
From Liberty Unleashed Wiki
(Difference between revisions)
(Created page with '{{Squirrel/Title|Pickup.Pos}} __NOTOC__ This ''Pickup'' class member returns or sets the position of the given pickup. == Syntax == You can either return or set a new value usin…') |
|||
Line 1: | Line 1: | ||
− | {{Squirrel/Title| | + | {{Squirrel/Title|Object.Pos}} |
__NOTOC__ | __NOTOC__ | ||
− | This '' | + | This ''Object'' class member returns or sets the position of the given object. |
== Syntax == | == Syntax == | ||
You can either return or set a new value using this member: | You can either return or set a new value using this member: | ||
− | <code>Vector | + | <code>Vector object.Pos</code> |
− | <code> | + | <code>object.Pos = Vector vPos</code> |
== Arguments == | == Arguments == | ||
− | * '''vPos''' - This is the new position for the | + | * '''vPos''' - This is the new position for the object as a [[Squirrel/Script_Types/Vector|Vector]] |
== Example 1. Returning == | == Example 1. Returning == | ||
Line 16: | Line 16: | ||
function onPlayerCommand( player, cmd, text ) | function onPlayerCommand( player, cmd, text ) | ||
{ | { | ||
− | if ( cmd == " | + | if ( cmd == "objectpos" ) |
{ | { | ||
− | local | + | local obj = FindObject( 0 ); |
− | if ( | + | if ( obj ) MessagePlayer( "Object 0s position is: " + obj.Pos, player ); |
− | else MessagePlayer( " | + | else MessagePlayer( "Object 0 does not exist", player ); |
} | } | ||
} | } | ||
</code> | </code> | ||
− | This command will tell the player the co-ordinates of | + | This command will tell the player the co-ordinates of object id 0. |
== Example 2. Setting == | == Example 2. Setting == | ||
Line 32: | Line 32: | ||
function onPlayerCommand( player, cmd, text ) | function onPlayerCommand( player, cmd, text ) | ||
{ | { | ||
− | if ( cmd == " | + | if ( cmd == "setobjectpos" ) |
{ | { | ||
local newpos = Vector( 100.00, 90.00, 1.00 ); | local newpos = Vector( 100.00, 90.00, 1.00 ); | ||
− | local | + | local obj = FindObject( 0 ); |
− | if ( | + | if ( obj ) obj.Pos = newpos; |
} | } | ||
} | } | ||
</code> | </code> | ||
− | This command will set the | + | This command will set the object with ID 0s position to the co-ordinates of 100.00 (X), 90.00 (Y), 1.00 (Z). |
=== Notes === | === Notes === | ||
− | The function [[Squirrel/Server/Functions/ | + | The function [[Squirrel/Server/Functions/Objects/FindObject|FindObject]] and event[[Squirrel/Server/Events/Player/onPlayerCommand|onPlayerCommand]] was used in in this example. More info about this in the corresponding page. |
== Related Functions == | == Related Functions == | ||
− | {{Squirrel/Server/Functions/ | + | {{Squirrel/Server/Functions/Objects}} |
Latest revision as of 11:42, 12 October 2010
This Object class member returns or sets the position of the given object.
[edit] Syntax
You can either return or set a new value using this member:
Vector object.Pos
object.Pos = Vector vPos
[edit] Arguments
- vPos - This is the new position for the object as a Vector
[edit] Example 1. Returning
function onPlayerCommand( player, cmd, text ) { if ( cmd == "objectpos" ) { local obj = FindObject( 0 ); if ( obj ) MessagePlayer( "Object 0s position is: " + obj.Pos, player ); else MessagePlayer( "Object 0 does not exist", player ); } }
This command will tell the player the co-ordinates of object id 0.
[edit] Example 2. Setting
function onPlayerCommand( player, cmd, text ) { if ( cmd == "setobjectpos" ) { local newpos = Vector( 100.00, 90.00, 1.00 ); local obj = FindObject( 0 ); if ( obj ) obj.Pos = newpos; } }
This command will set the object with ID 0s position to the co-ordinates of 100.00 (X), 90.00 (Y), 1.00 (Z).
[edit] Notes
The function FindObject and eventonPlayerCommand was used in in this example. More info about this in the corresponding page.