Skip to content

Classes

Gump

This class is for interacting with Gumps that are sent to the client by the server. Server gumps have a unique serial per shard, and can only have one open at a time.

An instance of Gump therefore interacts with any gump of that serial, and it may become "invalid" if the gump closes externally (e.g. by the shard or the user) You should always to validate the gump is still open by using gump.exists periodically.

Example

ts
player.use(0x4021c7b1); // Runebook object serial
const gump = Gump.findOrWait(0x59, 1000); // Wait 1 second for the gump to appear
if (!gump) {
  exit("There's no gump open, is the runebook missing?");
}

player.say("I'm outta here!");
gump.reply(10); // Press the first rune

Extends

Properties

exists
ts
exists: boolean;

Check if the gump is still open, i.e. the server hasn't closed it or the player.

Example
ts
const gump = Gump.findOrWait(0xbb1b5472, 100);
if (!gump) {
  exit("There's no gump open!");
}

// ... somewhere further down the script

if (gump.exists) {
  console.log('The gump closed, did you do it?');
}

last
ts
static last: null | Gump;

Get a reference to the last Gump sent by the server. Returns undefined if the gump is no longer open.

Example
ts
Gump.last?.close();

lastSerial
ts
static lastSerial: number;

The server serial of the last gump sent by the server. May no longer be open, check with exists first.


lastVendorBuyData
ts
static lastVendorBuyData: undefined | object;

Returns the data for the last vendor buy gump seen

Example
ts
const data = Gump.lastVendorBuyData;
if (data && data.type === 'buy') {
  // Lets buy all his ingots
  const ingots = data.items.filter((i) => i.name.toLowerCase().includes('ingot'));
  client.sendBuyRequest(data.vendor, ingots);
  console.log('Bought items', ingots);
}

lastVendorSellData
ts
static lastVendorSellData: undefined | object;

Returns the data for the last vendor buy gump seen

Example
ts
player.say('vendor sell');

const data = Gump.lastVendorSellData;

if (data && data.type === 'sell') {
  // Make sure we don't try to sell on a buy gump
  // Lets sell all our Tongs
  const tongs = data.items.filter((i) => i.name.toLowerCase() === 'tongs');
  client.sendSellRequest(data.vendor, tongs);
  console.log(
    'Sold items',
    tongs.map((i) => i.name)
  );
}

serial
ts
serial: number;
Inherited from

GameObject.serial

Methods

close()
ts
close(): void

Closes the gump

Example
ts
if (Gump.last?.containsText('Chat')) {
  gump.last?.close();
}

closeAll()
ts
static closeAll(): void

Closes all gumps that aren't the Top Bar, Buff bar, or the World view (radar) Same as the Close Gumps hotkey

Example
ts
Gump.closeAll();

containsText()
ts
containsText(value: string): boolean

Checks if the gump contains a certain string, case-insensitive.

Parameters
ParameterType
valuestring
Returns

boolean

Example
ts
const gump = Gump.findOrWait(0xbb1b5472, 100);
if (gump.containsText('Tailoring')) {
  player.say('I hate tailors');
  gump.close();
}

exists()
ts
static exists(serial: number): boolean

Checks if a gump with the provided server serial is open without making a new instance of Gump

Parameters
ParameterTypeDescription
serialnumber
Returns

boolean

Example
ts
if (Gump.exists(0xbb1b5472)) {
  player.say('My lovely lady gumps, check it out');
}

findOrWait()
ts
static findOrWait(serialOrText: string | number, timeoutMs?: number): undefined | Gump

Find a gump by its serial or containing certain text, or wait for it to appear

Parameters
ParameterTypeDescription
serialOrTextstring | number
timeoutMs?number
Returns

undefined | Gump

Examples
ts
const gump = Gump.findOrWait(0xbb1b5472, 100); // Wait 100 milliseconds (5,000 if unspecified) for the gump to appear
if (gump) {
  gump.reply(1); // Gump is open, simulate pressing a button
}
ts
const gump = Gump.findOrWait('Blacksmithy Selection Menu');
if (gump) {
  gump.reply(1); // Gump is open, simulate pressing a button
}

hasButton()
ts
hasButton(id: number): boolean

Checks if the gump has the button id. Useful if you want to prevent clicking a button that doesn't exist.

Parameters
ParameterTypeDescription
idnumber
Returns

boolean

Example
ts
const gump = Gump.findOrWait(0x59);
if (gump && gump.hasButton(10)) {
  gump.reply(10); // gump is open and has a button with id 10
}

horizontalMenuSelect()
ts
horizontalMenuSelect(graphic: number, hue?: number): void

Select an item in the old-school T2A horizontal menu gump.

Parameters
ParameterTypeDescription
graphicnumber
hue?number
Example
ts
const gump = Gump.findOrWait(0x59);
if (gump) {
  console.log('Gump exists.');
  gump.horizontalMenuSelect(gump);
}

reply()
ts
reply(buttonID: number): void

Replies to a gump by "pressing" one of the buttons

Parameters
ParameterType
buttonIDnumber
Example
ts
const gump = Gump.findOrWait(0xbb1b5472, 100);
if (gump?.containsText('Alchemy')) {
  // If there's a gump open with that serial, check if it has `Alchemy` in it.
  gump.reply(1); // Craft something
}

setCheckbox()
ts
setCheckbox(serial: number, value: boolean): void

Check or uncheck a checkbox/radio button

Parameters
ParameterTypeDescription
serialnumber
valueboolean
Example
ts
const gump = Gump.findOrWait(0x59);
gump?.gumpSetCheckbox(serial, true); // if the gump is open, check the checkbox/radio control
gump?.reply(1); // Press a button to reply

setTextEntry()
ts
setTextEntry(localSerial: number, value: string): void

Set the contents of a text entry in a gump

Parameters
ParameterTypeDescription
localSerialnumber
valuestring
Example
ts
const gump = Gump.findOrWait(0x59);
gump?.setTextEntry(0x01, 'Hello there'); // if the gump is open, set the text entries content
gump?.reply(1); // Press a button to reply

switchPage()
ts
switchPage(page: number): void

Attempts to switch the page if possible.

Parameters
ParameterTypeDescription
pagenumber
Example
ts
const gump = Gump.findOrWait(0x59);
gump?.switchPage(2); // if gump is open, try changing to page 2

waitForVendorGumpData()
ts
static waitForVendorGumpData(timeoutMs?: number): undefined | object

Waits for a vendor buy or sell gump to appear and returns the data. Or if no gump appears it will time out returning undefined

Parameters
ParameterType
timeoutMs?number
Returns

undefined | object

Example
ts
// Caution! This sells everything!
player.say('vendor sell');
const data = Gump.waitForVendorGumpData();

if (data && data.type === 'sell') {
  // Check the gump is a sell
  client.sendSellRequest(data.vendor, data.items); // Sell ALL the items the vendor will take
  console.log(
    'Sold items',
    data.items.map((i) => i.name)
  ); // Print what we sold
}