Documentation › Lua

Game

The Game module performs your character's actions: speaking, walking, attacking, using and equipping items, answering windows. It also has the game systems: quests, stash, store, daily reward, forge, imbuements, hunting tasks and task board. Events (Game.registerEvent) are in Game events.

Events#

Game.registerEvent(event, function)#

Game.registerEvent(event, function) → function

Binds the function to an event from Game.Events. Returns the function itself, so you can keep it and unbind it later.

lua
Game.registerEvent(Game.Events.TALK, function(name, level, mode, x, y, z, text) print(text) end)

Game.unregisterEvent(event, function)#

Game.unregisterEvent(event, function) → function

Unbinds the function from the event.

lua
local f = Game.registerEvent(Game.Events.ALARM, print)
Game.unregisterEvent(Game.Events.ALARM, f)

Speaking and channels#

Game.talk(text, mode)#

Game.talk(text, mode)

Speaks in Default. Spells are spoken this way too.

ParameterTypeDescription
texttextWhat to say
modenumber, optionalEnums.TalkTypes (default 1 = say; 2 whisper, 3 yell)
lua
Game.talk("hi")
Game.talk("exura gran", Enums.TalkTypes.TALKTYPE_SAY)

Game.talkChannel(text, channel)#

Game.talkChannel(text, channelId)

Speaks in an open channel.

ParameterTypeDescription
texttextWhat to say
channelIdnumberChannel id
lua
Game.talkChannel("selling 100 SD", 5)

Game.talkPrivate(text, name)#

Game.talkPrivate(text, name)

Sends a PM.

ParameterTypeDescription
texttextThe message
nametextPlayer name
lua
Game.talkPrivate("arrived at the hunt", "Friend Name")

Game.openChannel(channelId)#

Game.openChannel(channelId) → true

Asks the server to open a channel.

lua
Game.openChannel(5)

Game.getChannelsHistory()#

Game.getChannelsHistory() → list

The channels the bot saw in this session (channel list and open channels), as {id, name}.

lua
for _, c in ipairs(Game.getChannelsHistory()) do print(c.id, c.name) end

Walking, turning, attacking#

Game.walk(direction)#

Game.walk(direction)

Takes one step.

ParameterTypeDescription
directionnumberEnums.Directions: 0 north, 1 east, 2 south, 3 west, 4 southwest, 5 southeast, 6 northwest, 7 northeast
lua
Game.walk(Enums.Directions.NORTH)

Game.turn(direction)#

Game.turn(direction)

Turns the character without walking: 0 north, 1 east, 2 south, 3 west.

lua
Game.turn(Enums.Directions.SOUTH)

Game.attack(creatureId)#

Game.attack(creatureId)

Attacks the creature. With 0, stops attacking.

lua
Game.attack(0) -- stops attacking

Game.follow(creatureId)#

Game.follow(creatureId)

Follows the creature.

lua
local friend = Map.getPlayerOnScreen("Friend Name")
if friend then Game.follow(friend:getId()) end

Items#

Game.useItem(itemId)#

Game.useItem(itemId)

Uses the item like a hotkey (the server looks for the item in your bags).

lua
Game.useItem(3725) -- eats a brown mushroom

Game.useItemWithCreature(itemId, creatureId)#

Game.useItemWithCreature(itemId, creatureId) → true

Uses the item on a creature, like a rune or potion.

lua
Game.useItemWithCreature(3155, Player.getTargetId()) -- 3155 = sudden death rune

Game.useItemOnGround(itemId, x, y, z)#

Game.useItemOnGround(itemId, x, y, z) → boolean

Uses the item on a tile (area rune, shovel, rope). Returns whether the request went out.

lua
local p = Player.getPosition()
Game.useItemOnGround(3191, p.x + 2, p.y, p.z) -- 3191 = great fireball rune

Game.useItemOnInventory(itemId, slot)#

Game.useItemOnInventory(itemId, slot) → boolean

Uses the item on the item in an equipment slot. Returns false when the slot is empty.

lua
Game.useItemOnInventory(5908, Enums.InventorySlot.CONST_SLOT_LEFT)

Game.useItemFromGround(x, y, z)#

Game.useItemFromGround(x, y, z) → boolean

Uses the top item of a tile (lever, door, ladder).

lua
Game.useItemFromGround(32369, 32241, 7)

Game.equipItem(itemId, tier)#

Game.equipItem(itemId, tier)

Equips the item like the client's equip hotkey: the server finds the item and puts it in the right slot, or takes it off if it is already equipped. tier is accepted but ignored.

lua
Game.equipItem(3052) -- life ring

Game.getItemCount(itemId, tier)#

Game.getItemCount(itemId, tier) → number

How many of this item you have in the equipment and the open containers. tier is accepted but ignored.

lua
if Game.getItemCount(268) < 50 then print("few mana potions") end

Game.getInventoryItems()#

Game.getInventoryItems() → list

All items in the equipment and the open containers, summed by id, as {id, count, tier} (tier always 0).

lua
for _, it in ipairs(Game.getInventoryItems()) do print(it.id, it.count) end

Game.lootCorpse(x, y, z)#

Game.lootCorpse(x, y, z) → boolean

Quick loot on the top item of the tile. Returns false if the tile is not known.

lua
Game.lootCorpse(32000, 32000, 7)

Game.autoLoot()#

Game.autoLoot() → true

Asks the server to quick loot the corpses around you.

lua
Game.autoLoot()

Windows and texts#

Game.modalWindowAnswer(id, button, choice, close)#

Game.modalWindowAnswer(windowId, buttonId, choiceId) → true

