Squirrel/Server/Functions/Objects/FindObject
From Liberty Unleashed Wiki
(Difference between revisions)
(New page: __NOTOC__ This function finds an object from an ID and returns the pointer. If no object is found, ''null'' will be returned. == Syntax == <code>Object FindObject( int id )</code> == Ar...) |
|||
Line 12: | Line 12: | ||
== Example == | == Example == | ||
− | |||
<code lang="squirrel"> | <code lang="squirrel"> | ||
− | + | function onPlayerCommand( player, cmd, text ) | |
+ | { | ||
+ | if ( cmd == "findobj" ) | ||
+ | { | ||
+ | local obj; | ||
+ | if ( text ) obj = FindObject( text.tointeger() ); | ||
+ | |||
+ | if ( obj ) MessagePlayer( "Succesfully found object id: " + text + "!", player ); | ||
+ | else MessagePlayer( "Unable to find an object with id: " + text + "!", player ); | ||
+ | } | ||
+ | } | ||
</code> | </code> | ||
+ | |||
+ | This command will try to find the an object from the id given in the text. | ||
=== Notes === | === Notes === | ||
− | + | The call [[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/Objects}} | {{Squirrel/Server/Functions/Objects}} |
Revision as of 03:07, 8 March 2010
This function finds an object from an ID and returns the pointer. If no object is found, null will be returned.
Syntax
Object FindObject( int id )
Arguments
- id - The ID of the object to be found
Example
function onPlayerCommand( player, cmd, text ) { if ( cmd == "findobj" ) { local obj; if ( text ) obj = FindObject( text.tointeger() ); if ( obj ) MessagePlayer( "Succesfully found object id: " + text + "!", player ); else MessagePlayer( "Unable to find an object with id: " + text + "!", player ); } }
This command will try to find the an object from the id given in the text.
Notes
The call onPlayerCommand was used in in this example. More info about this in the corresponding page.