What is MBT?
Plain text scripts saved on your PC
An MBT script is a few lines of plain text. You write it in the in-game Script Studio and the SarahBOT client saves it on your PC, so your scripts stay with you. Every saved script shows up in the Studio list with its own run/stop button.
# Lines starting with # are comments
name "My First Script"
auto 200
if $hppc < 80 and $mp >= 20
cast "exura"
wait 900 1100
end Safe by design. The MBT language has no commands for logging out, switching characters, reconnecting or closing the client. Those actions are not blocked — they simply cannot be written. A script can never take you offline.
Used the old web editor? The scripts you saved on your account are kept in the read-only My Scripts archive. Copy or download them from there and paste them into the Studio.
- The Scripts feature enabled on your SarahBOT account. It is granted manually — ask on Discord.
- SarahBOT installed, signed in with Discord and attached to Necroxia Origin (see the getting started guide).
Quick Start
Your first script in five steps
Open the Script Studio
In the game, click the SCRIPTS button of the bot window or
press Ctrl+Shift+S. The Studio lists your scripts on the
left, each with a status dot and a run button, and shows the editor
on the right.
Create a script
Click + NUEVO SCRIPT and type a name for it in the box above the editor.
Write and save it
Paste the example above and click GUARDAR (or press
Ctrl+S). The script is saved on your PC and appears in the
list under its name directive, or under the name you typed
when there is none.
Test it
Press PROBAR (or F5) to try the script without
leaving the editor. A mistake shows up in the status bar with the line
where it happened.
Start it
Press RUN on its row. The dot turns green and the script runs
until you press STOP, it executes a stop command,
or you log out. Scripts always stop when you leave the game.
To change a script, open it in the Studio, edit it and click GUARDAR again — if it is running, the client restarts it with the new code.
Directives
The optional header of a script
Directives go at the top of the file, before any command. All of them are optional.
name "Mana Trainer"
auto 500
widget 3031 3035 "Trainer" auto — repeating mode
With auto 500 the whole script body runs again every 500
ms while the script is on — perfect for healers, eaters and trainers.
Minimum interval is 50 ms.
no auto — macro mode
Without auto, the script runs top to bottom once and
stops by itself — perfect for one-shot routines like buying
supplies or saying a sequence of things.
widget — floating on/off button
widget 3031 3035 "Trainer" puts a floating button over
the game map that turns the script on and off with one click. It
shows the sprite of item 3031 while the script is OFF,
item 3035 while it is ON, and the text below it (max 12
characters). The ON id and the text are optional: without the ON id
both states use the same sprite, without text it shows the script
name. An auto script stays ON while it runs; a macro
lights up while it executes and goes back to OFF when it finishes.
Drag it anywhere on the map or drop it near an edge to dock it to the left or right column; right click for quick options. Widgets hide together with the bot window (Ctrl+I). One widget per script.
Variables
Read the game, remember your own values
Variables always start with
$. Game
variables are read-only — the bot fills them with live values every
time your script looks at them.
| Character stats | Meaning |
|---|---|
| $hp | Current hit points |
| $maxhp | Maximum hit points |
| $hppc | Health percentage (0–100) |
| $mp | Current mana |
| $maxmp | Maximum mana |
| $mppc | Mana percentage (0–100) |
| $level | Character level |
| $cap | Free capacity |
| $stamina | Stamina left, in minutes |
| $soul | Soul points |
| $myname | Your character's name |
| $myid | Your character's unique creature id — compare against thingid() to exclude yourself |
| Position | Meaning |
|---|---|
| $posx | Your X coordinate on the map |
| $posy | Your Y coordinate on the map |
| $posz | Your floor (Z coordinate) |
| Target | Meaning |
|---|---|
| $target | Name of the creature you are attacking (empty text when none) |
| $targethppc | Health percentage of your target |
| $targetdist | Distance to your target, in tiles |
| Status flags | Meaning |
|---|---|
| $connected | true while you are logged into the game |
| $pz | true while you stand in a protection zone |
| $paralyzed | true while you are paralyzed |
| $poisoned | true while you are poisoned |
| $burning | true while you are burning |
| $hasted | true while haste is active |
| Mouse | Meaning |
|---|---|
| $mousex | Mouse X position on screen, in pixels |
| $mousey | Mouse Y position on screen, in pixels |
| $mousetilex | Map X of the tile under the mouse (0 when none) |
| $mousetiley | Map Y of the tile under the mouse (0 when none) |
| $mousetilez | Floor of the tile under the mouse (0 when none) |
| Waypoints | Meaning |
|---|---|
| $wptactive | true while the bot's waypoint walking is running |
| $wptindex | Index of the waypoint being walked to right now |
| $wptcount | How many waypoints are loaded |
Your own variables
Use set to
create and update your own variables. They keep their value between
auto repetitions while the script is running. Assigning to
a game variable like $hp is a syntax error.
set $count = 0
set $count = $count + 1
set $greeting = "hunting " + $target Functions
Ask questions about the world
Functions can be used anywhere an expression is expected — in
conditions, in set, or as command arguments.
| Function | Returns |
|---|---|
| itemcount(id) | How many of an item you carry (inventory + open backpacks) |
| monstersaround(range) | Monsters within range tiles of you |
| playersaround(range) | Other players within range tiles of you |
| distance(x, y) | Distance from your position to the coordinate x, y |
| creaturehppc(c) | Health % of a creature on screen — by name, creature id or saved $thing (0 when not visible) |
| creaturex(c) / creaturey(c) / creaturez(c) | Map position of a creature on screen (0 when not visible) |
| creaturedist(c) | Distance to a creature on screen (999 when not visible or on another floor) |
| outfit() | Your outfit as a list [type, head, body, legs, feet, addons] — feed it straight to setoutfit |
| creatureoutfit(c) | Same list for a creature on screen (empty list when not visible) |
if itemcount(3160) < 10
log "running low on runes"
end
if monstersaround(3) >= 2 and playersaround(7) == 0
cast "exori"
end
if creaturehppc("Bob") > 0 and creaturedist("Bob") <= 5
say "hang in there Bob!"
end Text analysis
Extract numbers, words and patterns from any text — perfect for
reacting to what an NPC says inside on npctalk.
match and matchall use Lua patterns:
%d+ is a number, %a+ a word, and parentheses capture
just that part.
| Function | Returns |
|---|---|
| contains(text, part) | true when part appears in text, ignoring upper/lower case |
| match(text, pattern) | First Lua-pattern match, or "" — match("price: 50 gp", "(%d+)") gives "50" |
| matchall(text, pattern) | List with every match — matchall("10 20 30", "%d+") gives ["10", "20", "30"] |
| split(text, sep) | Splits into a trimmed list — split("a, b, c", ",") gives ["a", "b", "c"] |
| lower(text) / upper(text) | The text in lowercase / uppercase |
| tonum(v) | Text to number (0 when not convertible) — use it on match() results before doing math, since + with text concatenates |
on npctalk
if contains($npcmsg, "do you want to buy")
npcsay "yes"
end
set $price = match($npcmsg, "(%d+) gold")
if $price != ""
serverlog $npcname "asks for" $price "gold"
end
end
The same analysis works on anything the server sends through
on message — the server log included.
on message "serverlog"
set $gained = match($msgtext, "You gained (%d+) experience")
if $gained != ""
set $total = $total + tonum($gained)
end
end
on message "private"
cancelmsg $msgname "wrote:" $msgtext
end
on message "channel:Loot"
chat "[" $msgchannel "]" $msgtext
end Things
Grab what is on a tile or in a bag
A thing is a snapshot of a creature
or an item taken from the map or from an open container. Save it in a variable
with set, inspect it, and pass it to commands like useat, movetotile or
opencontainer. When there is nothing to grab these
functions return 0, so a plain
if $t tells you whether you got something.
| Function | Returns |
|---|---|
| topthing(x, y) | Top of the tile — creature if there is one, else the top item (z optional) |
| topitem(x, y) | Only the top item of the tile |
| topcreature(x, y) | Only the top creature of the tile |
| containeritem(c, slot) | The item at a slot of an open container (both start at 0) |
| thingid($t) | Item id (or creature id) of a saved thing |
| thingname($t) | Creature name of a saved thing (items return empty text) |
| thingcount($t) | Stack count of a saved item |
| isitem($t) | true if the thing is an item |
| iscreature($t) | true if the thing is a creature |
set $t = topthing($posx + 1, $posy)
if iscreature($t)
log "next to me: " + thingname($t)
elseif isitem($t)
log "item on the tile: " + thingid($t)
end Containers
Open containers are numbered from 0 in the order they were opened.
Combine these with containeritem(c, slot) and a
while loop to iterate every item in a bag.
| Function | Returns |
|---|---|
| containers() | How many containers you have open |
| containeritems(c) | Number of items inside container c |
| containername(c) | Name of container c |
| containercap(c) | Capacity (slots) of container c |
set $i = 0
while $i < containeritems(0)
set $t = containeritem(0, $i)
if thingid($t) == 3031
log "gold at slot " + $i + " x" + thingcount($t)
end
set $i = $i + 1
end Party and guild
isparty(x) and isguild(x) accept a player name
or a saved creature thing, and let you react differently to friends and
strangers. Party detection uses the party shield, so it works whenever you
are in a party; guild detection relies on war emblems, so it only works
while a guild war is active.
set $c = topcreature($posx + 1, $posy)
if iscreature($c) and isparty($c)
say "hello party friend!"
elseif iscreature($c) and not isguild($c)
log "stranger nearby: " + thingname($c)
end Marking creatures
mark $c draws a permanent square around a creature, only on
your screen. It accepts a saved thing, a creature id or a name, and an
optional color: yellow (default), red,
green, blue, cyan,
orange, purple, pink,
white, black or "#RRGGBB". The mark
is tied to the creature id, so it is still there when the creature leaves
your screen and comes back, or when you change floor. It disappears when
the creature dies, with unmark / unmarkall, or
when the script that placed it stops — use an event script
(on look, on key) so the marks stay alive.
ismarked(c) tells whether a creature is marked,
markedcount() how many are, and markedlist()
returns their ids in the order they were marked.
name "Tag the real boss"
on look
if iscreature($lookthing)
if ismarked($lookthing)
unmark $lookthing
else
mark $lookthing "yellow"
end
end
end Lists
Group names, ids and things in one variable
A list holds several values in one
variable — friend names, item ids, saved things, or a mix. Create one with
square brackets; positions start at 1. Lists are values: listadd and listremove return a
new list, so assign the result back with set. An
empty list counts as false in an if, and
+ joins two lists into a new one.
| Function | Returns |
|---|---|
| ["a", "b"] | Create a list — mix text, numbers and saved things freely |
| listcount($l) | How many elements the list holds |
| listget($l, i) | Element at position i — the first one is 1 (0 when it does not exist) |
| listcontains($l, v) | true when v is in the list (text is matched ignoring upper/lower case) |
| listindex($l, v) | Position of v in the list (0 when it is not there) |
| listadd($l, v) | A new list with v appended — assign it back: set $l = listadd($l, v) |
| listremove($l, v) | A new list without the first occurrence of v |
| listrandom($l) | A random element (0 when the list is empty) |
| islist($v) | true when the value is a list |
set $friends = ["Bob", "Alice"]
set $friends = listadd($friends, "Eve")
set $c = topcreature($posx + 1, $posy)
if iscreature($c) and thingid($c) != $myid
if listcontains($friends, thingname($c))
say listrandom(["hello!", "hey there", "welcome back"])
else
log "stranger: " + thingname($c)
end
end Commands
Everything a script can do
One command per line. Commands in the same cooldown group share their cooldown — if a command is not ready yet, the script simply waits until it is. No spam, no kicks.
| Command | What it does | Cooldown |
|---|---|---|
| say "text" | Say a message in the default channel | 600 ms · talk |
| yell "text" | Yell a message | 600 ms · talk |
| npcsay "text" | Talk in the NPC channel | 600 ms · talk |
| pm "player" "text" | Send a private message | 600 ms · talk |
| cast "exura" | Cast a spell by saying its words | 600 ms · cast |
| starttrade 3031 "Player" | Offer the whole stack of that item to a nearby player in a trade (first stack found in your backpacks, or a saved $thing to pick one). Also answers a trade someone else opened. Does nothing if you already offered something, the item is missing or the player is not on screen. The player has to approve the script once because it offers without asking; with a variable or a $thing it asks before every trade | 1000 ms · starttrade |
| accepttrade "Player" | Accept the open trade with that player. Does nothing if there is no trade, the other player has not offered anything yet, or it is someone else, so it is safe inside an auto loop. The player has to approve the script once because it accepts without asking; with the name in a variable or no name at all it asks before every trade | 500 ms · trade |
| useitem 3160 | Use an inventory item by its id | 250 ms · use |
| useonself 3160 | Use an item on your own character | 250 ms · use |
| useontarget 3155 | Use an item on your current target | 250 ms · use |
| attack "Troll" | Attack the nearest living creature with that name on screen (also accepts a creature id or a saved $thing). Does nothing if you are already attacking it, so it is safe inside an auto loop | 200 ms · attack |
| cancelattack | Stop attacking your current target | — |
| mark $c "yellow" | Draw a permanent colored square around a creature (saved $thing, id or name). The color is optional (yellow by default) | — |
| unmark $c | Remove the square from that creature | — |
| unmarkall | Remove every mark | — |
| turn north | Turn to a direction (north, south, east, west) | 100 ms · step |
| step east | Walk one step in a direction | 100 ms · step |
| gotopos 100 100 7 | Walk to a position and wait until you arrive (z optional) | — |
| stopwalk | Cancel the current auto-walk | — |
| useat 100 100 7 | Use the top thing at a position (also accepts a saved $thing) | 250 ms · use |
| usewith 3155 100 100 7 | Use an inventory item on a position or saved $thing | 250 ms · use |
| movetotile $t 100 100 7 | Move an item (saved $thing or item id from your bags) to a tile, optional count | 300 ms · move |
| movetocontainer 100 100 7 0 | Move the top item of a tile (or a saved $thing) into open container 0 | 300 ms · move |
| opencontainer 2854 | Open a container by item id, saved $thing or ground position | 250 ms · use |
| closecontainer 0 | Close the open container with that index | — |
| setoutfit 128 | Change your outfit: type, then optional head body legs feet addons | 1000 ms · outfit |
| setcreatureoutfit "Name" 75 | Visually change another creature's outfit — only on your screen | — |
| equip 3420 | Equip an item by id — the server picks the slot; add a slot name to place it yourself | 300 ms · move |
| unequip "left" | Move what is in a slot into your first open container (or a given container index) | 300 ms · move |
| chat "text" | Show a message in your Default channel — only you see it | — |
| serverlog "text" | Show a message in your Server Log — only you see it | — |
| cancelmsg "text" | Show a status message under the game view, like "Sorry, not possible" | — |
| alarm "danger" | Play a voice alarm from the Alarms window (MAX plan, game opened from the launcher). Any alarm id works: danger, low_health, player_attack, private_message...; it uses that alarm's switch and volume | 1 s · alarm |
| wait 500 | Pause this script for 500 ms | — |
| wait 900 1100 | Pause a random time between 900 and 1100 ms | — |
| log "message" | Write a line to the bot log | — |
| stop | Stop this script immediately | — |
| wptload $route | Load a waypoint list — each entry is [x, y, z] plus an optional action: "use" (doors, stairs, levers), "usewith" + item id (rope, shovel), "say" + text (spells); append [nx, ny, nz] to retry the action until you land there | — |
| wptstart "loop" | Start walking the route — "loop" cycles forever, "once" walks a single pass, no argument keeps the panel setting | — |
| wptstop | Stop the waypoint walking | — |
| questline "tasks" | Ask the server for the quest whose name contains that text — its missions arrive via on questline (the strict way to track task progress) | 600 ms · quest |
Tip: prefer wait with a range, like
wait 900 1100 — the random pause looks a lot more human than
a fixed one.
gotopos blocks until you arrive.
It walks like a map click and holds the script on that line until you
reach the tile. If the spot is unreachable it gives up after about 15
seconds (longer for far destinations) and the script continues — check
distance(x, y) afterwards if you need to be sure you made
it.
Slots and message commands.
Valid slot names for equip / unequip are
head neck back body right left legs feet ring ammo. The
visual commands chat, serverlog and
cancelmsg accept up to 8 arguments joined with spaces:
chat "hp:" $hppc "%" — perfect for debugging your own scripts.
Control Flow
Decisions and loops
if / elseif / else
Every if needs a closing
end.
Conditions are checked top to bottom and only the first true branch
runs.
if $hppc < 50
cast "exura vita"
elseif $hppc < 80
cast "exura"
else
wait 200
end while
Repeats its body as long as the condition stays true. The engine keeps the game responsive even if the loop never ends.
while $mppc < 90
wait 500
end
say "mana is back!" repeat
Repeats its body an exact number of times.
repeat 50
useonself 3160
wait 1000 1200
end label / goto
goto jumps to a label in the same block or any
enclosing block. Handy for retry loops.
label ready
if $mp < 20
wait 2000
goto ready
end
cast "exura" Events
React to keys, clicks, NPCs, waypoints and items
An on block
anchors part of your script to an event. While the script is running, the
block fires every time the event happens — in parallel with the script body,
sharing your set variables. A script that only has on blocks stays alive listening even though its body finished.
on key "Ctrl+F5"
set $active = not $active
cancelmsg "active:" $active
end
on click
if $button == "right" and iscreature($clickthing)
serverlog "clicked" thingname($clickthing) "at" $clickx $clicky
end
end on key "combo"
Fires when you press a key or combo: "F5",
"Ctrl+F5", "Shift+A",
"Alt+1". Inside the block, $key holds the
combo that fired.
on click
Fires when you click the game map with any button. The game still handles the click normally — your script just observes it.
on look
Fires when you Look at something — Shift+click on the map, the Look
option of the menu or the battle list. The look still reaches the
server as usual. Inside the block, $lookthing is what you
looked at; pair it with mark to tag creatures.
on npctalk
Fires every time an NPC speaks on screen. Inside the block,
$npcname is the NPC and $npcmsg the full message
— combine with contains() and
match() to react to what it said.
on message ["filter"]
Fires for any message the server sends you — chat (say/yell,
privates, channels, NPCs, monsters) and the server log (loot, exp, damage,
status, login, warnings). The optional filter narrows it down: group
filters talk,
server, serverlog, default,
private, channel,
"channel:Loot", npc,
monster; or a single exact mode such as
"loot" or "exp". Without a filter you
receive everything, so filter early.
on wptdone / on wptcycle
wptdone fires when the waypoint route reaches its final
destination (single-pass mode); wptcycle fires each time
the route completes a lap in loop mode and keeps walking.
on questline
Fires when quest log data arrives after a
questline "name" request (or when you open a quest in the
Quest Log window). Script requests are silent — the client's Quest Log
window never opens. $missions holds each mission's description
— extract kill counters with
match($desc, "killed (%d+)") for exact task tracking.
on itemappear / on itemdisappear
Fire when an item with the given id shows up on, or leaves, a tile:
on itemdisappear 2129. The id is required and must be a
literal number (up to 16 of them: on itemappear 2129 2130).
Add near N to only react within N tiles of you on your own
floor: on itemappear 2129 near 7. Only items are detected,
not creatures or effects, and items already lying on freshly loaded tiles
(login, walking, changing floor) may fire itemappear. It
replaces polling topitem() inside an auto loop
— for example, re-casting a Magic Wall the moment it vanishes:
on itemdisappear 2129
if $activo == 1 and $itemx == $wx and $itemy == $wy and $itemz == $wz
wait 80 160
usewith 3180 $wx $wy $wz
end
end | Event variable | Meaning |
|---|---|
| $key | Inside on key — the combo that fired, in lowercase (e.g. "ctrl+f5") |
| $button | Inside on click — 'left', 'right' or 'middle' |
| $clickx / $clicky / $clickz | Inside on click — position of the clicked tile (0 when the click missed the map) |
| $clickthing | Inside on click — top thing of the clicked tile (0 when empty); works with useat, thingid, iscreature… |
| $lookthing | Inside on look — what you looked at, as a thing (creature or item); works with iscreature, mark, thingname… |
| $lookid | Inside on look — creature id or item id of what you looked at |
| $lookname | Inside on look — name of the creature or item |
| $lookx / $looky / $lookz | Inside on look — position of what you looked at (x is 65535 for items in backpacks) |
| $npcname | Inside on npctalk — name of the NPC that spoke |
| $npcmsg | Inside on npctalk — the full message; analyze it with contains() and match() |
| $msgtext | Inside on message — the message text |
| $msgmode | Inside on message — the exact mode (say, yell, private, channel, loot, exp, status…) |
| $msgname | Inside on message — who said it (empty for server messages with no speaker) |
| $msglevel | Inside on message — level of the speaker (0 when it does not apply) |
| $msgchannel | Inside on message — destination: 'Default', 'Server Log', the channel name, or the player name on a private |
| $msgchannelid | Inside on message — numeric channel id (-1 when the message is not from a channel) |
| $questname / $questid | Inside on questline — quest name (empty when not found) and id |
| $missions / $missionnames | Inside on questline — lists with each mission's description and name; parse with listget() + match() |
| $itemid | Inside on itemappear / itemdisappear — id of the item |
| $itemx / $itemy / $itemz | Inside on itemappear / itemdisappear — position of the tile |
| $itemdist | Inside on itemappear / itemdisappear — distance to you in tiles (999 on another floor) |
| $itemthing | Inside on itemappear / itemdisappear — the item as a thing; works with thingid(), thingname() and thingcount() |
Rules. on blocks only go at the top level of the script — never
inside if, loops or another on. If an
event fires again while its block is still running, that repetition
is ignored (holding a key down won't queue up work). Event variables
like $key exist only inside their block.
Expressions
Operators you can use
Standard arithmetic. % is the remainder.
Compare numbers or text. Result is true or false.
Combine conditions. and/or short-circuit like you expect.
Parentheses control evaluation order.
When one side is text, + joins them: "hp: " + $hppc.
Strings work with double or single quotes. Keywords and commands are
case-insensitive: IF, If and
if are the same thing.
Complete Examples
Copy, tweak, run
name "Spell Trainer"
set $casts = 0
while $casts < 100
if $mp >= 20
cast "exura"
set $casts = $casts + 1
end
wait 900 1100
end
log "finished: " + $casts + " casts" name "Food Eater"
auto 240000
useonself 3577
wait 400 700
useonself 3577 name "Anti Paralyze"
auto 200
if $paralyzed and $mp >= 20
cast "utani hur"
end name "Panic Alert"
auto 500
if $hppc < 30
pm "My Friend" "help! low hp at " + $posx + " " + $posy
wait 10000
end name "Drop Gold"
gotopos 1024 1024 7
set $i = 0
while $i < containeritems(0)
set $t = containeritem(0, $i)
if thingid($t) == 3031
movetotile $t $posx $posy $posz
wait 400 600
else
set $i = $i + 1
end
end
say "gold dropped" name "Sio Party"
auto 500
set $c = topcreature($posx + 1, $posy)
if iscreature($c) and isparty($c) and $mp >= 70
cast 'exura sio "' + thingname($c) + '"'
wait 900 1100
end name "Target Guard"
auto 500
if $target == "" and monstersaround(5) > 0
attack "Troll"
elseif $target != "" and $hppc < 20
cancelattack
end name "Hand Swap"
on key "F6"
equip 3420 "left"
cancelmsg "shield equipped"
end
on key "F7"
unequip "left"
cancelmsg "hand free"
end name "Tile Inspector"
on click
if $button == "right"
if iscreature($clickthing)
serverlog "creature:" thingname($clickthing) "at" $clickx $clicky
elseif isitem($clickthing)
serverlog "item id" thingid($clickthing) "x" thingcount($clickthing)
end
end
end FAQ
Common questions
I don't know how to program. Can I still make scripts?
Can a script log me out, switch character or close the client?
My script shows a red error state.
end) and runtime errors
(like dividing by zero), and RUN stays disabled until it
is fixed. Correct the script in the Studio and click
GUARDAR.
Why does my script pause between commands on its own?
wait lines for bigger, human-like pauses.
Can an infinite while loop freeze the game?
while 1 == 1 with no wait keeps the client perfectly
smooth.
Can gotopos get my script stuck forever?
distance(x, y) right after it when you need to confirm you
actually arrived, and stopwalk to cancel a walk early.