Scripts

Scripts: teach LOW Bot new tricks in JavaScript

Write a few lines of JavaScript in the Scripts tab and the bot runs them on its own, as often as you choose: it reads your character, the monsters and players on screen, your backpack and the Cavebot, and casts spells, drinks potions, attacks, walks, buys and sells at the NPC, holds a module or sends the Cavebot to a Label. 83 ready functions and 47 examples to start from.

Getting started

  1. 1Open the bot window, go to the Scripts tab and tick the Scripts box (it comes unticked).
  2. 2Press + New for an empty script, or Examples to pick one of the 47 ready ones. Functions lists everything a script can use: a click writes it in your code (with the script off).
  3. 3Give it a name, choose how often it runs in Every (ms), from 100 ms to 1 hour, write the code and press Save (Ctrl+S saves too).
  4. 4Press Turn on. The script runs while the bot, the Scripts box and the script are on. Run now runs it once in the game, even with the bot off, so you can test it.
  5. 5Scripts are saved with your settings and go into your profiles (Profiles tab) with the rest of the setup.

Safe by design

  • Scripts run in an isolated interpreter inside the bot: they only see the functions on this page, with no access to the game page, the game files or the internet.
  • A loop that never ends is cut off (Timeout) without freezing the game, and 3 errors in a row stop the script until you turn it on again or change the code.
  • A script that is on can't be edited: turn it off first. The examples come in turned off, so you can read them before turning them on.
  • log() and warn() write in the script's console, under the code, along with the errors and their line. The name and the code of your scripts never leave your PC or phone.
  • Up to 30 scripts per profile, 20,000 characters each.

Your first script

Heal under 60% HP, put Mana Block on when a player comes close and write in the console what is going on:

if (player.hpPercent < 60) cast("Strong Heal")
else if (playersAround(7) > 0 && !player.manaShield) cast("Mana Block")
log("HP", player.hp, "monsters", monsters().length)

How a script runs

Read this once: it explains when a script runs, when an action works and how a script works with the other tabs.

When it runs

Each script runs again every N ms (Every (ms), from 100 ms to 1 hour) while the bot, the Scripts box and the script are on, right after the bot's own healing. A script does one run at a time: the next one starts only after this one ends.

Reading the game

What the bot sees is ready to read: player, target, monsters(), players(), npcs(), backpack, lootBag (the botín), gold, hotkeys, cavebot, groundItems and messages(). The values are always the current ones, even after a wait.

const close = monsters().filter((m) => m.distance <= 1)
if (close.length >= 3) warn("Surrounded by", close.length, "monsters")

Doing things

Actions are the same ones the bot already does, with the same rules as the game: a spell is cast from the game's hotkey bar (if it isn't there, the script first puts it on a free slot, like the hotkey picker, and casts it on the next try), attacks and runes only go on what is on screen, walking is a click on the map (or on the minimap when the sqm is off screen), NPC trades work up to 4 sqm away and dropping items works from level 8.

if (!cast("Strong Heal")) log("no heal:", why())

One action per tick, and why()

Each script does one game action per tick: a second action in the same tick returns false. Every action returns true when the bot did it and false when it couldn't, and why() tells why the last call returned false (no-mana, cooldown, off-screen…). Put await wait(ms) between the steps of a sequence.

Waiting

await wait(ms), await waitUntil(check, ms) and await goTo(x, y) pause the script, and it continues on the next ticks while the game and the rest of the bot keep going. Always write await before them.

await waitUntil(() => monstersAround(7) === 0, 10000)
if (await goTo(player.x + 5, player.y)) log("arrived")
await wait(1000)

Memory between runs

storage keeps values from one run to the next (it is cleared when you change the code). now is the clock in ms: use it to do something once a minute.

if (now - (storage.at || 0) > 60000) {
  storage.at = now
  log("one more minute")
}

The other tabs and the Cavebot

pause("cavebot") holds a module of the bot (Target, Cavebot, Loot, healing, potions…) until resume() or until the script stops; turnOn() and turnOff() tick and untick a module's box; gotoLabel("Refill") sends the Cavebot to a Label; setOption("target.range", 4) changes an option.

if (itemCount("Medium Mana Potion") < 20) pause("cavebot")
else resume("cavebot")
if (itemCount("Medium Health Potion") < 30) gotoLabel("Refill")
setOption("target.range", monstersAround(3) >= 4 ? 3 : 6)

