grandExchange

Grand Exchange offers, collecting, and the restock machine.

Methods
18
Fields
None

Getting one

grandExchange

Methods

MethodReturnsDescription
isOpen()booleanWhether the Grand Exchange interface is open.
mainOfferListOpen()booleanWhether the main offer list is showing, rather than one offer.
firstOpenSlot()number?The first offer slot with nothing in it, as the game numbers them from 0.
slotItemId(number)number?What item a slot is trading.
slotByItemId(number)number?Which slot is trading an item, as the game numbers them from 0.
open(string?)booleanOpen the Grand Exchange. Already open is success.
collect()booleanCollect finished offers to the inventory.
collectBank()booleanCollect finished offers to the bank.
confirmOffer()booleanConfirm the offer being set up.
closeNotice()booleanDismiss the interface's notice popup. No notice is success.
startBuyOffer()booleanStart a buy offer in the first free slot.
setOfferPrice(number)(RunStatus, string?)One step towards the offer being set up at this price per item.
setOfferQuantity(number)(RunStatus, string?)One step towards the offer being set up for this quantity.
typeOfferSearch(string)booleanType into the offer's item search, which lists the results. It only types: selectSearchResult picks one.
selectSearchResult(number)booleanPick the search result for an item. By id, because the rows reorder.
increasePricePercent(number)(RunStatus, string?)One step towards raising the offer's price by a percentage, with the interface's custom +% button. Calling again after "done" raises it a…
newRestock({ RestockItem })RestockHandleA restock of items: each row bought on the Grand Exchange and collected to the bank. The list is fixed here, and a row without an item id…
buyLimits()BuyLimitsThe buy limits the client tracks for this account.

Method details

firstOpenSlot

firstOpenSlot: (GrandExchange) -> number?

The first offer slot with nothing in it, as the game numbers them from 0.

Returns
nil when all slots are busy.

slotItemId

slotItemId: (GrandExchange, number) -> number?

What item a slot is trading.

slot
Offer slot, as the game numbers them from 0.
Returns
nil when the slot is empty.

slotByItemId

slotByItemId: (GrandExchange, number) -> number?

Which slot is trading an item, as the game numbers them from 0.

itemId
Exact item id.
Returns
nil when no slot is.

open

open: (GrandExchange, string?) -> boolean

Open the Grand Exchange. Already open is success.

target
Name pattern to prefer; omit for the nearest clerk or booth.
Returns
false when none is in range.

collect

collect: (GrandExchange) -> boolean

Collect finished offers to the inventory.

Returns
false when there is nothing to collect.

collectBank

collectBank: (GrandExchange) -> boolean

Collect finished offers to the bank.

Returns
false when there is nothing to collect.

confirmOffer

confirmOffer: (GrandExchange) -> boolean

Confirm the offer being set up.

Returns
false when no offer is being set up.

setOfferPrice

setOfferPrice: (GrandExchange, number) -> (RunStatus, string?)

One step towards the offer being set up at this price per item.

price
Price per item, in coins.
Returns
"done" once the offer reads that price, "running" while a click or a typed amount is queued, and "blocked" with the reason when no offer is being set up.

setOfferQuantity

setOfferQuantity: (GrandExchange, number) -> (RunStatus, string?)

One step towards the offer being set up for this quantity.

quantity
How many.
Returns
"done" once the offer reads that quantity, "running" while a click or a typed amount is queued, and "blocked" with the reason when no offer is being set up.

typeOfferSearch

typeOfferSearch: (GrandExchange, string) -> boolean

Type into the offer's item search, which lists the results. It only types: selectSearchResult picks one.

text
What to search for.
Returns
false when the item search is not open.

selectSearchResult

selectSearchResult: (GrandExchange, number) -> boolean

Pick the search result for an item. By id, because the rows reorder.

itemId
Exact item id.
Returns
false when the results are not showing, or none of them is that item.

increasePricePercent

increasePricePercent: (GrandExchange, number) -> (RunStatus, string?)

One step towards raising the offer's price by a percentage, with the interface's custom +% button. Calling again after "done" raises it again.

percent
How much to add, a whole number.
Returns
"done" once the click that applies it is queued, "running" while the button's percentage is being set, and "blocked" with the reason when no offer is being set up.

newRestock

newRestock: (GrandExchange, { RestockItem }) -> RestockHandle

A restock of items: each row bought on the Grand Exchange and collected to the bank. The list is fixed here, and a row without an item id and a quantity raises here. It reads no game state, so make it once, when the plugin loads or starts, and keep it: its run advances one step a tick, and it opens the Grand Exchange itself.

local restock = grandExchange:newRestock({
    { itemId = ItemID.SHARK, quantity = 200 },
    { itemId = ItemID.LOBSTER, quantity = 50 },
})

function plugin:onGameTick()
    local status, reason = restock:run()
    if status == "done" then
        -- every row was bought or skipped: read the bank to see what arrived
    elseif status == "blocked" then
        log:warn(reason) -- walk to the Grand Exchange, then call again
    end
    -- "running": it acted, or is waiting on an offer
end
items
What to buy.