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.
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.
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.
| Parameter | Type | Description |
|---|---|---|
| text | text | What to say |
| mode | number, optional | Enums.TalkTypes (default 1 = say; 2 whisper, 3 yell) |
Game.talk("hi")
Game.talk("exura gran", Enums.TalkTypes.TALKTYPE_SAY)Game.talkChannel(text, channel)#
Game.talkChannel(text, channelId)
Speaks in an open channel.
| Parameter | Type | Description |
|---|---|---|
| text | text | What to say |
| channelId | number | Channel id |
Game.talkChannel("selling 100 SD", 5)Game.talkPrivate(text, name)#
Game.talkPrivate(text, name)
Sends a PM.
| Parameter | Type | Description |
|---|---|---|
| text | text | The message |
| name | text | Player name |
Game.talkPrivate("arrived at the hunt", "Friend Name")Game.openChannel(channelId)#
Game.openChannel(channelId) → true
Asks the server to open a channel.
Game.openChannel(5)Game.getChannelsHistory()#
Game.getChannelsHistory() → list
The channels the bot saw in this session (channel list and open channels), as {id, name}.
for _, c in ipairs(Game.getChannelsHistory()) do print(c.id, c.name) endWalking, turning, attacking#
Game.walk(direction)#
Game.walk(direction)
Takes one step.
| Parameter | Type | Description |
|---|---|---|
| direction | number | Enums.Directions: 0 north, 1 east, 2 south, 3 west, 4 southwest, 5 southeast, 6 northwest, 7 northeast |
Game.walk(Enums.Directions.NORTH)Game.turn(direction)#
Game.turn(direction)
Turns the character without walking: 0 north, 1 east, 2 south, 3 west.
Game.turn(Enums.Directions.SOUTH)Game.attack(creatureId)#
Game.attack(creatureId)
Attacks the creature. With 0, stops attacking.
Game.attack(0) -- stops attackingGame.follow(creatureId)#
Game.follow(creatureId)
Follows the creature.
local friend = Map.getPlayerOnScreen("Friend Name")
if friend then Game.follow(friend:getId()) endItems#
Game.useItem(itemId)#
Game.useItem(itemId)
Uses the item like a hotkey (the server looks for the item in your bags).
Game.useItem(3725) -- eats a brown mushroomGame.useItemWithCreature(itemId, creatureId)#
Game.useItemWithCreature(itemId, creatureId) → true
Uses the item on a creature, like a rune or potion.
Game.useItemWithCreature(3155, Player.getTargetId()) -- 3155 = sudden death runeGame.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.
local p = Player.getPosition()
Game.useItemOnGround(3191, p.x + 2, p.y, p.z) -- 3191 = great fireball runeGame.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.
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).
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.
Game.equipItem(3052) -- life ringGame.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.
if Game.getItemCount(268) < 50 then print("few mana potions") endGame.getInventoryItems()#
Game.getInventoryItems() → list
All items in the equipment and the open containers, summed by id, as {id, count, tier} (tier always 0).
for _, it in ipairs(Game.getInventoryItems()) do print(it.id, it.count) endGame.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.
Game.lootCorpse(32000, 32000, 7)Game.autoLoot()#
Game.autoLoot() → true
Asks the server to quick loot the corpses around you.
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.
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.
Game.writeTextWindow("Hello!")Quests and stash#
Game.requestQuestLog()#
Game.requestQuestLog() → true
Asks for the quest list. The answer arrives in the QUEST_LOG event.
Game.requestQuestLog()Game.requestQuestLines(questId)#
Game.requestQuestLines(questId) → true
Asks for the missions of a quest. The answer arrives in the QUEST_LINES event.
Game.requestQuestLines(1)Game.stashRetrieve(itemId, amount)#
Game.stashRetrieve(itemId, amount) → true
Takes items out of the supply stash.
Game.stashRetrieve(268, 100)Store#
Game.storeOpen()#
Game.storeOpen() → true
Opens the store.
Game.storeOpen()Game.storeRequestOffers(category)#
Game.storeRequestOffers(category) → true
Asks for the offers of a category, by name.
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).
Game.storeBuyOffer(12345)Game.storeGetTibiaCoinsBalance() and Game.storeGetTransferableCoinsBalance()#
→ number
Tibia coins and transferable coins, from the last balance the server sent (0 until then).
print(Game.storeGetTibiaCoinsBalance())Daily reward#
Game.openDailyReward()#
Game.openDailyReward() → true
Opens the daily reward window.
Game.openDailyReward()Game.collectDailyReward(noShrine, choices)#
Game.collectDailyReward(noShrine, choices) → true
Collects the reward.
| Parameter | Type | Description |
|---|---|---|
| noShrine | boolean | true collects at the shrine, false through the reward wall |
| choices | list | Chosen items: {itemId, count} (empty when there is no choice) |
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.
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.
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.
Game.applyImbuement(0, 1, false)Game.applyImbuementOnScroll(imbuementId)#
Game.applyImbuementOnScroll(imbuementId) → true
Opens the window for a scroll and applies the imbuement to it.
Game.applyImbuementOnScroll(1)Game.clearImbuement(slot) and Game.closeImbuementWindow()#
→ true
Clears an imbuement slot and closes the window.
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.
| Function | What 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 |
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.
| Function | Parameters |
|---|---|
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 |
Game.openTaskBoardBounty()
Game.selectTaskBoardBounty(0)
Comments
to comment.