Console and messages

log() and warn() write in the script's console, along with the errors and their line. messages() returns the new game messages (private messages and server lines) since the last call.

for (const m of messages()) {
  if (m.type === "private") warn(m.from, m.text)
}

Every function

83 functions and values, grouped like the Functions list of the bot. The names stay in English in every language; the examples are short pieces to put inside your own script.

Reading

player

You: name, level, vocation (knight, paladin, mage, healer), hp, maxHp, hpPercent, mana, maxMana, manaPercent, x, y, z, moving, inPz, hasted, paralyzed, manaShield, berserker, experience.

Example

if (player.hpPercent < 50) cast("Strong Heal")

target

The creature you are attacking, or null.

Example

if (target && target.hpPercent < 20) log("almost dead:", target.name)

now

The clock in ms. It moves while the script waits.

Example

if (now - (storage.at || 0) > 60000) { storage.at = now; log("one more minute") }

online

How long you are in the game in this session, in ms.

Example

if (online > 2 * 3600000) logout()

gold

Gold in the backpack (null if the game didn't say).

Example

if (gold !== null && gold > 10000) depositGold(gold - 1000)

bankGold

Gold in the bank (null if the game didn't say).

Example

log("bank:", bankGold)

backpack

The items in the backpack: [{ id, name, count }].

Example

for (const it of backpack) log(it.name, it.count)

lootBag

The items in the botín: [{ id, name, count }].

Example

const item = lootBag.find((it) => it.name === "Wolf Paw")

mailbox

The items in the mailbox (buzón): [{ id, name, count }].

Example

for (const it of mailbox) log(it.name, it.count)

equipment

What you are wearing: [{ slot, id, name }]. slot: necklace, helmet, backpack, lootBag, armor, shield, legs, ring, boots, ammo, melee, distance, wand.

Example

const ring = equipment.find((e) => e.slot === "ring")

charging

Your Charging (the game's imbuements): { on, list: [{ type, tier, on, minutesLeft }] }, or null before the game sends it.

Example

if (charging && !charging.on && monstersAround(7) > 0) chargingOn()

backpackFree

Free slots in the backpack, or null.

Example

if (backpackFree !== null && backpackFree <= 2) gotoLabel("Depot")

lootBagFree

Free slots in the botín, or null.

Example

if (lootBagFree === 0) warn("botín full")

hotkeys

The game's hotkey bar: [{ slot, spell, item }].

Example

log(hotkeys.map((h) => h.spell || h.item || "-").join(", "))

cavebot

Where the Cavebot is: { on, index, total, label, waypoint }. label = the last Label passed.

Example

if (cavebot.label === "Refill") pause("target")

groundItems

Items on the ground of your floor: [{ id, name, count, x, y, distance }].

Example

if (groundItems.some((g) => g.distance <= 1)) collectLoot()

inPrison

true when you are in the game's prison.

Example

if (inPrison) { alarm(); stopBot() }

chase

The game's Chase mode: off, chase or sticky (null without it).

Example

if (chase !== "chase") chaseMode("chase")

storage

An object of the script that stays between runs (it is cleared when you change the code).

Example

storage.count = (storage.count || 0) + 1

scriptName

The name of this script.

Example

log("running", scriptName)

Creatures

monsters()

The monsters of your floor: [{ id, name, x, y, z, hpPercent, distance, onScreen, isTarget }].

Example

if (monsters().filter((m) => m.distance <= 1).length >= 3) cast("Fire Wave")

players()

The other players of your floor (with level, vocation, guild, skull and manaBlock: true, false or null when the game didn't say).

Example

if (players().some((p) => p.distance <= 5)) pause("cavebot")

npcs()

The NPCs of your floor (kind: shop, bank, depot or other).

Example

for (const n of npcs()) log(n.name, n.kind, n.distance)

creatures()

Everybody the game shows: monsters, players and NPCs.

Example

log(creatures().filter((c) => c.onScreen).length, "on screen")

findMonster(name)

The closest monster with this name, or null.

Example

const boss = findMonster("Orc Warden")
if (boss) attack(boss)

findPlayer(name)

The player with this name on your floor, or null.

Example

const friend = findPlayer("Friend Name")

findNpc(name)

The NPC with this name on your floor, or null.

Example

const seller = findNpc("Seller")

findCreature(name)

The closest creature with this name, or null.

Example

log(findCreature("Rat"))

monstersAround(sqm)

How many monsters are up to N sqm away (1 = next to you).

Example

if (monstersAround(1) >= 3) cast("Twist Rage")

playersAround(sqm)

How many players are up to N sqm away (7 if you leave it empty).

Example

if (playersAround(7) > 0) pause("cavebot")

distance(a, b)

The distance in sqm from you (or from a to b). Another floor = Infinity.

Example

if (target && distance(target) > 4) log("far")

Spells

cast(spell)

Casts the spell by name, like the game's hotkey. Checks level, mana, cooldown and target. If the spell is not on the hotkey bar, puts it on a free slot first (try again).

Example

if (!player.hasted) cast("Hurry")

canCast(spell)

true if the spell can be cast now (why() says why not).

Example

if (canCast("Fire Ball")) cast("Fire Ball")

spell(name)

The spell: { id, name, mana, level, cooldownMs, onHotkey, ready, why }, or null.

Example

log(spell("Strong Heal"))

cooldown(spell)

How many ms the spell still needs.

Example

log(cooldown("Strong Heal"), "ms")

await castWhenReady(spell, ms)

Waits for the cooldown (up to ms, 5 s if empty) and casts. Use it with await.

Example

await castWhenReady("Mana Block", 3000)

Items

itemCount(item)

How many of the item you have in the backpack (by name or id).

Example

if (itemCount("Medium Mana Potion") < 20) warn("few potions")

lootCount(item)

How many of the item you have in the botín.

Example

log(lootCount("Wolf Paw"))

item(name)

The game item with this name: { id, name }, or null.

Example

log(item("Small Mana Potion"))

useItem(item)

Uses the item of the backpack (potion, rune without target). Attack runes go on the target.

Example

if (player.manaPercent < 40) useItem("Medium Mana Potion")

useOnTarget(item)

Uses the attack rune on the creature you are attacking.

Example

if (target) useOnTarget("Spirit of Doom")

dropItem(item, count)

Drops the item (from the backpack or the botín) on the ground. From level 8.

Example

dropItem("Bone")

moveToBackpack(item, count)

Moves the item from the botín to the backpack.

Example

moveToBackpack("Medium Mana Potion")

collectLoot()

Picks up the loot next to you, like the game's Loot button (it doesn't walk).

Example

if (monstersAround(5) === 0) collectLoot()

Equipment and Charging

equip(item)

Equips the item from the backpack or the botín, like the Equip button of the inventory.

Example

if (player.hpPercent < 30) equip("Ring Name")

unequip(slot, toLootBag)

Takes off what is in the slot (ring, helmet, ammo...) or the item by name. It goes to the backpack (to the botín with true).

Example

if (monstersAround(7) === 0) unequip("ring")

setLootBag(item)

Uses a bag of your backpack as the botín, like the button of the inventory.

Example

setLootBag("Bag Name")

takeFromMailbox(item, count)

Moves the item from the mailbox to the backpack (one stack per call; the whole stack if count is empty).

Example

takeFromMailbox("Medium Mana Potion", 100)

chargingOn()

Turns all your Charging on, like "Activate all". The game asks 1 minute between changes.

Example

if (monstersAround(5) >= 3) chargingOn()

chargingOff()

Turns all your Charging off. The game asks 1 minute between changes.

Example

if (player.inPz) chargingOff()

setCharging(type, on)

Turns one Charging on or off: critical, speed, lifeDrain, manaDrain, melee, distance, magic, defense, fire, ice, earth, energy or death. 1 minute between changes.

Example

setCharging("critical", monstersAround(3) > 0)

Combat and moving

attack(creature)

Attacks a creature (the object, the id or the name). It has to be on screen.

Example

const weak = monsters().find((m) => m.onScreen && m.hpPercent < 30)
if (weak) attack(weak)

stopAttack()

Stops attacking.

Example

if (player.hpPercent < 20) stopAttack()

walkTo(x, y)

Walks to the sqm of your floor, like a click on the map (or on the minimap, if it is off screen).

Example

walkTo(player.x + 3, player.y)

await goTo(x, y, ms)

Walks to the sqm and waits to arrive (30 s if empty). Use it with await; false if it didn't arrive.

Example

if (await goTo(100, 200)) log("arrived")

await walkPath(points, ms)

Walks through a list of sqm with goTo, one after the other. Use it with await.

Example

await walkPath([{ x: 100, y: 200 }, { x: 104, y: 200 }])

step(direction)

Walks one sqm: north, south, east, west, northeast, northwest, southeast, southwest.

Example

step("north")

turn(direction)

Turns to north, south, east or west.

Example

turn("east")

clickMap(x, y)

Clicks a sqm of the screen, like a click on the map: for chests and other things you take by clicking. The server decides what happens.

Example

clickMap(player.x + 1, player.y)

push(player, direction)

Pushes a player next to you to the sqm next to him in that direction (or x, y), like dragging him in the game. Only players.

Example

const enemy = players().find((p) => p.distance === 1)
if (enemy) push(enemy, "north")

chaseMode(mode)

Changes the game's Chase: off, chase or sticky (one click per call, like the HUD button).

Example

chaseMode("sticky")

NPC

buy(item, count)

Buys from the shop NPC up to 4 sqm away (count = how many). It asks the NPC for the offers first.

Example

buy("Medium Mana Potion", 100 - itemCount("Medium Mana Potion"))

sell(item, count)

Sells the item to the shop NPC (from the botín first). count = how many or "all".

Example

sell("Wolf Paw", "all")

deposit(item)

Deposits all of the item at the depot NPC up to 4 sqm away.

Example

deposit("Wolf Paw")

depositGold(amount)

Deposits gold at the bank NPC (all if you leave it empty).

Example

depositGold()

Bot modules

pause(module)

Holds a module (target, cavebot, loot, healing, potions, attack, extra, follow, refill...) until resume() or until the script stops.

Example

if (itemCount("Medium Mana Potion") < 20) pause("cavebot")
else resume("cavebot")

resume(module)

Lets go of a module the script held with pause().

Example

resume("target")

isHeld(module)

true if a script is holding the module.

Example

log(isHeld("cavebot"))

turnOn(module)

Turns the module on (its checkbox in the window).

Example

turnOn("loot")

turnOff(module)

Turns the module off (its checkbox in the window).

Example

turnOff("loot")

isOn(module)

true if the module and the bot are on.

Example

if (!isOn("healing")) warn("healing is off")

gotoLabel(label)

Sends the Cavebot to the Label with this name.

Example

if (itemCount("Medium Health Potion") < 30) gotoLabel("Refill")

setOption(path, value)

Changes an option of the bot, for example setOption("target.range", 4).

Example

setOption("target.range", monstersAround(3) >= 4 ? 3 : 6)

option(path)

Reads an option of the bot, for example option("follow.playerName").

Example

log(option("follow.playerName"))

alarm()

Sounds the alarm of the scripts (a beep on the PC).

Example

if (players().length > 0) alarm()

stopBot()

Turns the bot off (like the Pause of the alerts).

Example

if (inPrison) stopBot()

logout()

Logs out to the login screen, like the game's exit button.

Example

if (player.hpPercent < 15 && itemCount("Medium Health Potion") === 0) logout()

Waiting

await wait(ms)

Waits ms milliseconds. Use it with await: await wait(1000).

Example

cast("Hurry")
await wait(1000)
log("one second later")

await waitUntil(check, ms)

Waits until the function returns true (up to ms, 5 s if empty). Use it with await.

Example

await waitUntil(() => monstersAround(7) === 0, 10000)

Console

log(...values)

Writes a line in the console of the script.

Example

log("hp:", player.hp, "of", player.maxHp)

warn(...values)

Writes a warning line in the console of the script.

Example

warn("watch out")

why()

Why the last function returned false (for example no-mana, cooldown, no-target, off-screen).

Example

if (!cast("Fire Ball")) log("not now:", why())

messages()

The new game messages since the last call: [{ type: private, system or announcement, from, text }].

Example

for (const m of messages()) if (m.type === "private") warn(m.from, m.text)

47 ready examples

They are in the bot too: Scripts → Examples. A click adds the example turned off, with its description as a comment at the top: check the names (spells, potions, Labels, friends) and turn it on.

Train magic level (Create Rune)

runs every 2 s

Trains magic level: casts SPELL when your mana is at 95% or more and no monster is up to 7 sqm away. Change SPELL to a spell of your vocation (Create Rune needs a blank rune).

const SPELL = "Create Rune"

if (player.manaPercent >= 95 && monstersAround(7) === 0) {
  cast(SPELL)
}

Hurry when no monster is around

runs every 1 s

Casts Hurry when you are not hasted, no monster is up to 7 sqm away and you are out of a protection zone.

if (!player.hasted && !player.inPz && monstersAround(7) === 0) {
  cast("Hurry")
}

Hurry when paralyzed

runs every 0.2 s

Casts Hurry as soon as you are paralyzed.

if (player.paralyzed) {
  cast("Hurry")
}

Mana Block when HP is low

runs every 0.3 s

Casts Mana Block when your HP falls below 40% and it is not on.

if (player.hpPercent < 40 && !player.manaShield) {
  cast("Mana Block")
}

Mana Block when a player shows up

runs every 0.5 s

Casts Mana Block when another player (not in FRIENDS) is up to 7 sqm away on your floor.

const FRIENDS = ["Friend One", "Friend Two"]

const someone = players().find((p) => p.distance <= 7 && !FRIENDS.includes(p.name))
if (someone && !player.manaShield) {
  cast("Mana Block")
}

Heal Target on your friend

runs every 0.3 s

For healers: casts Heal Target when your friend's HP falls below 60% and they are up to 7 sqm away. Save the friend in the game first with /heal Name, and write the same name in FRIEND.

const FRIEND = "Friend Name"

const friend = findPlayer(FRIEND)
if (friend && friend.hpPercent < 60 && friend.distance <= 7) {
  cast("Heal Target")
}

Health potion when HP is low

runs every 0.2 s

Uses POTION when your HP falls below 35%. Change POTION to the health potion you carry.

const POTION = "Medium Health Potion"

if (player.hpPercent < 35) {
  useItem(POTION)
}

Mana potion when mana is low

runs every 0.3 s

Uses POTION when your mana falls below 40%. Change POTION to the mana potion you carry.

const POTION = "Medium Mana Potion"

if (player.manaPercent < 40) {
  useItem(POTION)
}

Berserker on 3+ monsters

runs every 0.5 s

For knights and paladins: casts Berserker when 3 or more monsters are up to 2 sqm away and it is not on.

if (!player.berserker && monstersAround(2) >= 3) {
  cast("Berserker")
}

Defy on 3+ monsters (knight)

runs every 0.5 s

For knights: casts Defy when 3 or more monsters are up to 2 sqm away.

if (monstersAround(2) >= 3) {
  cast("Defy")
}

Area spell on 3 monsters around

runs every 0.3 s

Casts the area spell of your vocation (AREA) when 3 or more monsters stand next to you.

const AREA = { knight: "Twist Rage", paladin: "Arrow Storm", mage: "Fire Wave", healer: "Ice Wave" }

const spellName = AREA[player.vocation]
if (spellName && monstersAround(1) >= 3) {
  cast(spellName)
}

Attack the weakest monster

runs every 0.3 s

Attacks the monster with the least HP up to 6 sqm away. Holds the Target tab while it runs, so they don't fight; turning the script off gives it back.

pause("target")
const near = monsters().filter((m) => m.onScreen && m.distance <= 6)
if (near.length > 0) {
  const weakest = near.reduce((a, b) => (b.hpPercent < a.hpPercent ? b : a))
  if (!target || target.id !== weakest.id) attack(weakest)
}

Attack the boss first

runs every 0.3 s

When a monster from BOSSES is on screen, attacks it, even if you are attacking another one.

const BOSSES = ["Orc Warden", "Dhardon"]

const boss = monsters().find((m) => m.onScreen && BOSSES.includes(m.name))
if (boss && (!target || target.id !== boss.id)) {
  attack(boss)
}

Rune on the target

runs every 0.3 s

Uses RUNE on the monster you are attacking, once every 2 s, while it has 30% HP or more. If the Combat tab also uses this rune, turn it off there.

const RUNE = "Spirit of Doom"

storage.usedAt = storage.usedAt || 0
if (target && target.type === "monster" && target.hpPercent >= 30 && now - storage.usedAt >= 2000) {
  if (useOnTarget(RUNE)) storage.usedAt = now
}

Chase mode on a boss

runs every 0.5 s

Turns the game's Chase on while you attack a monster from BOSSES and off for the others.

const BOSSES = ["Orc Warden", "Dhardon"]

const wanted = target && BOSSES.includes(target.name) ? "chase" : "off"
if (chase !== null && chase !== wanted) {
  chaseMode(wanted)
}

Alarm on few potions

runs every 2 s

Sounds the alarm once and writes it in the console when you have fewer than 20 of POTION.

const POTION = "Medium Mana Potion"
const LIMIT = 20

const left = itemCount(POTION)
if (left < LIMIT && !storage.warned) {
  alarm()
  warn("Only", left, POTION, "left")
  storage.warned = true
} else if (left >= LIMIT) {
  storage.warned = false
}

Hold the Cavebot on few potions

runs every 1 s

Holds the Cavebot while you have fewer than 20 of POTION and lets it go when you have more.

const POTION = "Medium Mana Potion"

if (itemCount(POTION) < 20) {
  pause("cavebot")
} else {
  resume("cavebot")
}

Go refill on low supplies

runs every 2 s

Sends the Cavebot to the label Refill when you have fewer than 30 health or 50 mana potions (once a minute at most). Add a Label named Refill to your route, before the way to the city.

const HEALTH = "Medium Health Potion"
const MANA = "Medium Mana Potion"

const low = itemCount(HEALTH) < 30 || itemCount(MANA) < 50
if (low && cavebot.label !== "Refill" && now - (storage.sentAt || 0) > 60000) {
  if (gotoLabel("Refill")) {
    storage.sentAt = now
    log("Going to refill")
  } else {
    warn("No label Refill in the route")
  }
}

Go to the depot with a full bag

runs every 2 s

Sends the Cavebot to the label Depot when the backpack has 2 free slots or less (once a minute at most).

if (backpackFree !== null && backpackFree <= 2 && cavebot.label !== "Depot" && now - (storage.sentAt || 0) > 60000) {
  if (gotoLabel("Depot")) storage.sentAt = now
}

Buy potions up to 100 (at the NPC)

runs every 1.5 s

Next to a shop NPC (up to 4 sqm): buys ITEM until you have WANT. Use it with Run now or leave it on while you stand at the NPC.

const ITEM = "Medium Mana Potion"
const WANT = 100

const missing = WANT - itemCount(ITEM)
if (missing > 0 && !buy(ITEM, missing)) {
  log("Not yet:", why())
}

Sell loot to the NPC

runs every 1.5 s

Next to a shop NPC: sells every item of SELL that is in your botín, one item per run.

const SELL = ["Orc Leather", "Wolf Paw"]

const item = lootBag.find((it) => SELL.includes(it.name))
if (item && !sell(item.name, "all")) {
  log("Not sold yet:", why())
}

Deposit items at the depot NPC

runs every 1.5 s

Next to the depot NPC: deposits every item of DEPOSIT that is in your backpack, one item per run.

const DEPOSIT = ["Orc Leather", "Wolf Paw"]

const item = backpack.find((it) => DEPOSIT.includes(it.name))
if (item && !deposit(item.name)) {
  log("Not deposited:", why())
}

Deposit gold at the bank

runs every 2 s

Next to the bank NPC: deposits your gold and keeps KEEP in the backpack.

const KEEP = 1000

if (gold !== null && gold > KEEP) {
  depositGold(gold - KEEP)
}

Stop hunting, log out after 2 h

runs every 1 s

After 2 hours online: holds the Cavebot and Target, sounds the alarm once and logs out as soon as you are not attacking anything.

const HOURS = 2

if (online > HOURS * 3600000) {
  pause("cavebot")
  pause("target")
  if (!storage.alarmed) {
    alarm()
    warn("Hunt time is over")
    storage.alarmed = true
  }
  if (!target) logout()
}

Log out with low HP and no potions

runs every 0.3 s

Logs out when your HP falls below 20% and you have no POTION left.

const POTION = "Medium Health Potion"

if (player.hpPercent < 20 && itemCount(POTION) === 0) {
  logout()
}

Alarm on a private message

runs every 0.5 s

Sounds the alarm and writes who sent it and the text when you get a private message.

for (const m of messages()) {
  if (m.type === "private") {
    alarm()
    warn("PM from", m.from + ":", m.text)
  }
}

Stop the bot on a server message

runs every 0.5 s

When a server line has one of the WORDS, sounds the alarm, writes it in the console and turns the bot off.

const WORDS = ["gm", "jail", "prison", "banned"]

for (const m of messages()) {
  if (m.type === "private") continue
  const text = m.text.toLowerCase()
  if (WORDS.some((w) => text.includes(w))) {
    alarm()
    warn("Server:", m.text)
    stopBot()
  }
}

Hold the Cavebot near players

runs every 0.5 s

Holds the Cavebot while a player who is not in FRIENDS is up to 4 sqm away.

const FRIENDS = ["Friend One", "Friend Two"]

const near = players().some((p) => p.distance <= 4 && !FRIENDS.includes(p.name))
if (near) {
  pause("cavebot")
} else {
  resume("cavebot")
}

Alarm on a rare monster

runs every 1 s

Sounds the alarm and writes it in the console when a monster from RARE shows up on your floor, once for each one.

const RARE = ["Orc Warden", "Dhardon"]

storage.seen = storage.seen || {}
for (const m of monsters()) {
  if (RARE.includes(m.name) && !storage.seen[m.id]) {
    storage.seen[m.id] = true
    alarm()
    warn("Rare monster:", m.name, "at", m.distance, "sqm")
  }
}

Alarm when your partner leaves

runs every 1 s

Sounds the alarm when your partner is not on your floor for 15 s. Write the name in PARTNER.

const PARTNER = "Friend Name"

if (findPlayer(PARTNER)) {
  storage.lastSeen = now
  storage.alarmed = false
} else if (now - (storage.lastSeen || now) > 15000 && !storage.alarmed) {
  alarm()
  warn(PARTNER, "left your floor")
  storage.alarmed = true
}
storage.lastSeen = storage.lastSeen || now

Alarm when the Cavebot is stuck

runs every 2 s

With the Cavebot on, sounds the alarm when you stay on the same sqm for 2 minutes.

const here = player.x + "," + player.y + "," + player.z
if (!cavebot.on || here !== storage.here) {
  storage.here = here
  storage.since = now
  storage.alarmed = false
} else if (now - storage.since > 120000 && !storage.alarmed) {
  alarm()
  warn("Standing still for 2 minutes at", here)
  storage.alarmed = true
}

Wait for the respawn at a label

runs every 0.5 s

When the Cavebot passes the label Spawn and no monster is up to 7 sqm away, holds the route up to 40 s waiting for the respawn. Add a Label named Spawn to your route, where the monsters come back.

const LABEL = "Spawn"
const MAX_MS = 40000

if (cavebot.label === LABEL && monstersAround(7) === 0) {
  storage.since = storage.since || now
  if (now - storage.since < MAX_MS) {
    pause("cavebot")
  } else {
    resume("cavebot")
  }
} else {
  storage.since = 0
  resume("cavebot")
}

Change hunt when a player is there

runs every 1 s

While the Cavebot is in the label Hunt and another player (not in FRIENDS) stays up to 8 sqm away for 30 s, goes to the label Hunt 2. Change the labels to the ones in your route.

const FRIENDS = ["Friend One"]
const HUNT = "Hunt"
const NEXT = "Hunt 2"

const other = players().some((p) => p.distance <= 8 && !FRIENDS.includes(p.name))
if (cavebot.label === HUNT && other) {
  storage.since = storage.since || now
  if (now - storage.since > 30000) {
    gotoLabel(NEXT)
    storage.since = 0
  }
} else {
  storage.since = 0
}

Walk a route of sqm by script

runs every 1 s

Walks through the sqm of POINTS one by one and starts over at the end, holding the Cavebot while it walks. To get the x, y of a sqm, stand on it and use the example Write where you are.

const POINTS = [
  { x: 100, y: 200 },
  { x: 104, y: 200 },
  { x: 104, y: 196 },
]

pause("cavebot")
for (const point of POINTS) {
  if (!(await goTo(point, 20000))) {
    warn("Could not reach", point.x, point.y, "-", why())
    break
  }
}

Follow a friend on screen

runs every 1 s

Turns the Follow of the Target / Movement tab on for FRIEND while they are on your floor, and off when they leave.

const FRIEND = "Friend Name"

if (findPlayer(FRIEND)) {
  if (option("follow.playerName") !== FRIEND) setOption("follow.playerName", FRIEND)
  turnOn("follow")
} else {
  turnOff("follow")
}

Smaller Target range on crowds

runs every 1 s

Changes the Target range to 3 sqm when 4 or more monsters are up to 3 sqm away, and back to 6 when they are fewer.

const range = monstersAround(3) >= 4 ? 3 : 6
if (option("target.range") !== range) {
  setOption("target.range", range)
}

Drop junk from the backpack

runs every 1 s

Drops every item of JUNK that is in your backpack, one per run (the game lets you drop from level 8).

const JUNK = ["Bone", "Rotten Meat"]

const item = backpack.find((it) => JUNK.includes(it.name))
if (item) {
  dropItem(item.name)
}

Move items from botín to backpack

runs every 1 s

Moves every item of MOVE from the botín to the backpack, one per run, while the backpack has room.

const MOVE = ["Medium Mana Potion", "Medium Health Potion"]

const item = lootBag.find((it) => MOVE.includes(it.name))
if (item && !moveToBackpack(item.name)) {
  log("Not moved:", why())
}

Kills per hour

runs every 0.3 s

Counts the monsters you kill (your target disappearing with little HP) and writes the kills per hour every minute.

storage.kills = storage.kills || 0
storage.since = storage.since || now
const last = storage.last
if (last && !monsters().some((m) => m.id === last.id) && last.hpPercent <= 20) {
  storage.kills += 1
  storage.last = null
}
if (target && target.type === "monster") {
  storage.last = { id: target.id, hpPercent: target.hpPercent }
}
if (now - (storage.printedAt || 0) >= 60000) {
  storage.printedAt = now
  const hours = Math.max((now - storage.since) / 3600000, 1 / 60)
  log("Kills:", storage.kills, "-", Math.round(storage.kills / hours), "per hour")
}

Experience per hour

runs every 1 min

Every minute writes in the console the experience you gained since the script started and how much per hour.

if (player.experience !== null) {
  if (storage.start === undefined) {
    storage.start = player.experience
    storage.since = now
  }
  const gained = player.experience - storage.start
  const hours = Math.max((now - storage.since) / 3600000, 1 / 60)
  log("Experience:", gained, "-", Math.round(gained / hours), "per hour")
}

Potions used per hour

runs every 1 min

Every minute writes in the console how many of POTION you used per hour and for how long the rest lasts.

const POTION = "Medium Mana Potion"

const have = itemCount(POTION)
if (storage.last === undefined) {
  storage.last = have
  storage.used = 0
  storage.since = now
}
if (have < storage.last) storage.used += storage.last - have
storage.last = have
const hours = Math.max((now - storage.since) / 3600000, 1 / 60)
const perHour = Math.round(storage.used / hours)
const lasts = perHour > 0 ? (have / perHour).toFixed(1) + " h" : "-"
log(POTION + ":", have, "left,", perHour, "per hour, lasts", lasts)

Write where you are (x, y, z)

runs every 5 s

Writes your x, y and z in the console (use Run now). Good to fill the POINTS of Walk a route.

log("x:", player.x, "y:", player.y, "z:", player.z)
log("{ x: " + player.x + ", y: " + player.y + " },")

List what is on screen

runs every 5 s

Writes in the console the monsters, players and NPCs on screen, with the distance (use Run now).

for (const c of creatures()) {
  if (!c.onScreen) continue
  log(c.type, c.name, c.distance + " sqm", c.hpPercent === undefined ? "" : c.hpPercent + "%")
}
log("Monsters:", monsters().length, "Players:", players().length)

Charging only while hunting

runs every 2 s

Turns your Charging on when a monster is up to 7 sqm away and off in a protection zone. The game asks 1 minute between changes.

if (player.inPz) {
  chargingOff()
} else if (monstersAround(7) > 0) {
  chargingOn()
}

Ring when HP is low

runs every 0.3 s

Puts RING on when your HP falls below 40% and takes it off above 80%. Change RING to the ring you carry.

const RING = "Ring Name"

if (player.hpPercent < 40) {
  equip(RING)
} else if (player.hpPercent > 80 && equipment.some((e) => e.name === RING)) {
  unequip("ring")
}

Potions from the mailbox

runs every 2 s

Moves POTION from the mailbox to the backpack when you have fewer than 50 of it.

const POTION = "Medium Mana Potion"

if (itemCount(POTION) < 50 && mailbox.some((it) => it.name === POTION)) {
  takeFromMailbox(POTION, 50 - itemCount(POTION))
}

Click a chest on the map

runs every 0.5 s

Clicks the sqm CHEST once when you stand next to it, for things on the map you take by clicking. Change CHEST to the x, y of the chest (use the example Write where you are).

const CHEST = { x: 100, y: 200 }

if (!storage.done && distance(CHEST) <= 1) {
  if (clickMap(CHEST.x, CHEST.y)) storage.done = true
}