Called before equipment changes are processed. This function is mandatory to
implement in your bot script. You should handle here any logic that needs to be executed before
equipment changes take place.
Example implementation:
function handle_equip_change_before()
if get_waypoint_mode()~=0 then
return true --do not change amulet/rings if is not in hunt mode
end
return false
end
handle_new_status(newstatus)
Called after status changes. You should handle here any logic that needs to be
executed after the status changes take place, newstatus can be: "Idle", "Attacking", "Walking".
Example implementation:
function handle_new_status(status)
if status == "Idle"
send_keyboard("KEY_F1")
end
return false
end
main_handle()
Main handling function that's called regularly.
Example implementation:
function main_handle()
local xbl, ybl = last_battlelist_position()
if xbl == 0 or ybl == 0 then
return false -- if there is no battlelist, returns false to skip execution
end
return false -- returns false to work normal
end
wpt_before() and wpt_after()
Called before clicking on each waypoint. / Called after reaching the waypoint
Example implementation:
function wpt_before()
return false
end
function wpt_after()
return false
end
Returns: boolean - true to skip waypoint action,
false to proceed
Movement & Navigation
goto_refill(value)
Forces the bot to enter refill mode and return to town.
Parameters:
• value: boolean - Whether to force refill mode
Returns: void
get_walk_mode() / set_walk_mode(value)
Forces the bot to change its walk mode, values can be:
WALK_MODE_KEYBOARD = 0
WALK_MODE_MAPCLICK = 1
WALK_MODE_WINDOWCLICK = 2
Parameters:
• value: number - The walk mode to set
Returns: void
try_go_to_wpt(mode,index)
Bot will try to go to the specified waypoint index in the given mode:
Mode can be:
0 - Hunt Mode
1 - Refill Mode
2 - To Hunt Mode
3 - To Logout Mode
4 - Login To Go Hunt Mode
Parameters:
• mode: number - The mode to use for navigation (0-4)
• index: number - The waypoint index to navigate to
Returns: void
get_waypoint_index() / set_waypoint_index(x)
Get or set the current waypoint index.
Parameters for set:
• x: number - The index to set as current waypoint
Returns for get: number - Current waypoint index
get_waypoint_mode() / set_waypoint_mode(x)
Get or set current waypoint mode.
Parameters for set:
• x: number - The mode to set (0: hunt, 1: refill, 2: to-hunt, 3:
to-logout)
Returns for get: number - Current mode (0-3)
current_wpt()
Gets information about the current waypoint, including its position, dimensions,
and various action properties.
Returns: table with the following fields:
Required fields:
• x, y, z: number - Waypoint coordinates
• vX, vY, vZ: number - Waypoint vectors
• vL, vR, vT, vB: number - Waypoint boundaries (Left, Right, Top,
Bottom)
• radius: number - Waypoint radius
• minimumWaitTime: number - Minimum time to wait at waypoint
• luafunc: string - Lua function associated with waypoint
Optional fields:
• title: string - Waypoint title/description
• pausebot: boolean - Whether to pause bot at this waypoint
• lure: boolean - Whether this is a lure waypoint
• hotkey: string - Hotkey to press at waypoint
• click: string - Mouse click action to perform
• windowClick_X: number - X coordinate for window click
• windowClick_Y: number - Y coordinate for window click
• ladder_direction: string - Direction for ladder interaction
• nowait: boolean - Whether to skip waiting at waypoint
• chat_spell: string - Spell/text to say in chat
• facing_direction: string - Direction character should face
Example usage:
local wpt = current_wpt()
if wpt.pausebot then
close_tibia()
end
get_char_pos()
Gets the current character position.
Returns: table - [x, y, z] coordinates of character
is_pos_found()
Checks if the character's position has been successfully detected.
Returns: boolean - true if position is found, false
otherwise
Parameters:
• icon_name: string - The item icon to locate
• filter: string - Filter text for finding correct item
• amount: number - Quantity to purchase
• complete_buy: boolean - Whether to complete the purchase
immediately
Returns: boolean - true if successful
do_npc_sellall()
Sells all eligible items to the NPC.
Returns: boolean - true if successful
dodepositall()
Deposits all items in the NPC bank.
Returns: void
get_potion_mana() / get_potion_hp()
Get current number of mana or health potions.
Returns: number - Current quantity of potions
do_drag_drop(x_ori, y_ori, x_dest, y_dest, reset)
Performs drag and drop operation.
Parameters:
• x_ori: number - Starting X coordinate
• y_ori: number - Starting Y coordinate
• x_dest: number - Destination X coordinate
• y_dest: number - Destination Y coordinate
• reset: boolean - Whether to reset mouse position after operation
Returns: boolean - true if successful
try_drop_vial()
Attempts to drop empty vials when conditions are met.
Returns: void
trydorefillpot()
Single attempt to refill potions from NPC.
Returns: boolean - true if successful
dorefillpot()
Multiple attempts to refill potions with retry logic.
Ask the bot to use the new ring/amulet.
Allowed values for Amulets: "Foxtail", "Turtle", "Red Plasma", "Gill", "Glacier", "Magma", "Lightning",
Terra"
Allowed values for Rings: "Dwarven", "Sword", "Club", "Axe", "Red Plasma", "Prismatic", "Stealth",
"Spiritthorn"
Returns: void
UI & Interface
checkscreen()
Check if the screen is missing something, it will print on the lua console whats
not found and save a screenshot under ./tmp/clientwindow.png with the found details.
Returns: void
set_ignore_first_x_pm_tabs(value:number)
Set the amount of tabs that will be ignored when checking for pm messages,
default value is 4.
Returns: void
last_battlelist_position()
Gets the position of the last found creature in the battle list on screen.
Returns: tuple - (x, y) screen coordinates of battle
list position. Returns (0,0) if no battle list is found
has_player_on_screen()
Checks if other players are visible on the screen. This function is used in
conjunction with player detection systems and anti-PK features.
Example usage:
if has_player_on_screen() then
printwebln("Warning: Player detected!")
screenshot_telegram("Player on screen")
-- Add your safety measures here
end
Returns: boolean - true if other players are detected
on screen, false otherwise
Related functions:
• notify_player_on_screen - Global variable to enable/disable notifications
send_keyboard(command)
Sends a keyboard command to the game client.
Parameters:
• command: string - Keyboard command to send
Returns: boolean - true if successful
send_keyboard_before_potion(command)
Sends a keyboard command to the game client before using pot.
Parameters:
• command: string - Keyboard command to send
Prints message to web console, with or without line break.
Parameters:
• message: string - Message to display
Returns: void
sendserial(command)
Sends a serial command and logs it to web console.
Parameters:
• command: string - Command to send
Returns: void
screenshot_telegram(command)
Sends a screenshot to Telegram with a command message.
Parameters:
• command: string - Message to send with screenshot
Returns: void
Note: Can only be used once every 30 seconds
handle_pending_command()
Processes any pending commands from the web interface.
Returns: void
locate(icon)
Locates an image on the screen.
Parameters:
• icon: string - Name of the icon to locate
Returns: tuple - (x, y, confidence, centerx, centery)
click_at(x, y, button, reset)
Performs mouse click at specified coordinates.
Parameters:
• x: number - X coordinate
• y: number - Y coordinate
• button: number - Mouse button (1: left, 2: right)
• reset: boolean - Whether to reset mouse position after click
Returns: boolean - true if successful
mousedown(x, y, button) / mouseup(x, y, button)
Controls individual mouse button press and release actions.
Parameters:
• x: number - X coordinate
• y: number - Y coordinate
• button: number - Mouse button (1: left, 2: right)
Returns: boolean - true if successful
send_keyboard_down(key) / send_keyboard_up(key)
Sends a keyboard key down or up event.
Parameters:
• key: string - Key to press or release (e.g., KEY_F1, KEY_F2...)
list of all keys at the end
Returns: boolean - true if successful
mousemove(x, y)
Moves the mouse cursor to the specified coordinates.
Parameters:
• x: number - X coordinate
• y: number - Y coordinate
Returns: boolean - true if successful
Timer Functions
reset_exit_time(timetoexit)
Resets the exit timer with a new duration.
Parameters:
• timetoexit: string - Time in format "HH:MM:SS"
Returns: void
timeToMilliseconds(timeStr)
Converts time string to milliseconds.
Parameters:
• timeStr: string - Time in format "HH:MM:SS"
Returns: number - Time in milliseconds
Global Variables
drop_empty_vials_min, drop_empty_vials_max
Minimum and maximum time intervals between vial dropping attempts.
Type: number (default: 5000, 12000 milliseconds)
drop_empty_vials_min_cap
Minimum capacity threshold for dropping empty vials.
Type: number (default: 500)
exit_timer, ms_exit_timer
Time until bot exits hunt and absolute millisecond timestamp for exit.
Type: string (format: "HH:MM:SS") and number
player_detection_start, cumulative_player_time
Timestamps for player detection system.
Type: number (milliseconds)
mana_to_buy, hp_to_buy
Amount of mana and health potions to maintain during refill.
Type: number
exit_hunt_timer_playeronscreen
Time in milliseconds before exiting hunt when player is detected.
Type: number (default: 15000)
health_potion, mana_potion
Type of potions to use for healing and mana.
Type: string (default: "supreme h", "strong m")
notify_player_on_screen
Whether to enable player detection notifications.
Type: boolean (default: true)
CITY_COORDINATES
Table containing coordinates for all cities.
Type: table - Contains city names and their
coordinates
Overwritable Functions
cast_utito()
If you want to change it, set it up inside the script
Original code:
function cast_utito()
local last_utito = get_last_utito()
local last_support_spell = get_last_support_spell()
local is_paralyzed, is_utito, is_hungry, is_hasted = is_paralyzed_utited_hungry_hasted()
if (not is_utito or (last_utito.as_millis() > 9700))
and (last_support_spell.as_millis() > 2000)
and get_creatures_battlelist().len() > 0
then
cast("utito_tempo")
end
end
Parameters:
Returns: void
Utility Functions
set_read_party_list(BOOL)
If set to true will set the bot to start reading the party list, if false,
will ignore and improve performance, default value is false
Parameters:
Returns: void
get_last_utito()
Return the amount of milliseconds since last utito.
Parameters: None
get_last_support_spell()
Return the amount of milliseconds since last support spell was used.
Parameters: None
get_partymembers()
Returns a table with vector of (hp,mana), if both are 0, means the player is
far away from the screen
Example implementation:
local members = get_partymembers()
print("Party members:")
for i = 1, #members do
print("Member " .. i .. ": hp=" .. members[i][1] .. ", mana=" .. members[i][2])
end
Parameters: None
Returns: table
last_move_millis()
Returns the amount of milliseconds since character last moved
Returns: number
reset_lastmove()
Resets the lastmove timer.
Returns: void
grid_to_window_pixel(x_offset,y_offset)
Return a pixel coordinate of the game window screen based on the grid
format.
0,0 means center, -1,0, means 1 square to left, -2,-2 means diagonal top left (2 square distance
from 0,0)
Returns: table
set_status() / get_status()
Gets/Sets bot status, allowed values: "Idle", "Attacking", "Walking"
(they
are
all case sensitive).
Returns: string - Current Status: "Idle",
"Attacking", "Walking"
Get or set whether to notify when players are detected on screen.
Parameters for set:
• value: boolean - true to enable notifications, false to
disable
Returns for get: boolean - Current
notification
state
send_telegram(message)
Sends a message to the configured Telegram, only one message can be sent
every minute to avoid spam.
Parameters:
• message: string - Message to send
Returns: void
locate_on_battlelist(icon_name)
Attempts to locate a image on the battle list.
Parameters:
• icon_name: string - Name of the icon to locate
Returns: (x, y, confidence, center_x,
center_y)
sleep(duration_millis)
Pauses execution for specified duration.
Parameters:
• duration_millis: number - Duration in milliseconds
Returns: boolean - true if successful
sleep_with_healattack(duration_millis)
Pauses execution for specified duration but will still cast healling and
attackign spells while waiting.
Parameters:
• duration_millis: number - Duration in milliseconds
Returns: void
goto_next_wpt()
Will try to go to the next waypoint ignoring creatures and current state.
Returns: void
checkscreen()
Alerts you on telegram in case there is missing some mandatore objects on
screen,
like Battlelist, Battlelist Players and some backpacks.
Returns: void
get_millis()
Gets current system time in milliseconds.
Returns: number - Current time in
milliseconds
release_pressed_keys()
Releases all pressed keyboard keys.
Returns: void
current_fps()
Gets the current frames per second being processed.
Returns: number - Current FPS
exit_client()
Exits the client application.
Returns: void
is_paused() / set_is_bot_paused(val)
Gets or sets the bot's pause state.
Parameters for set:
• val: boolean - Pause state to set
Returns for get: boolean - Current pause
state
close_tibia()
Will close tibia client and pause the bot.
Returns: void
calculate_distance_creatures()
Calculate the distance considering the pathfinding between you and the
creatures
on screen.
Returns: table it contains the distance
between
you
and all visible creatures on screen.
get_loot_positions()
Return the table containing [x,y,z] of the loots visible on the window.
Returns: table.
is_bestiary_mode()
Checks if the bestiary mode is enabled.
Returns: boolean - True if bestiary mode is
enabled, false otherwise.
set_bestiary_mode(enable)
Enables or disables bestiary mode.
Parameters:
• enable: boolean - true to enable, false to disable
Returns: void
get_creatures_battlelist()
Returns a table containing information about all creatures currently visible in the battle list.
Returns: table - A table of creature objects, each containing:
• creature_hp: number - Current HP of the creature
• priority: number - Priority value of the creature (defined in the script)
• is_with_ampres: boolean - Whether the creature has ampres status
• is_ranged: boolean - Whether the creature is ranged (defined in the script)
• is_exeta: boolean - Whether the creature has exeta (defined in the script)
Example:
local battlelist = get_creatures_battlelist()
print("Battle List (" .. #battlelist .. " creatures):")
print("=" .. string.rep("=", 50))
for i, creature in pairs(battlelist) do
print(string.format("Creature %d: HP=%d, Priority=%d, Ampres=%s, Ranged=%s, Exeta=%s",
i,
creature.creature_hp,
creature.priority,
creature.is_with_ampres and "Yes" or "No",
creature.is_ranged and "Yes" or "No",
creature.is_exeta and "Yes" or "No"
))
end
reset_mouse()
Resets the mouse position so bot knows where the mouse is (in case you
moved
the mouse and want to move it back programatically).
Returns: void
goto_position(x, y, z, r, mwt, lure, nowait)
Create a virtual waypoint.
Parameters:
• x: number - X coordinate
• y: number - Y coordinate
• z: number - Z coordinate
• r: number - Radius for movement
• mwt: number - Minimum wait time
• lure: boolean - Whether its a lure waypoint
• nowait: boolean - Whether is a no wait waypoint