Loadouts & Restocking
Loadouts are an item management system which works in conjunction with banking and the grand exchange.
They allow you to define and organize inventory and equipment setups that your script needs to function and offers efficient withdrawals from the bank. This helps to streamline inventory management, making tasks like banking tick perfect and more reliable.
You can set up a loadout that defines exactly what items should be in the inventory, including
quantities and behavior to take place when an item runs out, for example restocking
behavior or simply stopping the script. This is done via calling setOutOfItemListener
.
Example & breakdown
Using loadouts:
BackpackLoadout loadout = new BackpackLoadout("firemaking");
loadout.add(new ItemEntryBuilder()
.key("Tinderbox")
.stackable(false)
.quantity(1)
.restockMeta(new RestockMeta(1, 5000))
.build()
);
loadout.add(new ItemEntryBuilder()
.key(log.getName())
.stackable(false)
.quantity(27)
.restockMeta(new RestockMeta(restockAmount, restockPrice))
.build()
);
loadout.setOutOfItemListener(entry -> {
stockMarketService.submit(StockMarketable.Type.BUY, entry);
});
loadout.withdraw();
This code automates the process of filling the player’s inventory with the required items.
Calling withdraw()
will withdraw the items, and if an item isn't present then the out-of-item
listener will be called - which triggers restocking (assuming you have RestockTask
in your
tasks).
The above example shows you how to programatically build a loadout. You don't always have to do
this, as there is an in-client UI for building loadouts and you can load saved loadouts by name via
provided methods in LoadoutService
i.e.
BackpackLoadout loadout = loadoutService.getBackpackLoadout(name);
Or you can bind them from user input as referenced in the Internal Script UIs tutorial
Moving onto more restocking specifics, as previously mentioned - RestockTask
is the task you
want for all of your easy restocking needs.
This class has its own API which lets you have some control over the restocking behavior, for example implementing a retry strategy if items don't buy or sell. Below is an example implementation, but you can change it as per needs.
@Override
public void initialize() {
RestockTask restocker = injector.getInstance(RestockTask.class);
restocker.setRetryStrategy(new RestockTask.RetryStrategy() {
@Override
public boolean isWarranted(StockMarketEntry entry, int ticksPassed) {
int price = entry.getItemPrice();
if (entry.getType() == StockMarketable.Type.SELL && price == 1) {
//can't go any lower
return false;
}
//check if 30 ticks have passed and the only retry if the price isn't much much higher than live price
return ticksPassed >= 30 && price <= PriceCheck.lookup(entry.getItemId()).getHigh() * 1.5;
}
@Override
public int getPrice(StockMarketEntry entry) {
if (entry.getType() == StockMarketable.Type.SELL) {
//for sell items go 10% lower than previous price every attempt
return (int) (entry.getItemPrice() * 0.9);
}
//buy items go 10% higher than last price every attempt
return (int) (entry.getItemPrice() * 1.1);
}
});
}