Scripts + ChatGPT

Create scripts with ChatGPT

You don't need to know how to code. Tell ChatGPT what you want the bot to do, in your own words, and it writes the script for you. The prompt below carries our whole documentation and real examples, so ChatGPT knows exactly which functions the bot has.

How it works

  1. 1

    Describe what you want in the box below, in your own words. Say which spells, items, monsters, labels and numbers to use.

  2. 2

    Press Copy prompt. It copies your request together with the rules, every function of the bot and some examples, so ChatGPT knows how our scripts work.

  3. 3

    Press Open ChatGPT, paste the prompt (Ctrl+V on the PC, long press → Paste on the phone) and send it. A free account is enough.

  4. 4

    Copy the code ChatGPT answers with.

  5. 5

    In the bot, open Scripts → + New script, paste the code, set Run every to the interval ChatGPT suggested and press Save.

  6. 6

    Turn the script on (its switch and the Scripts module) and watch the Console under the code. Try it somewhere safe first.

Your prompt

Write what the script must do, or start from an idea. The prompt updates as you type.

Ideas:
Open ChatGPTOpen ChatGPT also copies the prompt: just paste it there.
See the whole prompt · 22606 characters
You write scripts for the Scripts module of Minibia Bot, a bot for the game Minibia (an online Tibia 7.4 world).
Full documentation: https://engines-bot.com/en/minibia/docs/api — ready examples: https://engines-bot.com/en/minibia/scripts. Everything you need is also below, in case you can't open the links.

## Rules
- A script is JavaScript (ES2020) that runs in a closed sandbox inside the bot (QuickJS). There is no window, document, fetch, require, import, setTimeout or setInterval: use only the functions and values listed below. Never invent a function; if something can't be done with them, say so.
- The whole script runs again from the top every few seconds (the player chooses the interval). A top-level return ends this run. Top-level await is allowed.
- Each script does one game action per tick: put await wait(ms) between the steps of a sequence (talking to an NPC, swapping items…).
- Actions return true when the bot does them and false when it can't; why() tells why.
- storage keeps values between runs and now is the game clock in milliseconds: use them for timers and to do something only once.
- Spell words and item, monster and NPC names are in English, as in the game (exura vita, "mana fluid", "Dragon Lord").
- Put everything the player may want to change (names, numbers, labels) in UPPER_CASE constants at the top of the script.

## How a script runs
- Where it runs: Scripts live in the Scripts module of the bot. Each one runs again every few seconds (you choose, from 0.1 s) while its switch and the Scripts module are on. Run now runs it once, even when it is off. A script that is on can’t be edited: turn it off first. In the PC app, Key on a script’s row gives it a key that turns it on and off while you play (up to 14 scripts).
- Reading the game: What the bot sees is ready to read: player, monsters(), players(), target, containers, depot, equipment, hotbar, skills, trade and messages(). The values are refreshed at the start of each run and after every await, so a script that waits always sees the game as it is now.
```js
const close = monsters().filter((m) => distance(m) <= 1)
if (close.length >= 3) warn("Surrounded by", close.length, "monsters")
```
- Doing things: Action functions (cast, useItem, attack, walk, say, buy…) return true when the bot did it and false when it couldn’t; why() tells you why (mana, cooldown, no-item…). Each script does one game action per tick, so put await wait(ms) between the steps of a sequence. Items, equipment, walking, the depot and shops need Direct Controls (General page), which is on by default.
```js
if (!cast("exura vita")) log("no heal:", why())
```
- Waiting: await wait(ms) pauses the script, await waitUntil(check, ms) waits until something is true and await goTo(x, y, z) walks there. Always write await before them. A script never runs twice at the same time: the next run starts only after this one ends.
```js
say("hi")
await wait(1500)
say("trade")
if (!(await waitUntil(() => trade, 4000))) warn("the shop did not open")
```
- Memory between runs: storage keeps values from one run to the next, until you edit the script or reload the game. now is the game clock in milliseconds: use it to do something every few minutes.
```js
if (now - (storage.last || 0) > 60000) {
  storage.last = now
  log("one more minute")
}
```
- The console: log() and warn() write in the script’s console, under the code (press Edit). Errors show there too, with the line number.
- With the Cavebot: A Script waypoint of the Cavebot runs one of your scripts once and waits for it to end. Inside it, gotoLabel("Name") makes the Cavebot jump to a label, and cavebot.label, cavebot.index and cavebot.status tell where the route is. turnOn() and turnOff() flip a module’s switch; pause() holds a module only while the script is on.
```js
if (itemCount("life fluid") < 100) gotoLabel("City")
else gotoLabel("Hunt")
```
- Rules for the Target and the Loot: onAttack((monster) => …) decides whom the Target attacks: return false to skip a monster or a number to raise its priority. onLoot((item) => …) decides what the Loot takes: true takes it, false leaves it.
```js
onAttack((m) => {
  if (m.name === "Rat") return false
  if (m.hpPercent !== null && m.hpPercent < 30) return 10
})
```
- Limits and safety: Each run has 50 ms of work (waiting doesn’t count); a script that keeps going over it is stopped. Scripts run in a closed box: they can’t see the game page, your passwords or the internet. Scripts that come in someone else’s profile arrive blocked until you allow them.

