Documentation › Lua
Client
The Client module works with the game client: the window, the keyboard, on-screen messages, login and logout, fight modes and static data (items and monsters).
Connection#
Client.isConnected()#
→ boolean
Whether you are inside the game.
if not Client.isConnected() then return endClient.logout()#
→ true
Asks the server for a logout, like the client's Logout button.
if Player.getStamina() < 14 * 60 then Client.logout() endClient.XLog()#
→ true
Drops the connection right away, without asking for a logout.
Client.XLog()Client.login(account, password, character)#
→ true
Logs out (if logged in), presses Enter on the login screen and picks the character from the list by position (character, starting at 1). The account and password are not typed: keep the account saved in the client. The first two parameters exist only for compatibility.
Client.login(nil, nil, 2) -- second character in the listGame window#
| Function | What it does |
|---|---|
Client.focus() | Brings the client window to the front |
Client.flashWindow() | Flashes the window in the taskbar |
Client.setWindowTitle(text) | Changes the window title |
Client.showMessage(text) | Shows the text in the middle of the game screen for 3 s |
All of them (except showMessage) return false if the bot cannot find the client window.
Client.setWindowTitle("Hunt: rotworm")
Client.showMessage("Refill in 5 min")Client.getGameWindowDimensions()#
→ {x, y, width, height}
Position and size of the map area in the window. All 0 until the bot's in-game interface reports them.
local g = Client.getGameWindowDimensions()
local hud = HUD.new(g.x + g.width - 120, g.y + 10, "corner")Client.getCursorMapPosition()#
→ {x, y, z} or nil
The map tile under the mouse. nil if the mouse is not on the map or the interface has not reported it yet.
local p = Client.getCursorMapPosition()
if p then print(p.x, p.y, p.z) endClient.getMapIndexes()#
→ {x, y}
Origin (corner) of the map the client has loaded.
print(Client.getMapIndexes().x)Client.isChatEnabled() and Client.toggleChatEnabled()#
→ boolean or nil
Whether chat is on (typing mode), and switches the state. toggleChatEnabled returns the new state. Both return nil until the interface reports it.
if Client.isChatEnabled() then Client.toggleChatEnabled() endKeyboard#
Client.isKeyPressed(key, modifiers)#
→ boolean
Whether the key is pressed right now. With modifiers, it also requires exactly that mask (Enums.FlagModifiers).
if Client.isKeyPressed(0x20) then print("space pressed") endClient.sendHotkey(key, modifiers)#
→ boolean
Presses a key in the client. Without modifiers, the key goes straight to the window, even in the background. With Ctrl, Alt or Shift, the bot brings the client to the front and really types it.
local ok, mods, key = HotkeyManager.parseKeyCombination("F1")
Client.sendHotkey(key, mods)Fight modes#
| Function | What it does |
|---|---|
Client.getFightMode() / Client.setFightMode(mode) | Enums.FightMode: 1 attack, 2 balanced, 3 defense. On clients 15.25 or newer, which have no fight mode, setFightMode changes nothing |
Client.getChaseMode() / Client.setChaseMode(mode) | Enums.ChaseMode: 0 stand, 1 chase |
Client.setChaseMode(Enums.ChaseMode.CHASE)Loot#
Client.getLootBlackWhitelist(id) and Client.setLootBlackWhitelist(id, json)#
The list is a JSON text: {"type": 0 or 1, "items": [ids]} (0 = ignore the items, 1 = accept only them). set sends the quick loot filter to the server and stores the text; get returns what was stored under that id in this session, or "".
Client.setLootBlackWhitelist(1, JSON.encode({ type = 1, items = { 3031, 3035 } }))Client data#
| Function | Returns |
|---|---|
Client.getVersion() | Protocol version, such as "15.23" |
Client.isTradeShopOpen() | Whether the NPC trade window is open |
Client.getAllItems() | Every item, as {id, flags} (bits of Enums.ThingFlagAttr) |
Client.getAllMonsters() | Every monster in the client: {raceId, name, isBoss, outfit} |
Client.getMonsterByRaceId(raceId) | One monster, or nil |
local m = Client.getMonsterByRaceId(1)
if m then print(m.name, m.isBoss) endFunctions with a fixed value#
They exist so ZeroBot scripts do not break, but DrenoxBot does not measure these values yet:
| Function | Always returns |
|---|---|
Client.getLatency() | -1 |
Client.getServerLatency() | 0 |
Client.getFps() | 0 |
Client.getWorldName() | "" |
print(Client.getLatency()) -- -1
Comments
to comment.