Buy using storage

From Kolmafia
Revision as of 08:47, 6 November 2014 by imported>Bale (r14389)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Function Syntax

boolean buy_using_storage(int qty ,item it )

int buy_using_storage(int qty ,item it ,int price )

  • qty is the number to purchase
  • it is the item to purchase
  • price is the (optional) maximum price to spend per item

Using meat in Hangk's Storage the function attempts to mall purchase qty amount of item it. If qty is less than 1, the function will not purchase anything.

If the optional maximum price is specified, it returns the integer amount of items purchased; otherwise it returns true if the purchase succeeded and false if it did not. If a price less than 1 is passed, the function will always buy qty, regardless of price.

The version that returns a boolean value determine success depending on whether your inventory of the desired item went up by the amount you tried to buy. If qty is less than 1, the function will always return true.

Code Sample

Pull a quantity of a given item from storage, even if you are in ronin and don't have it in storage.

boolean buy_pull(int quantity, item topull) {
   if( in_hardcore() )
      print( "You cannot pull items in hardcore.", "red" );
   else if(topull == $item[none])
      print( "You need to choose a real item to pull.", "red" );
   else if(can_interact())
      return retrieve_item( quantity, topull );
   else if( pulls_remaining() >= quantity ) {
      if( storage_amount(topull) < quantity )
         buy_using_storage( quantity - storage_amount(topull), topull, get_property("autoBuyPriceLimit").to_int() );
      return take_storage(q, topull);
   } else
      print( ( pulls_remaining() == 0? "No": "Only " + pulls_remaining() ) + " pulls remaining for today.", "red" );
   return false;
}

CLI Equivalent

The CLI commands "buy" and "acquire" will purchase items if you are not in ronin or hardcore.

See Also

mall_price() | buy()