What a package's script can reach inside Asterobot, what it can't, and the one job every Full socket script does itself.
A script is the JavaScript code inside a package. When a bot plays a package, Asterobot runs that code for the bot, right next to the bot's connection to the game. Read this before your first script: it saves you from looking for things that don't exist.
One copy per bot
Every bot that plays a package runs its own copy of the script. Two bots playing the same package share no variables, a script can't see or control another bot, and stopping one bot's script leaves the others running.
The code runs inside Asterobot, on the computer where Asterobot runs. Asteroboard only shows you what happens, so closing it doesn't stop a script.
What a script can do
Everything a script can do comes from the built-in modules it imports:
| To | Use | From |
|---|---|---|
| React to messages the game server sends | on(), wait() |
asterobot:protocol |
| See every message, in both directions | onTraffic() |
asterobot:protocol |
| Send messages | send(), request() |
asterobot:protocol |
| Change or block messages on their way through | intercept() |
asterobot:protocol |
| Read game data: items, monsters, maps, game texts | text(), record(), table(), find(), search(), query() |
asterobot:gamedata |
| Show settings on the bot's page and read them | export const parameters, values, onChange() |
Your index.js, and asterobot:parameters |
| Show buttons on the bot's page | export const actions |
Your index.js |
| Write to the bot's console | botDebug(), botInfo(), botWarn(), botError() |
asterobot:bot |
| Write to Asterobot's own log | debug(), log(), info(), warn(), error() |
asterobot:console |
| Read the session: game ticket, server, language, why the script started | session |
asterobot:bot |
| Know where the character stands: its map, its cell, the actors around it and the interactive elements of the map | currentMap() |
asterobot:bot |
| Keep values that outlive the script, and share them with the bot's other packages | memory |
asterobot:bot |
| Know the character's level, kamas, energy, life and pods, whether it's in a fight, its items, how many of an item it has and its job levels | character(), items(), itemCount(), jobLevel() |
asterobot:character |
| Have the fight module play the character's fights, with the profile, speed and kinds of fight you choose while the script runs | enable(), disable(), setProfile(), setSpeed(), setFights() |
asterobot:fight |
| Follow every fight, read the fight under way, and take the fight module's decisions yourself | onFight(), state(), onDecision() |
asterobot:fight |
| Say things in the game chat or whisper a player, with random wording, the character's level or map and item links, while the bot's chat guard waits out each channel's cooldown | say(), whisper(), setVariable() |
asterobot:chat |
| Have the chat module post ads, answer private messages and act on the channels' lines from the chat profiles you pick while the script runs, answer private messages yourself, and hear what it does | enable(), setProfiles(), setFlag(), onAnswer(), onChat() |
asterobot:chat |
| Raise an event of your own for the alarms' rules, and hear every event of the bot: staff, whispers, the chat module's, the game messages the rules hook | raise(), onAlarm() |
asterobot:alarms |
| Find the route the Dofus client would walk to a cell of a map, and how long walking it takes | findPath() |
asterobot:pathfinding |
| Work out a cell's grid position, or the distance and the direction between two cells | cellToPoint(), pointToCell(), distance(), direction() |
asterobot:pathfinding |
| Walk the character to a cell of its map, and wait for the end of the walk | move() |
asterobot:movement |
| Take the character to the next map by one side of its map, from the exit you choose or the nearest one | changeMap() |
asterobot:movement |
| Use an interactive element of the map: a door, a zaap, a resource, a workshop, or an exit drawn as a sun | useElement() |
asterobot:movement |
| Take the character to any map, however far, through map sides, stairs, suns and doors, or just see the way there | travel(), route() |
asterobot:movement |
| Answer the proof of identity the game server asks a Full socket bot for | commitment(), publicKey(), proof() |
asterobot:verification |
| Pause for a while | sleep() |
asterobot:timers |
| Close the bot's game connection | disconnect() |
asterobot:bot |
| Read the name, version and permissions of your package or of one of its dependencies | packages.info() |
asterobot:runtime |
In MITM mode (man-in-the-middle: the bot relays the game session of a Dofus client that someone plays), the same functions work on that session. A script sees what the Dofus client sends and what the server answers. It can send messages to the server as if the client had sent them, or to the client as if the server had, and it can change or drop messages before they reach the other side.
The reference describes every function, one page per module.
What a script can't do
Some things you'd expect from JavaScript elsewhere aren't there, and a package can't add them.
| Not available | Use instead |
|---|---|
| Reading or writing files | Nothing. A script only has the modules of its own package and of the packages it depends on. |
The internet: fetch(), sockets, HTTP requests |
Nothing. The bot's game connection is the only connection a script talks through. |
npm packages and require() |
import from the asterobot: modules, from your package's own files, or from library packages your package declares as dependencies. |
setTimeout() and setInterval() |
await sleep(milliseconds) from asterobot:timers. |
The global console |
The console functions of asterobot:bot or asterobot:console, imported like anything else. |
window, document, process and the other browser or Node.js globals |
Nothing. |
Scripts also run within limits. For example, code that runs for more than 5 s without awaiting anything, as an endless loop does, ends the script. Limits lists them all.
Built-in moves, and what isn't built in
Moving the character is built in, on both kinds of bot, the way the Dofus client does it when the player clicks. move() walks the character to a cell of its map. changeMap() takes it to the next map by one side, from the exit you choose or the one it reaches soonest. useElement() uses a door, a zaap, a resource, a workshop or an exit drawn as a sun, walking within reach first. travel() takes it to any map, however far, map after map along the game's own travel graph. currentMap() says where the character, the other actors and the interactive elements are, and findPath() gives the route the Dofus client would take and how long the walk lasts.
There's no built-in function that chooses a zaap's destination or plays a fight, and travel() doesn't take zaaps yet. A script does those the way the Dofus client does: it sends the messages the client would send and reacts to what the server sends back, as Harvest and move on does for a zaap. The Dofus protocol reference describes those messages, and How bots talk to Dofus explains how they work.
Full socket scripts identify the bot
In Full socket mode, Asterobot signs in with the Ankama account, picks the game server and opens the game connection. Then it stops. It doesn't identify the bot on the game server and doesn't choose a character: that's the script's job. Its first message on a new connection must be IdentificationRequest, and Identify and run shows the few lines that send it. Every sample in these docs includes them, so each one works in both modes.
A MITM bot doesn't need them. The Dofus client has already identified the session when the script starts, and the same lines skip the identification there.
The official package @asterobot:base, which Asterobot installs and keeps up to date by itself, takes a Full socket bot into the game for you: it identifies the connection, selects a character, enters the world and keeps the connection alive. A package that depends on it starts from a character standing on its map.
Next, read The JavaScript you need, or go straight to Create a package if you'd rather start typing.