## Every function and value
### Your character
- player: Your character: hp, maxHp, hpPercent, mana, maxMana, manaPercent, cap, soul, level, vocation, name, x, y, z, direction, skull, inPz, inBattle, pzLocked, hasted, paralyzed, poisoned, magicShield, invisible, hungry, moving, targetId. — if (player.hpPercent < 50) cast("exura vita")
- skills: Your skills: magic, fist, club, sword, axe, distance and shielding, each with level and percent. — log(skills.magic && skills.magic.level)
- experience: Your total experience points. — log(experience)
- money: Gold you carry (gold, platinum and crystal coins in gold). null when unknown. — if (money !== null && money < 1000) warn("low on gold")
### Creatures and the world
- creatures: Everything visible except you: monsters, players and NPCs. Each has id, name, type, hpPercent, x, y, z, distance (sqm), sameFloor, skull, party, level, vocation, summon, attackingMe and isTarget. — for (const c of creatures) log(c.name, c.type, c.distance)
- monsters(): Only the monsters on your floor. — if (monsters().length >= 3) cast("exevo gran mas vis")
- players(): Only the players on your floor. — if (players().length > 0) pause("cavebot")
- npcs(): Only the NPCs on your floor. — log(npcs().map((n) => n.name))
- target: The creature you are attacking, or null. — if (target && target.hpPercent < 20) useOnTarget(3155)
- findCreature(name): The first creature on your floor with that name (capital letters don't matter), or null. — const bob = findCreature("Bob")
- distance(a, b?): Distance in sqm (the bigger gap of x and y). With one argument it measures from you. Another floor = Infinity. — if (target && distance(target) > 4) chaseMode("chase")
- messages(): New lines since the last call: server messages, NPC replies, monster speech, loot and private messages (sender only). — for (const m of messages()) if (m.type === "npc") log(m.from, m.text)
### Items
- containers: Your open backpacks: index, name, size, free and items (id, name, count, slot, fluid, bag = true when the item is a backpack). — for (const bp of containers) log(bp.name, bp.items.length)
- equipment: What you wear, slot by slot: helmet, amulet, backpack, armor, rightHand, leftHand, legs, boots, ring and ammo. Each one is null when empty or has id, name and count (ring, amulet and boots also charges and seconds). — if (!equipment.ring) warn("no ring on")
- hotbar: Your hotbar slots: slot, key, words, itemId and mode (spell, self, target, crosshair, equip…). — log(hotbar.map((h) => h.slot + ":" + (h.words || h.itemId)))
- item(name): Finds any item of the game by its name and gives its id, fluid and name, or null. Every item function also takes the name in quotes directly, like useItem("mana fluid"); the Functions panel has a search that shows the ids.
- depot: The depot when it is open, or null: index, size, free, items (id, name, count, slot, bag…) and bags (the backpacks of the depot you opened, with their items and free slots). — if (depot) log(depot.items.length, "items in the depot")
- openDepot(): Opens the depot: uses the free locker closest to you (up to 7 sqm; the game walks to it). Needs Direct Controls.
- openItem(item): Opens a backpack that is inside an open container, like a backpack of the depot. Needs Direct Controls.
- moveItem(item, to, count?): Moves an item (from containers or the depot) to a container (its first free slot), into a backpack item, onto a pile of the same item that stacks (joins them, up to 100), or to "backpack" (your main backpack). count is optional: all by default. Needs Direct Controls. — moveItem(containers[0].items[0], depot.bags[0])
- closeContainer(container): Closes an open container: one of your backpacks, a depot backpack or the depot. — closeContainer(depot)
- equipItem(item, slot, count?): Puts an item from an open backpack on a slot: helmet, amulet, armor, rightHand, leftHand, legs, boots, ring or ammo. Takes the name, the id or an item from containers. An empty slot takes the item; a slot with the same stackable item (coins, arrows) gets more, up to 100. A slot with another item = false with slot-taken: take it off first with unequipItem. count is optional. Needs Direct Controls.
- unequipItem(slot, to?, count?): Takes the item off a slot and puts it in your main backpack, or in the container you give (like moveItem). count is optional: all by default. Needs Direct Controls. — if (equipment.leftHand) unequipItem("leftHand")
- itemCount(item, fluid?): How many of an item you carry, by name ("life fluid") or id. Counts closed backpacks when the item is on the hotbar. By id, fluids share the vial id 2874: add the fluid (7 mana, 10 life). — if (itemCount("mana fluid") < 20) alarm()
- findItem(name): The first item with that name in your open backpacks, or null. Use its id in the other functions. — const sd = findItem("sudden death rune")
### Actions (true when the bot does it)
- cast(words): Casts a spell of your vocation. Uses its hotbar key when it has one, otherwise types it. Checks level, mana and cooldown first. — cast("utani hur")
- canCast(words): true when cast(words) would work right now. — if (canCast("exura vita")) cast("exura vita")
- say(text): Says a text in the Default channel: NPC words, house spells, anything. — say("hi")
- useItem(id, fluid?): Uses an item on yourself (food, fluid, rune), by name or id: useItem("mana fluid"). Uses its hotbar key in Self mode when it has one, otherwise the backpack. — if (player.manaPercent < 40) useItem(2874, 7)
- useItemOn(id, creatureOrSqm): Uses an item (rune, rope, shovel) on a creature or on a sqm {x, y, z}. Needs Direct Controls. — useItemOn(3160, findCreature("Bob"))
- useOnTarget(id): Uses a rune on the creature you are attacking. — useOnTarget(3155)
- useHotbar(slot): Presses a hotbar slot. The slot numbers are in the hotbar list. — useHotbar(4)
- attack(creature): Attacks a creature (the object, its id or its name). The Target module may pick another one on its next turn. — attack(monsters()[0])
- stopAttack(): Stops attacking. — if (player.hpPercent < 30) stopAttack()
- walk(direction): One step: north, south, east, west, north-east, north-west, south-east or south-west. — walk("north")
- walkTo(x, y, z): Walks to a sqm on your floor, like a click on the map. Needs Direct Controls. — walkTo(32369, 32241, 7)
- await goTo(x, y, z, timeoutMs?): Walks to a sqm on your floor and waits until you are there (true) or the time runs out (false, default 30 s). Pause the Cavebot first so it doesn't walk elsewhere. Needs Direct Controls.
- turn(direction): Turns without walking: north, south, east or west. — turn("west")
- useTile(x, y, z): Uses a sqm next to you: door, lever, ladder. — useTile(player.x + 1, player.y, player.z)
- dropItem(id, count?, x?, y?, z?): Drops an item from your backpack on the ground (under you when no sqm is given). Needs Direct Controls. — dropItem(3031, 10)
- fightMode(mode): Changes the fight mode: attack, balanced or defense. — fightMode("defense")
- chaseMode(mode): Changes the chase mode: stand, chase or aggressive. — chaseMode("stand")
- logout(): Logs out (the game refuses while you are in battle). — if (player.hpPercent < 15 && !player.inBattle) logout()
- alarm(): Plays the alarm sound and flashes the bot window. — if (player.cap < 50) alarm()
### NPCs and shops
- trade: The NPC shop window, or null when it is closed: npcName, tab, gold and offers (id, name, price, side buy/sell). — if (trade) log(trade.npcName, trade.offers.length, trade.gold)
- await buy(id, count, fluid?): Buys from the open shop window, in lots of up to 100, and waits each lot to go through. Open the shop first (say hi, then trade). Needs Direct Controls.
- await sell(id, count, fluid?): Sells to the open shop window, like buy. — await sell(3031, itemCount(3031))
- closeTrade(): Closes the shop window. — closeTrade()
### Bot modules
- onAttack((monster) => …): A rule for the Target module: it asks your function about each monster on screen. false = never attack it, a number = priority (higher first, above the order of your list), nothing = as usual. Target must be on.
- onLoot((item) => …): A rule for the Loot module: it asks about each item in an open corpse. false = never take it, true = always take it, nothing = your Loot settings decide. Loot must be on.
- cavebot: The Cavebot now: status (walking, paused:monster, script…), label (the label of the part of the route it is in, like "Hunt"), index (the waypoint number), waypoint (its type), stuck (true after 3 skips in a row) and inWaypoint (true when a Script waypoint started this run). null with the Cavebot off. — if (cavebot && cavebot.label === "Hunt") log("hunting, waypoint", cavebot.index)
- gotoLabel(label): Makes the Cavebot jump to a label. In a run started by a Script waypoint it jumps when the script ends; in any other script, right away. — if (player.cap < 100) gotoLabel("Refill")
- turnOn(module): Turns a module on, like its switch (target, attack, loot, cavebot, healing…). It stays on until something turns it off. — turnOn("target")
- turnOff(module): Turns a module off, like its switch. Unlike pause(), it stays off after the script ends. — turnOff("target")
- pause(module): Holds a module (cavebot, target, attack, healing, loot, rune-maker, hunt-follow…) while this script is on. Turning the script off releases it. — pause("cavebot")
- resume(module): Releases a module held by pause(). — resume("cavebot")
- isOn(module): true when the switch of that module is on. — if (isOn("cavebot")) log("walking")
### Script tools
- await wait(ms): Waits, then goes on with the next line. Write await before it.
- await waitUntil(check, timeoutMs?): Waits until the check returns true (true) or the time runs out (false, default 5 s). The check runs every 0.1 s. — await waitUntil(() => player.manaPercent > 90, 60000)
- why(): Why the last action returned false: mana, cooldown, no-item, chat-busy, one-action-per-tick… — if (!cast("exura")) log(why())
- log(...values): Writes a line in this script's console, below the code. — log("HP", player.hp, "of", player.maxHp)
- warn(...values): Like log, marked in yellow. — warn("no mana fluids")
- storage: An object that keeps its values between runs, until you edit the script or reload the game. — storage.kills = (storage.kills || 0) + 1
- now: The game clock, in milliseconds. — if (now - (storage.last || 0) > 60000) storage.last = now

## Examples
### Walk a route of sqm by script (runs every 1 s)
```js
// Walks through the sqm of POINTS one by one, holding the Cavebot while it walks, and starts over at the end (LOOP = false stops at the last one). To get the x, y, z of a sqm, stand on it and write log(player.x, player.y, player.z) in a script, or leave POINTS empty ([]) and this script writes where you are. Needs Direct Controls (General page).
const POINTS = [
  [32369, 32241, 7],
  [32373, 32241, 7],
  [32373, 32245, 7],
  [32369, 32245, 7],
]
const LOOP = true
const TIMEOUT_MS = 20000
if (POINTS.length === 0) {
  log("You are at", player.x, player.y, player.z)
  return
}
if (storage.next === undefined) storage.next = 0
if (storage.next >= POINTS.length) {
  if (!LOOP) {
    resume("cavebot")
    return
  }
  storage.next = 0
}
pause("cavebot")
const [x, y, z] = POINTS[storage.next]
if (await goTo(x, y, z, TIMEOUT_MS)) {
  log("Point", storage.next + 1, "of", POINTS.length)
} else {
  warn("Could not reach point", storage.next + 1, "(" + x + ", " + y + ", " + z + "):", why())
}
storage.next += 1
```

### Rune on the target (sudden death) (runs every 0.5 s)
```js
// Uses a sudden death rune on the monster you are attacking, once every 2 s, when it is in ONLY (an empty list = any monster) and has 30% health or more. Keeps the last 10 runes. Put the rune on the hotbar in Target mode or keep it in an open backpack. If the Magic module already uses this rune, turn it off there.
const RUNE = "sudden death rune"
const ONLY = ["Dragon", "Dragon Lord", "Giant Spider"]
const MIN_HP_PERCENT = 30
const KEEP = 10
const EVERY_MS = 2100
if (!target || target.type !== "monster") return
const name = (target.name || "").toLowerCase()
if (ONLY.length > 0 && !ONLY.some((wanted) => wanted.toLowerCase() === name)) return
if (target.hpPercent !== null && target.hpPercent < MIN_HP_PERCENT) return
if (storage.usedAt !== undefined && now - storage.usedAt < EVERY_MS) return
const left = itemCount(RUNE)
if (left <= KEEP) {
  if (!storage.warned) warn("Only", left, "left of", RUNE + ": keeping them")
  storage.warned = true
  return
}
storage.warned = false
storage.usedAt = now
if (!useOnTarget(RUNE)) warn("Could not use", RUNE + ":", why())
```

### Deposit loot in the depot (runs every 60 s)
```js
// Next to the depot: opens it and moves every item of DEPOSIT from your open backpacks into the depot (into an open depot backpack or the first backpack inside the depot, never the inbox). Stops when the depot is full.
// How to use it in your Cavebot route:
// 1. Walk to a sqm next to a free depot locker.
// 2. Add a Script waypoint with the name of this script (limit 60 s).
// Keep this script off: the waypoint runs it. Run now works too, next to the depot.
const DEPOSIT = ["dragon ham", "plate armor", "dragon shield", "platinum coin"]
const MAX_STACKS = 40
const wanted = DEPOSIT.map((name) => name.toLowerCase())
const isWanted = (item) => !item.bag && wanted.includes((item.name || "").toLowerCase())
const carried = () => containers.flatMap((bp) => bp.items).filter(isWanted)
const remaining = () => carried().reduce((sum, item) => sum + item.count, 0)
if (carried().length === 0) return
if (!depot) {
  if (!openDepot()) {
    if (why() !== "no-locker") warn("Could not open the depot:", why())
    return
  }
  if (!(await waitUntil(() => depot, 5000))) {
    warn("The depot did not open")
    return
  }
}
const box = () => {
  const open = depot.bags.find((bag) => bag.free > 0)
  if (open) return open
  return depot.items.find((item) => item.bag && (item.name || "").toLowerCase() !== "inbox") || depot
}
let moved = 0
let before = remaining()
for (let i = 0; i < MAX_STACKS; i++) {
  const item = carried()[0]
  if (!item || !depot) break
  if (!moveItem(item, box())) {
    warn("Could not deposit", item.name + ":", why())
    break
  }
  await wait(800)
  const after = remaining()
  if (after >= before) {
    warn("The depot did not take", item.name, "- is it full?")
    break
  }
  before = after
  moved += 1
}
log("Stacks deposited:", moved)
if (depot) closeContainer(depot)
```

### Hide from PKs during the hunt (runs every 0.5 s)
```js
// When a player with a white, red or black skull shows up, the Cavebot leaves the hunt, walks to your hiding place (up the stairs, into a house or to the depot), waits there and comes back after 60 s without a PK. Target and Loot are on hold while you run.
// How to set it up in your Cavebot route:
// 1. After the Goto that closes your hunt: Label Flee, then the way to the hiding place (record it with Record; a door is a Use tile waypoint).
// 2. Label Hide, then a Script waypoint with the name of this script (limit 60 s).
// 3. Label Back, then the way back to the hunt and a Goto to your hunt label.
// Turn this script on. Put friends who have a skull in IGNORE.
const FLEE_LABEL = "Flee"
const HIDE_LABEL = "Hide"
const SAFE_SECONDS = 60
const IGNORE = ["Friend Name"]
const PK_SKULLS = ["white", "red", "black"]
const KEEP_WAITING_MS = 45000
const ignored = (p) => IGNORE.some((name) => name.toLowerCase() === (p.name || "").toLowerCase())
const pkOnScreen = () => players().some((p) => PK_SKULLS.includes(p.skull) && !ignored(p))
const safe = () => storage.pkAt === undefined || now - storage.pkAt >= SAFE_SECONDS * 1000
if (pkOnScreen()) storage.pkAt = now
if (!cavebot) return
if (cavebot.inWaypoint) {
  const started = now
  while (!safe()) {
    if (now - started >= KEEP_WAITING_MS) {
      gotoLabel(HIDE_LABEL)
      return
    }
    await wait(1000)
    if (pkOnScreen()) storage.pkAt = now
  }
  resume("target")
  resume("loot")
  log("No PK for", SAFE_SECONDS, "s: going back")
  return
}
const hiding = cavebot.label === FLEE_LABEL || cavebot.label === HIDE_LABEL
if (!hiding && safe()) {
  resume("target")
  resume("loot")
  return
}
if (hiding || !pkOnScreen()) return
if (storage.fledAt !== undefined && now - storage.fledAt < 3000) return
if (storage.fledAt !== undefined && now - storage.fledAt < 10000) warn("The Cavebot did not go to the label", FLEE_LABEL, "- check your route")
storage.fledAt = now
pause("target")
pause("loot")
if (target) stopAttack()
alarm()
warn("PK on screen: running to the label", FLEE_LABEL)
gotoLabel(FLEE_LABEL)
```

### Buy mana fluids up to 100 (runs every 60 s)
```js
// At a shop NPC: opens the trade and buys mana fluids until you have 100.
const WANT = 100
const have = itemCount(2874, 7)
if (have >= WANT) return
say("hi")
await wait(1500)
say("trade")
if (!(await waitUntil(() => trade, 3000))) {
  warn("The shop did not open")
  return
}
if (!(await buy(2874, WANT - have, 7))) warn("Could not buy:", why())
closeTrade()
```

### Stop hunting, log out after 2 h (runs every 10 s)
```js
// After 2 hours: holds the Cavebot and Target, sounds the alarm once and logs out as soon as you are out of battle.
const HOURS = 2
storage.start = storage.start || now
if (now - storage.start >= HOURS * 3600000) {
  pause("cavebot")
  pause("target")
  if (!storage.warned) {
    warn("Hunt time is over")
    alarm()
    storage.warned = true
  }
  if (!player.inBattle && !player.pzLocked) logout()
}
```

## How to answer
- Reply with one JavaScript code block I can paste in the bot.
- Start the code with comments in English explaining what it does and what I can change.
- Then tell me in a few lines which interval to choose (Run every, in seconds), whether to turn the script on or run it from a Script waypoint of the Cavebot, and what to set up (labels in the Cavebot route, hotbar, items in an open backpack).
- Keep the script short and simple.

## What my script must do
[describe here what the script must do]

When something goes wrong

If the script shows an error or does something you didn't want, go back to the same ChatGPT chat and tell it what happened. The Console under the code shows errors in red, with the line number: copy that line. For example:

The script shows this error in the Console: [paste the error here]. Fix it and send me the whole script again.
It casts the spell even when no monster is on screen. Change it to cast only with a monster up to 3 sqm away.

Tips

  • Be specific: “cast exura vita below 50% life” works better than “heal me”.
  • Spell, item and monster names stay in English, like in the game. Not sure of an item's name? Look at it in the game: the Scripts tab shows its name and id.
  • Labels (like Refill or Hunt) must exist in your Cavebot route with the same name.
  • Read the code before turning it on and try it in a safe place first: ChatGPT can make mistakes.
  • Never write passwords or your account in the chat: a script never needs them.
  • Other AI chats (Claude, Gemini, Copilot) work with the same prompt.

Examples ChatGPT learns from

The prompt carries these examples. They are in the bot too: Scripts → + From an example.

Walk a route of sqm by script

runs every 1 s

// Walks through the sqm of POINTS one by one, holding the Cavebot while it walks, and starts over at the end (LOOP = false stops at the last one). To get the x, y, z of a sqm, stand on it and write log(player.x, player.y, player.z) in a script, or leave POINTS empty ([]) and this script writes where you are. Needs Direct Controls (General page).
const POINTS = [
  [32369, 32241, 7],
  [32373, 32241, 7],
  [32373, 32245, 7],
  [32369, 32245, 7],
]
const LOOP = true
const TIMEOUT_MS = 20000
if (POINTS.length === 0) {
  log("You are at", player.x, player.y, player.z)
  return
}
if (storage.next === undefined) storage.next = 0
if (storage.next >= POINTS.length) {
  if (!LOOP) {
    resume("cavebot")
    return
  }
  storage.next = 0
}
pause("cavebot")
const [x, y, z] = POINTS[storage.next]
if (await goTo(x, y, z, TIMEOUT_MS)) {
  log("Point", storage.next + 1, "of", POINTS.length)
} else {
  warn("Could not reach point", storage.next + 1, "(" + x + ", " + y + ", " + z + "):", why())
}
storage.next += 1

Rune on the target (sudden death)

runs every 0.5 s

// Uses a sudden death rune on the monster you are attacking, once every 2 s, when it is in ONLY (an empty list = any monster) and has 30% health or more. Keeps the last 10 runes. Put the rune on the hotbar in Target mode or keep it in an open backpack. If the Magic module already uses this rune, turn it off there.
const RUNE = "sudden death rune"
const ONLY = ["Dragon", "Dragon Lord", "Giant Spider"]
const MIN_HP_PERCENT = 30
const KEEP = 10
const EVERY_MS = 2100
if (!target || target.type !== "monster") return
const name = (target.name || "").toLowerCase()
if (ONLY.length > 0 && !ONLY.some((wanted) => wanted.toLowerCase() === name)) return
if (target.hpPercent !== null && target.hpPercent < MIN_HP_PERCENT) return
if (storage.usedAt !== undefined && now - storage.usedAt < EVERY_MS) return
const left = itemCount(RUNE)
if (left <= KEEP) {
  if (!storage.warned) warn("Only", left, "left of", RUNE + ": keeping them")
  storage.warned = true
  return
}
storage.warned = false
storage.usedAt = now
if (!useOnTarget(RUNE)) warn("Could not use", RUNE + ":", why())

Deposit loot in the depot

runs every 60 s

// Next to the depot: opens it and moves every item of DEPOSIT from your open backpacks into the depot (into an open depot backpack or the first backpack inside the depot, never the inbox). Stops when the depot is full.
// How to use it in your Cavebot route:
// 1. Walk to a sqm next to a free depot locker.
// 2. Add a Script waypoint with the name of this script (limit 60 s).
// Keep this script off: the waypoint runs it. Run now works too, next to the depot.
const DEPOSIT = ["dragon ham", "plate armor", "dragon shield", "platinum coin"]
const MAX_STACKS = 40
const wanted = DEPOSIT.map((name) => name.toLowerCase())
const isWanted = (item) => !item.bag && wanted.includes((item.name || "").toLowerCase())
const carried = () => containers.flatMap((bp) => bp.items).filter(isWanted)
const remaining = () => carried().reduce((sum, item) => sum + item.count, 0)
if (carried().length === 0) return
if (!depot) {
  if (!openDepot()) {
    if (why() !== "no-locker") warn("Could not open the depot:", why())
    return
  }
  if (!(await waitUntil(() => depot, 5000))) {
    warn("The depot did not open")
    return
  }
}
const box = () => {
  const open = depot.bags.find((bag) => bag.free > 0)
  if (open) return open
  return depot.items.find((item) => item.bag && (item.name || "").toLowerCase() !== "inbox") || depot
}
let moved = 0
let before = remaining()
for (let i = 0; i < MAX_STACKS; i++) {
  const item = carried()[0]
  if (!item || !depot) break
  if (!moveItem(item, box())) {
    warn("Could not deposit", item.name + ":", why())
    break
  }
  await wait(800)
  const after = remaining()
  if (after >= before) {
    warn("The depot did not take", item.name, "- is it full?")
    break
  }
  before = after
  moved += 1
}
log("Stacks deposited:", moved)
if (depot) closeContainer(depot)

Hide from PKs during the hunt

runs every 0.5 s

// When a player with a white, red or black skull shows up, the Cavebot leaves the hunt, walks to your hiding place (up the stairs, into a house or to the depot), waits there and comes back after 60 s without a PK. Target and Loot are on hold while you run.
// How to set it up in your Cavebot route:
// 1. After the Goto that closes your hunt: Label Flee, then the way to the hiding place (record it with Record; a door is a Use tile waypoint).
// 2. Label Hide, then a Script waypoint with the name of this script (limit 60 s).
// 3. Label Back, then the way back to the hunt and a Goto to your hunt label.
// Turn this script on. Put friends who have a skull in IGNORE.
const FLEE_LABEL = "Flee"
const HIDE_LABEL = "Hide"
const SAFE_SECONDS = 60
const IGNORE = ["Friend Name"]
const PK_SKULLS = ["white", "red", "black"]
const KEEP_WAITING_MS = 45000
const ignored = (p) => IGNORE.some((name) => name.toLowerCase() === (p.name || "").toLowerCase())
const pkOnScreen = () => players().some((p) => PK_SKULLS.includes(p.skull) && !ignored(p))
const safe = () => storage.pkAt === undefined || now - storage.pkAt >= SAFE_SECONDS * 1000
if (pkOnScreen()) storage.pkAt = now
if (!cavebot) return
if (cavebot.inWaypoint) {
  const started = now
  while (!safe()) {
    if (now - started >= KEEP_WAITING_MS) {
      gotoLabel(HIDE_LABEL)
      return
    }
    await wait(1000)
    if (pkOnScreen()) storage.pkAt = now
  }
  resume("target")
  resume("loot")
  log("No PK for", SAFE_SECONDS, "s: going back")
  return
}
const hiding = cavebot.label === FLEE_LABEL || cavebot.label === HIDE_LABEL
if (!hiding && safe()) {
  resume("target")
  resume("loot")
  return
}
if (hiding || !pkOnScreen()) return
if (storage.fledAt !== undefined && now - storage.fledAt < 3000) return
if (storage.fledAt !== undefined && now - storage.fledAt < 10000) warn("The Cavebot did not go to the label", FLEE_LABEL, "- check your route")
storage.fledAt = now
pause("target")
pause("loot")
if (target) stopAttack()
alarm()
warn("PK on screen: running to the label", FLEE_LABEL)
gotoLabel(FLEE_LABEL)

Buy mana fluids up to 100

runs every 60 s

// At a shop NPC: opens the trade and buys mana fluids until you have 100.
const WANT = 100
const have = itemCount(2874, 7)
if (have >= WANT) return
say("hi")
await wait(1500)
say("trade")
if (!(await waitUntil(() => trade, 3000))) {
  warn("The shop did not open")
  return
}
if (!(await buy(2874, WANT - have, 7))) warn("Could not buy:", why())
closeTrade()

Stop hunting, log out after 2 h

runs every 10 s

// After 2 hours: holds the Cavebot and Target, sounds the alarm once and logs out as soon as you are out of battle.
const HOURS = 2
storage.start = storage.start || now
if (now - storage.start >= HOURS * 3600000) {
  pause("cavebot")
  pause("target")
  if (!storage.warned) {
    warn("Hunt time is over")
    alarm()
    storage.warned = true
  }
  if (!player.inBattle && !player.pzLocked) logout()
}
See all 41 examples