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.

lua
if not Client.isConnected() then return end

Client.logout()#

→ true

Asks the server for a logout, like the client's Logout button.

lua
if Player.getStamina() < 14 * 60 then Client.logout() end

Client.XLog()#

→ true

Drops the connection right away, without asking for a logout.

lua
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.

lua
Client.login(nil, nil, 2) -- second character in the list

Game window#

FunctionWhat 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.

lua
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.

lua
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.

lua
local p = Client.getCursorMapPosition()
if p then print(p.x, p.y, p.z) end

Client.getMapIndexes()#

→ {x, y}

Origin (corner) of the map the client has loaded.

lua
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.

lua
if Client.isChatEnabled() then Client.toggleChatEnabled() end

Keyboard#

Client.isKeyPressed(key, modifiers)#

→ boolean

Whether the key is pressed right now. With modifiers, it also requires exactly that mask (Enums.FlagModifiers).

lua
if Client.isKeyPressed(0x20) then print("space pressed") end

Client.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.

lua
local ok, mods, key = HotkeyManager.parseKeyCombination("F1")
Client.sendHotkey(key, mods)

Fight modes#

FunctionWhat 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
lua
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 "".

lua
Client.setLootBlackWhitelist(1, JSON.encode({ type = 1, items = { 3031, 3035 } }))

Client data#

FunctionReturns
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
lua
local m = Client.getMonsterByRaceId(1)
if m then print(m.name, m.isBoss) end

Functions with a fixed value#

They exist so ZeroBot scripts do not break, but DrenoxBot does not measure these values yet:

FunctionAlways returns
Client.getLatency()-1
Client.getServerLatency()0
Client.getFps()0
Client.getWorldName()""
lua
print(Client.getLatency()) -- -1