Documentation › Lua
HUD, windows and utilities
This page gathers what is not part of the game itself: drawing on the screen (HUD), windows with buttons (CustomModalWindow), timers (Timer), wait, JSON, sound, hotkeys and Lua's global functions.
HUD#
A HUD is a text or icon drawn over the game screen. It goes away by itself when the script stops.
HUD.new(x, y, value)#
HUD.new(x, y, value) → HUD
Creates a HUD at position x, y of the window. With a number value, it draws the icon of the item with that id; with text (or nothing), it draws the text.
local text = HUD.new(20, 60, "Hello")
local icon = HUD.new(20, 90, 268) -- mana potion iconHUD.newSpellIcon(x, y, spellId) and HUD.newOutfit(x, y, outfitId)#
→ HUD
Create a HUD with the icon of a spell or an outfit.
local spell = HUD.newSpellIcon(20, 120, Spells.getIdByWords("exura vita"))HUD methods#
| Method | What it does |
|---|---|
hud:getId() | HUD id (what arrives in HUD_CLICK and HUD_DRAG) |
hud:getPos() | Current position {x, y} |
hud:setPos(x, y) | Moves it |
hud:setText(text) | Changes the text |
hud:setColor(r, g, b) | Text color (0 to 255) |
hud:setFontSize(size) | Font size |
hud:setHorizontalAlignment(a) / hud:setVerticalAlignment(a) | Enums.HorizontalAlign / Enums.VerticalAlign |
hud:setItemId(id) / hud:setSpellIconId(id) | Changes the icon |
hud:setOutfitId(id), hud:setOutfitAddons(a), hud:setOutfitColors(head, body, legs, feet), hud:setOutfitDirection(d), hud:setOutfitMoving(b) | Outfit settings |
hud:setSize(width, height), hud:setScale(v), hud:setOpacity(v), hud:setZIndex(z) | Size, scale, transparency and layer |
hud:setDraggable(b) | Lets you drag it with the mouse (HUD_DRAG event) |
hud:setPhantom(b) | The HUD does not receive clicks |
hud:show() / hud:hide() | Shows / hides |
hud:setCallback(function) | Function called when you click the HUD |
hud:destroy() | Deletes the HUD |
hud:getMargins() | Always {x = 0, y = 0} |
local button = HUD.new(20, 100, "[ Pause ]")
button:setColor(255, 200, 0)
button:setCallback(function()
Engine.enableBot(not Engine.isBotEnabled())
end)CustomModalWindow#
A window with a title, text and buttons, drawn by the bot in the game.
CustomModalWindow.new(title, text)#
→ window
Creates the window. The text loses its line breaks and is cut to at most 54 characters.
| Method | What it does |
|---|---|
window:addButton(text) | Adds a button. Returns its index (0, 1, 2...), or nil after 20 buttons |
window:setCallback(function) | Function called with the index of the clicked button |
window:setCaption(text) / window:setDescription(text) | Changes title and text |
window:getId() | Window id |
window:destroy() | Closes it without a click |
Clicking a button closes the window and fires the CUSTOM_MODAL_WINDOW_BUTTON_CLICK event.
local window = CustomModalWindow.new("Hunt", "Continue the hunt?")
window:addButton("Yes")
window:addButton("No")
window:setCallback(function(button)
if button == 1 then Engine.enableCaveBot(false) end
end)Timer#
Runs a function every so often, on the script's thread. The bot checks timers about every 20 ms.
Timer.new(name, function, ms, start)#
Timer.new(name, function, ms, start) → timer
| Parameter | Type | Description |
|---|---|---|
| name | text | Timer name. A new timer with the same name replaces the old one |
| function | function or text | The function, or the name of a global function |
| ms | number, optional | Interval (default 100) |
| start | boolean, optional | false creates it stopped (default: starts right away) |
| Method | What it does |
|---|---|
timer:start() / timer:stop() | Starts / stops |
timer:isActive() | Whether it is running |
timer:update(ms) | Schedules the next run ms from now (without ms, the normal interval) |
timer:run() | Runs the function now |
timer:name() | Timer name |
destroyTimer(name) deletes the timer and returns true if it existed.
Timer.new("cap", function()
if Player.getCapacity() / 100 < 50 then Client.showMessage("Low cap") end
end, 5000)wait(ms)#
wait(ms)
Pauses the script for ms milliseconds. Unlike ZeroBot, the script's events and timers keep running during the wait. A negative time gives an error.
Game.talk("hi")
wait(800)
Game.talk("trade")JSON#
| Function | What it does |
|---|---|
JSON.encode(value) | Table (or number, text, boolean) to JSON text |
JSON.decode(text) | JSON text to table. Gives an error if it does not get a text |
local t = JSON.decode('{"hp": 50}')
print(t.hp, JSON.encode({ 1, 2, 3 }))Sound#
Sound.play(file, default)#
Sound.play(file, default) → boolean
Plays a .wav without blocking the script. A relative path starts at scripts/; with default = true, it starts at scripts/sounds/. Returns false if the file does not exist.
Sound.play("alarm.wav", true) -- scripts/sounds/alarm.wavHotkeyManager#
HotkeyManager.parseKeyCombination(text)#
→ ok, modifiers, key
Converts a shortcut such as "Ctrl+Shift+F5" into the key code and the Enums.FlagModifiers mask. Accepts ctrl/control, alt, shift, numlock, letters, numbers, num0–num9, f1–f24 and names such as space, enter, esc, home, pageup, left, delete. Returns false, nil, nil for an invalid shortcut.
HotkeyManager.keyMapping is the name → code table used in the conversion.
local ok, mods, key = HotkeyManager.parseKeyCombination("Alt+2")
if ok then print(key, mods) end -- 50 2Lua and files#
| Function | What it does |
|---|---|
print(...) | Writes to the Console as [script name] text |
require(name) | Loads scripts/<name>.lua or scripts/<name>/init.lua. package.path starts at the scripts/ folder, and you can add folders |
dofile(path) | Runs the file. Returns true, or nil and the error (does not bring down the script) |
loadfile(path) | Loads the file without running it. Returns the function, or nil and the error |
bit.band, bit.bor, bit.bxor, bit.bnot, bit.lshift, bit.rshift, bit.arshift, bit.rol, bit.ror, bit.bswap, bit.tobit, bit.tohex | Bit operations as in LuaJIT (signed 32-bit) |
unpack, loadstring, table.getn, math.pow, math.mod | Lua 5.1 names, for old scripts |
Relative paths in dofile and loadfile start at scripts/.
local util = require("lib/util") -- scripts/lib/util.lua
Comments
to comment.