Documentation › Lua

CaveBot

The CaveBot module controls the CaveBot route from a script: jump to a label, pause, read and edit waypoints, change lure settings and the sell and refill lists.

Waypoints are counted from 0. Route changes made by the script take effect without stopping the CaveBot.

CaveBot.GoTo(label)#

CaveBot.GoTo(label) → boolean

Jumps the route to the Label waypoint with that text (case-insensitive). Returns false if the label does not exist. Inside a Script waypoint, it also ends the script.

lua
if Game.getItemCount(268) < 50 then CaveBot.GoTo("refill") end

CaveBot.selectWaypoint(index)#

CaveBot.selectWaypoint(index)

Jumps the route to the waypoint by its number. Inside a Script waypoint, it also ends the script.

lua
CaveBot.selectWaypoint(0) -- back to the start

CaveBot.getSelectedWaypointId()#

→ number

Current waypoint. Returns -1 when the route is empty.

lua
print("current waypoint: " .. CaveBot.getSelectedWaypointId())

CaveBot.pause(ms)#

CaveBot.pause(ms)

Pauses the route for ms milliseconds. 0 resumes right away, including the pause from the LABEL event.

lua
CaveBot.pause(10000) -- waits 10 s
CaveBot.pause(0)     -- resumes

CaveBot.stopCurrentScript()#

CaveBot.stopCurrentScript()

Stops the Script waypoint that is running.

lua
CaveBot.stopCurrentScript()

Reading waypoints#

CaveBot.getWaypoints()#

→ list

Every waypoint, as {x, y, z, type, data}. type is the Enums.WaypointType number and data is the waypoint's text (label, script code).

lua
for i, w in ipairs(CaveBot.getWaypoints()) do print(i - 1, w.type, w.data) end

CaveBot.getWaypointsCount()#

→ number

How many waypoints the route has.

lua
print(CaveBot.getWaypointsCount())

CaveBot.getWaypointTypeById(index) and CaveBot.getWaypointDataById(index)#

→ number / → table or nil

The waypoint's type (-1 if the index does not exist) and the whole waypoint {x, y, z, type, data} (nil if it does not exist).

lua
local w = CaveBot.getWaypointDataById(CaveBot.getSelectedWaypointId())
if w then print(w.x, w.y, w.z) end

Editing waypoints#

type is Enums.WaypointType (an unknown number becomes Node). data is the waypoint's text, optional.

FunctionWhat it does
CaveBot.addWaypoint(type, x, y, z, data)Adds at the end
CaveBot.insertWaypoint(index, type, x, y, z, data)Inserts at the position
CaveBot.replaceWaypoint(index, type, x, y, z, data)Replaces the waypoint
CaveBot.deleteWaypoint(index)Deletes the waypoint
CaveBot.clearWaypoints()Deletes all of them and restarts the route
lua
local p = Player.getPosition()
CaveBot.addWaypoint(Enums.WaypointType.WAYPOINT_TYPE_STAND, p.x, p.y, p.z)
CaveBot.addWaypoint(Enums.WaypointType.WAYPOINT_TYPE_LABEL, 0, 0, 0, "back")

Files#

CaveBot.saveFile(name) and CaveBot.loadFile(name)#

→ boolean

Save and load the route to a file inside the scripts/ folder (ZeroBot uses Documents/ZeroBot). With a name ending in .lua, saveFile writes a ZeroBot script with the route and the settings; with any other name, it writes DrenoxBot's route JSON. loadFile reads both formats and restarts the route. They return false for a path outside scripts/ or a file that does not exist.

lua
CaveBot.saveFile("routes/rotworm.lua")
CaveBot.loadFile("routes/rotworm.lua")

Walking#

FunctionWhat it does
CaveBot.setWalkMode(mode)Enums.WalkMode: 1 (ARROW_KEYS) walks step by step, any other value walks by path
CaveBot.setWalkDelay(ms)Wait between steps
CaveBot.setNodeSettings(distance)Distance at which a Node counts as reached (default 3)
CaveBot.setStartFromNearestWaypoint(enable)Starts the route from the nearest waypoint
CaveBot.disablePlayerWalkthrough(enable)Turns on the setting to not walk through players (default true)
CaveBot.getCoreTeleportIds() / CaveBot.setCoreTeleportIds(ids)List of teleport ids the CaveBot knows
lua
CaveBot.setWalkMode(Enums.WalkMode.MAP_CLICK)
CaveBot.setNodeSettings(2)

CaveBot.isDebugEnabled() and CaveBot.setDebugHUDSettings(a, b, c)#

→ boolean

DrenoxBot has a single text debug HUD: setDebugHUDSettings turns the HUD on if any of the three parameters is true. ZeroBot's separate path and tile drawings do not exist here.

lua
CaveBot.setDebugHUDSettings(true, false, false)

Lure#

CaveBot.setLureSettings(toRun, dynamic, skipUnreachable) and CaveBot.getLureSettings()#

How many monsters must follow before moving on (creaturesToRun), whether dynamic lure is on (dynamicLure) and whether unreachable creatures are skipped (skipUnreachableCreatures, default true). getLureSettings returns the table with these three fields.

lua
CaveBot.setLureSettings(3, false, true)
print(CaveBot.getLureSettings().creaturesToRun)

CaveBot.setSafetyLureSettings(distance, count, trap) and CaveBot.getSafetyLureSettings()#

Lure safety: nearCreatureDistance, nearCreatureCount and avoidStuckTrapCount.

lua
CaveBot.setSafetyLureSettings(1, 4, 3)

CaveBot.setEndLureSettings(...) and CaveBot.getEndLureSettings()#

End Lure rules, in this order: creaturesToStop, creaturesToLeave, tryWalkToCenter, creaturesToLeaveByHp, creaturesToLeaveByHpValue, creaturesToLeaveByHpCount, dontLeaveIfHp, dontLeaveIfHpValue, dontLeaveIfHpCount. getEndLureSettings returns a table with these names.

lua
CaveBot.setEndLureSettings(5, 1)
print(CaveBot.getEndLureSettings().creaturesToStop)

CaveBot.setLureIgnoreList(names)#

List of monster names the lure ignores.

lua
CaveBot.setLureIgnoreList({ "Rat", "Cave Rat" })

Special areas#

CaveBot.addSpecialArea(x, y, z, type, width, height, fromWp, toWp)#

→ boolean

Creates a rectangular area starting at x, y, z. type is Enums.SpecialAreaType: 0 both things, 1 the CaveBot does not walk through it, 2 Targeting ignores the monsters in it. fromWp and toWp (optional) limit the area to a stretch of the route. Returns false with width or height 0 or an invalid type.

lua
CaveBot.addSpecialArea(32000, 32000, 7, Enums.SpecialAreaType.SPECIAL_AREA_CAVEBOT, 5, 3)

CaveBot.deleteSpecialArea(index) and CaveBot.clearSpecialAreas()#

Deletes one area (false if the index does not exist) or all of them.

lua
CaveBot.clearSpecialAreas()

Sell, refill and recording#

FunctionWhat it does
CaveBot.getSellList() / CaveBot.setSellList(ids)List of item ids to sell
CaveBot.getRefillList() / CaveBot.setRefillList(text)Refill list, as text
CaveBot.setAutoRecorderSettings(step, type)Auto recording: tiles between waypoints (default 3) and type (0 Stand, other Node)
CaveBot.enableAutoRecorder(enable)Turns auto recording on or off; false if the recorder is not available
lua
CaveBot.setSellList({ 3357, 3359 })
CaveBot.enableAutoRecorder(true)