Examples
Save as .lua next to opusbot.dll, then Load from the Scripts tab (or set lua_scripts=).
Auto-bless
local waitingForBless = false
Timer.new("AutoBless", function()
if not Client.isConnected() then
waitingForBless = false
return
end
local blessState = Player.getBlessingState() or 0
if blessState <= 0 and not waitingForBless then
waitingForBless = true
Game.talk("!bless", Enums.TalkTypes.TALKTYPE_SAY)
elseif blessState > 0 then
waitingForBless = false
end
end, 2000, true)
Death → press Enter (hotkey)
local function OnTextEvent(ev)
if ev.text == "You are dead."
and (ev.channelId or 0) == 0 then
-- Qt key Return; adjust if your client expects a different key
Client.sendHotkey(16777220, 0)
end
end
Game.registerEvent(Game.Events.TEXT_MESSAGE, OnTextEvent)
:::tip Message type
Some scripts also check ev.messageType == Enums.MessageTypes.MESSAGE_EVENT_ADVANCE. Those numbers can differ per client build — matching on text is safer until you calibrate types from the bot log.
:::
Simple vitals HUD
local PANEL_X, PANEL_Y = 24, 120
local PANEL_W, PANEL_H = 220, 90
local panel = HUD.newRect(PANEL_X, PANEL_Y, PANEL_W, PANEL_H, 12, 14, 20, 205)
local title = HUD.new(PANEL_X + 10, PANEL_Y + 8, "STATUS")
title:setColor(90, 190, 255):setFontSize(14)
local lineHp = HUD.new(PANEL_X + 10, PANEL_Y + 34, "")
local lineGold = HUD.new(PANEL_X + 10, PANEL_Y + 54, "")
lineHp:setColor(230, 230, 235)
lineGold:setColor(230, 230, 235)
local last = 0
function onTick()
local now = getTick()
if now - last < 250 then return end
last = now
local hp = Player.getHealthPercent() or 0
local mp = Player.getManaPercent() or 0
local gold = Player.getTotalGoldBalance() or 0
local lat = Client.getLatency() or 0
lineHp:setText(string.format("HP/MP: %d%% / %d%%", hp, mp))
lineGold:setText(string.format("Gold: %s | Ping: %d ms", tostring(gold), lat))
end
Item icon under the panel
local icon = HUD.newItem(24, 220, 0, 32)
local label = HUD.new(64, 228, "Item: …")
local function findAnyItemId()
for s = 1, 10 do
local it = Player.getInventorySlot(s)
if type(it) == "table" and it.id and it.id > 0 then
return it.id
end
end
local conts = Player.getContainers() or {}
for _, cid in ipairs(conts) do
local items = getContainerItems(cid)
if type(items) == "table" then
for _, it in ipairs(items) do
if it.clientId and it.clientId > 0 then
return it.clientId
end
end
end
end
return 0
end
function onTick()
local id = findAnyItemId()
if id > 0 then
icon:setItemId(id):setVisible(true)
label:setText("Item " .. id)
else
icon:setVisible(false)
label:setText("Open a backpack")
end
end
Toggle modules from script
Engine.enableCaveBot(true)
Engine.enableHealing(true)
Engine.enableTargeting(true)
Engine.enableMagicShooter(false)
if Engine.isCaveBotEnabled() then
print("cavebot is on")
end
NPC buy helper
-- After the trade window is open:
if Client.isTradeShopOpen() then
Npc.buy(268, 10) -- example item id + amount
end
Storage (persist data)
Storage.set("lastHunt", "dragons")
Storage.setInt("kills", (Storage.getInt("kills", 0) or 0) + 1)
Storage.save("my_script_store.txt")
-- Storage.load("my_script_store.txt") on startup if needed
Debugging
print("tick " .. tostring(getTick()))
Client.XLog("pos", Player.getPosition())
Logs appear in the bot log (opusbot_run.log / console when log_console=1).