Answers a server window (MODAL_WINDOW event). choiceId is optional (default 0). ZeroBot's fourth parameter (closeAfterAnswer) is accepted but ignored.

lua
Game.modalWindowAnswer(window.id, window.buttons[1].id, 0)

Game.writeTextWindow(text)#

Game.writeTextWindow(text) → true or nil

Writes the text in the last text window the server opened (letter, book). Returns nil if none was opened.

lua
Game.writeTextWindow("Hello!")

Quests and stash#

Game.requestQuestLog()#

Game.requestQuestLog() → true

Asks for the quest list. The answer arrives in the QUEST_LOG event.

lua
Game.requestQuestLog()

Game.requestQuestLines(questId)#

Game.requestQuestLines(questId) → true

Asks for the missions of a quest. The answer arrives in the QUEST_LINES event.

lua
Game.requestQuestLines(1)

Game.stashRetrieve(itemId, amount)#

Game.stashRetrieve(itemId, amount) → true

Takes items out of the supply stash.

lua
Game.stashRetrieve(268, 100)

Store#

Game.storeOpen()#

Game.storeOpen() → true

Opens the store.

lua
Game.storeOpen()

Game.storeRequestOffers(category)#

Game.storeRequestOffers(category) → true

Asks for the offers of a category, by name.

lua
Game.storeRequestOffers("Useful Things")

Game.storeBuyOffer(offerId)#

Game.storeBuyOffer(offerId) → true

Buys an offer. Every offer goes out as a simple purchase (hirelings, which need a name, do not work).

lua
Game.storeBuyOffer(12345)

Game.storeGetTibiaCoinsBalance() and Game.storeGetTransferableCoinsBalance()#

→ number

Tibia coins and transferable coins, from the last balance the server sent (0 until then).

lua
print(Game.storeGetTibiaCoinsBalance())

Daily reward#

Game.openDailyReward()#

Game.openDailyReward() → true

Opens the daily reward window.

lua
Game.openDailyReward()

Game.collectDailyReward(noShrine, choices)#

Game.collectDailyReward(noShrine, choices) → true

Collects the reward.

ParameterTypeDescription
noShrinebooleantrue collects at the shrine, false through the reward wall
choiceslistChosen items: {itemId, count} (empty when there is no choice)
lua
Game.collectDailyReward(true, {})

Forge#

Game.forgeConvertDust(), Game.forgeConvertSlivers() and Game.forgeIncreaseLimit()#

→ true

Converts dust into slivers, slivers into exalted core, and raises the dust limit.

lua
Game.forgeConvertDust()

Game.forgeFuseItems(itemId, tier, otherId, otherTier, convergence)#

Game.forgeFuseItems(itemId, tier, otherItemId, otherTier, convergence) → true or nil

Fuses two items. Both must have the same tier; if they do not, it returns nil and nothing is sent.

lua
Game.forgeFuseItems(3079, 1, 3079, 1, false)

Imbuements#

Game.applyImbuement(slot, imbuementId, protection)#

Game.applyImbuement(slot, imbuementId, useProtection) → true

Applies an imbuement to a slot of the item open in the imbuement window.

lua
Game.applyImbuement(0, 1, false)

Game.applyImbuementOnScroll(imbuementId)#

Game.applyImbuementOnScroll(imbuementId) → true

Opens the window for a scroll and applies the imbuement to it.

lua
Game.applyImbuementOnScroll(1)

Game.clearImbuement(slot) and Game.closeImbuementWindow()#

→ true

Clears an imbuement slot and closes the window.

lua
Game.clearImbuement(0)
Game.closeImbuementWindow()

To open the window on an item, use Inventory.pickItemImbuement(slot) or container:pickItemImbuement(slot). The IMBUEMENT_DATA and IMBUEMENT_OPEN_WINDOW events do not fire yet.

Hunting tasks#

All of them take the task slot (0, 1 or 2) and return true.

FunctionWhat it does
Game.huntingTaskRerollList(slot)Rerolls the monster list
Game.huntingTaskRerollRewards(slot)Rerolls the rewards
Game.huntingTaskListAllMonsters(slot)Asks for the list with all monsters
Game.huntingTaskSelectMonster(slot, raceId, maximum)Picks the monster; maximum (default true) takes the larger amount
Game.huntingTaskCancel(slot)Cancels the task
Game.huntingTaskClaim(slot)Claims the reward
lua
Game.huntingTaskSelectMonster(0, 1234, true)

Task board#

For 15.20 or newer servers. Game.taskBoardAction(action, a, b) sends an action from Enums.TaskBoardAction; the functions below are shortcuts for it and raise an error if you pass the wrong number of parameters. All of them return true. The TASK_BOARD_DATA event does not fire yet.

FunctionParameters
Game.openTaskBoardBounty() / Game.openTaskBoardWeekly() / Game.openTaskBoardShop()none
Game.rerollTaskBoardBounties() / Game.claimTaskBoardDailyReroll()none
Game.claimTaskBoardBountyReward() / Game.unlockTaskBoardPreferenceSlot()none
Game.setTaskBoardBountyDifficulty(d) / Game.setTaskBoardWeeklyDifficulty(d)1
Game.selectTaskBoardBounty(i) / Game.upgradeTaskBoardTalisman(i) / Game.deliverTaskBoardWeekly(i)1
Game.buyTaskBoardOffer(id) / Game.clearTaskBoardPreferred(id) / Game.clearTaskBoardUnwanted(id)1
Game.assignTaskBoardPreferred(a, b) / Game.assignTaskBoardUnwanted(a, b)2
lua
Game.openTaskBoardBounty()
Game.selectTaskBoardBounty(0)