Shop amount: Difference between revisions
Jump to navigation
Jump to search
imported>StDoodle mNo edit summary |
imported>Eliteofdelete No edit summary |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{#vardefine:name|shop_amount}} | {{ | ||
{{#vardefine:return_type|int}} | #vardefine:name|shop_amount}}{{ | ||
#vardefine:return_type|int}}{{ | |||
FunctionPage| | |||
name={{#var:name}}| | name={{#var:name}}| | ||
function1={{Function| | function1={{Function| | ||
Line 16: | Line 16: | ||
function_description=Returns the amount of a given item that are currently for sale in your mall store.| | function_description=Returns the amount of a given item that are currently for sale in your mall store.| | ||
code1={{CodeSample| | |||
title=Code Samples| | |||
description=The following function will use your shop when acquiring an item however it will not purchase anything. | | |||
code= | |||
<syntaxhighlight> | |||
void get_it (item thing, int amount) { | |||
int have = item_amount(thing); | |||
int need = max(0, amount-have); | |||
if (need == 0) { | |||
print("You already have "+amount+" of "+thing+".", "green"); | |||
return; | |||
} | |||
else if (shop_amount(thing) > 0) { | |||
refresh_shop(); | |||
int pull = min(shop_amount(thing), need); | |||
print("Removing "+pull+" "+thing+" from your store.", "blue"); | |||
take_shop(pull, thing); | |||
need = max(0, amount - item_amount(thing)); | |||
} | |||
if (need == 0) | |||
print("You now have "+amount+" "+thing+".", "green"); | |||
else { | |||
print("Need to buy "+amount+" "+thing+".", "blue"); | |||
//cli_execute("find "+amount+" "+thing); | |||
print("This example doesn't buy though!", "red"); | |||
} | |||
} | |||
get_it($item[mae west], 5); | |||
</syntaxhighlight>| | |||
moreinfo=Uncomment the third to last line if you want it to buy. | |||
}}| | |||
see_also={{SeeAlso|closet_amount|display_amount|equipped_amount|item_amount|stash_amount|storage_amount}}| | see_also={{SeeAlso|closet_amount|display_amount|equipped_amount|item_amount|stash_amount|storage_amount}}| | ||
}} | }} | ||
[[Category:Item Management]] |
Latest revision as of 22:25, 21 January 2015
Function Syntax
- it is the item to check
Returns the amount of a given item that are currently for sale in your mall store.
Code Samples
The following function will use your shop when acquiring an item however it will not purchase anything.
void get_it (item thing, int amount) {
int have = item_amount(thing);
int need = max(0, amount-have);
if (need == 0) {
print("You already have "+amount+" of "+thing+".", "green");
return;
}
else if (shop_amount(thing) > 0) {
refresh_shop();
int pull = min(shop_amount(thing), need);
print("Removing "+pull+" "+thing+" from your store.", "blue");
take_shop(pull, thing);
need = max(0, amount - item_amount(thing));
}
if (need == 0)
print("You now have "+amount+" "+thing+".", "green");
else {
print("Need to buy "+amount+" "+thing+".", "blue");
//cli_execute("find "+amount+" "+thing);
print("This example doesn't buy though!", "red");
}
}
get_it($item[mae west], 5);
Uncomment the third to last line if you want it to buy.