Get inventory: Difference between revisions
Jump to navigation
Jump to search
imported>Slyz No edit summary |
imported>Heeheehee m Slight code modification to make it more server-friendly. |
||
Line 21: | Line 21: | ||
code= | code= | ||
<syntaxhighlight> | <syntaxhighlight> | ||
batch_open(); | |||
int[item] inventory = get_inventory() ; | int[item] inventory = get_inventory() ; | ||
foreach it in inventory | foreach it in inventory | ||
if ( inventory[it] > 5 ) | if ( inventory[it] > 5 ) | ||
put_closet( 1, it ) ; | put_closet( 1, it ) ; | ||
batch_close(); | |||
// We're using a batch here to minimize server hits. | |||
</syntaxhighlight>}}| | </syntaxhighlight>}}| | ||
}} | }} |
Revision as of 23:43, 31 March 2010
Function Syntax
int [item] get_inventory()
Returns a map where each key is an item in your inventory, with the integer value its quantity.
Simple Example
This example puts one of each item of your inventory in your closet if you have more than 5:
batch_open();
int[item] inventory = get_inventory() ;
foreach it in inventory
if ( inventory[it] > 5 )
put_closet( 1, it ) ;
batch_close();
// We're using a batch here to minimize server hits.