Documentation



isOnline


isOnline ( )

Returns true if yor are currently connected to the game, false otherwise.

g_game.isOnline()

getLocalPlayer


getLocalPlayer ( )

Returns LocalPlayer object if connected to the game, nil otherwise.

g_game.getLocalPlayer()

attack


attack (Creature   creature )

Attacks provided Creature object.

local creature
for v, k in pairs(g_game.getCreatures()) do
  if k:getName() == "Monk" then
    creature = k
    break
  end
end
if not g_game.isAttacking() and creature then 
  g_game.attack(creature)
end

Attack the first found creature with name "Monk".

follow


follow (Creature   creature )

Follows provided Creature object.

local creature
for v, k in pairs(g_game.getCreatures()) do
  if k:getName() == "Monk" then
    creature = k
    break
  end
end
if not g_game.isFollowing() and creature then 
  g_game.follow(creature)
end

Follows the first found creature with name "Monk".

getTalkMessages


getTalkMessages ( )

Returns a table that contains all of the talk messages received until logging in.

g_game.getTalkMessages()

getTextMessages


getTextMessages ( )

Returns a table that contains all of the text messages received until logging in.

g_game.getTextMessages()

lastTalkMessage


lastTalkMessage ( )

Returns the last received talk message.

g_game.lastTalkMessage()

lastTextMessage


lastTextMessage ( )

Returns the last received text message.

g_game.lastTextMessage()

isAttacking


isAttacking ( )

Returns true if currently attacking, false otherwise.

g_game.isAttacking()

getAttackingCreature


getAttackingCreature ( )

Returns currently attacking creature.

g_game.getAttackingCreature()

isFollowing


isFollowing ( )

Returns true if currently following, false otherwise.

g_game.isFollowing()

talk


talk (string   message )

Sends specified message in local chat.

g_game.talk("hello")

talkChannel


talkChannel (number channelId , string message )

Sends the specified message in the specified channelId.

g_game.talkChannel(6, "hello")

talkPrivate


talkPrivate (string receiver , string message )

Sends the specified message to the receiver via whisper.

g_game.talkPrivate("PlayerName", "hello")

setChaseMode


setChaseMode (ChaseMode mode )

Sets chase mode to the specified one.

g_game.setChaseMode(ChaseModes.ChaseOppontent)

Available ChaseModes:

ChaseModes = {
  DontChase = 0,
  ChaseOpponent = 1
}

setFightMode


setFightMode (FightMode mode )

Sets fight mode to the specified one.

g_game.setFightMode(FightModes.FightBalanced)

Available FightModes:

FightModes = {
  FightOffensive = 0,
  FightBalanced = 1,
  FightDefensive = 2
}

setSafeFight


setSafeFight (boolean state )

Sets safe fight mode to specified state.

g_game.setSafeFight(true)

setPVPMode


setPVPMode (PVPMode mode )

Sets PvP mode to the specified one.

g_game.setPVPMode(PVPModes.YellowHand)

Available PVPModes:

PVPModes = {
  WhiteDove = 0,
  WhiteHand = 1,
  YellowHand = 2,
  RedFist = 3
}

turn


turn (Direction direction )

Turns to the specified direction.

g_game.turn(Directions.North)

Available Directions:

Directions = {
  North = 0,
  East = 1,
  South = 2,
  West = 3,
}

stop


stop ( )

Stops character's walking.

g_game.stop()

useMapItem


useMapItem (Position pos )

Uses top use item on specified position.

g_game.useMapItem({x = 123, y = 346, z = 7})

useItem


useItem (Item item )

Uses specified item.

g_game.useItem(item)

use


use (number itemId )

Uses first found item with specified itemId.

g_game.use(3031)

useMapItemOnCreature


useMapItemOnCreature (Position pos , Creature creature, )

Uses top use item from specified position on specified creature.

g_game.useMapItemOnCreature({x = 123, y = 346, z = 7}, g_game.getLocalPlayer():asCreature())

useMapItemOnPosition


useMapItemOnPosition (Position fromPos , Position toPos, )

Uses top use item from specified fromPos on specified toPos.

g_game.useMapItemOnPosition({x = 123, y = 346, z = 7}, g_game.getLocalPlayer():getPosition())

useInventoryItem


useInventoryItem (number itemId )

Uses item with specified itemId (if supported by server will use items even with closed containers).

g_game.useInventoryItem(3031)

useInventoryItemOnCreature


useInventoryItemOnCreature (number itemId , Creature creature )

Uses item with specified itemId (if supported by server will use items even with closed containers) at specified creature.

g_game.useInventoryItemOnCreature(3031, g_game.getAttackingCreature())

useInventoryItemOnPosition


useInventoryItemOnPosition (number itemId , Position position )

Uses item with specified itemId (if supported by server will use items even with closed containers) at specified position.

g_game.useInventoryItemOnPosition(3031, g_game.getAttackingCreature():getPosition())

useItemOnCreature


useItemOnCreature (number itemId , Creature creature )

Uses item with specified itemId at specified creature.

g_game.useItemOnCreature(3031, g_game.getAttackingCreature())

useItemOnPosition


useItemOnPosition (number itemId , Position position )

Uses item with specified itemId at specified position.

g_game.useItemOnPosition(3031, g_game.getAttackingCreature():getPosition())

getBestTurnDirection


getBestTurnDirection ()

Returns direction with most monsters around the LocalPlayer.

g_game.turn(g_game.getBestTurnDirection())

Turns to the direction with most monsters around the LocalPlayer.

getMonstersInFront


getMonstersInFront ()

Returns a table with monsters that are in front of a LocalPlayer.

if #g_game.getMonstersInFront() >= 1 then
  g_game.talk("exevo vis hur")
end

Sends "exevo vis hur" if there is atleast 1 monster in front of LocalPlayer.

getMonstersAround


getMonstersAround (number range )

Returns a table with monsters that are within specified range.

if #g_game.getMonstersAround(4) >= 3 then
  g_game.talk("exevo gran mas vis")
end

Sends "exevo gran mas vis" if there are atleast 3 monsters within 4 sqm distance of LocalPlayer.

getContainers


getContainers ( )

Returns a table containing all open containers.

if #g_game.getContainers() == 0 then
  g_game.forceLogout()
end

Exits to the character list if there are no open containers.

getContainer


getContainer (number containerId )

Returns a container with specified containerId

if g_game.getContainer(1):getName() ~= "backpack" then
  g_game.forceLogout()
end

Exits to the character list if the first open container name isn't "backpack".

getContainersCount


getContainersCount ( )

Returns a count of open containers.

if g_game.getContainersCount() == 0 then
  g_game.forceLogout()
end

Exits to the character list if there are no open containers.

closeAllContainers


closeAllContainers ( )

Closes all open containers.

if g_game.getContainersCount() >= 6 then
  g_game.closeAllContainers()
end

Closes all containers if there are atleast 6 open containers.

reconnect


reconnect ( )

Reconnects to the

if not g_game.isOnline() then
  g_game.reconnect()
  sleep(5000)
end

If not in game then tries to reconnect to the

openItem


openItem (Item containerItem , [newWindow = false] )

Opens the specified container item.

g_game.openItem(containerItem)

openItem


open (number itemId )

Opens the first found item with specified itemId.

g_game.open(1234)

move


(number itemId , Position position , number count )

Moves the first found item with specified itemId and count to the specified position.

g_game.move(1234, {x= 65535, y = 64, 0}, 1)

moveItem


moveItem (Item item , Position position , number count )

Moves the specified item to the specified position.

if not g_game.isOnline() then
  return
end
local items = {}
local containers = g_game.getContainers()
for v, container in pairs(containers) do
  if container:getItemsCount() > 0 then
    local containerItems = container:getItems()
    for j, item in pairs(containerItems) do
      if item:getCount() ~= 100 then
        if not items[item:getId()] then
          items[item:getId()] = {}
        end
        table.insert(items[item:getId()], item)
      end
    end
  end
end

for v, k in pairs(items) do
  if #items[v] > 1 then
    if items[v][2]:isStackable() then
      g_game.moveItem(items[v][2], items[v][1]:getPosition(), items[v][2]:getCount())
      break
    end
  end
end
auto(200)

Stacks items with the same IDs.

stop


getCreatures ( )

Return a table that contains all visible creatures.

g_game.talk(tostring(#g_game.getCreatures()))

Sends the visible creatures count on local chat.

isOnScreen


isOnScreen (string name )

Returns true if creature with provided name is visible.

if g_game.isOnScreen("Wolf") then
  g_game.forceLogout()
end

If "Wolf" is on screen then exit to character list.

getName


getName ()

Returns character's name.

g_game.getLocalPlayer():getName()

getHealth


getHealth ()

Returns character's current health.

g_game.getLocalPlayer():getHealth()

getHealthPercent


getHealthPercent ()

Returns character's current health percent.

g_game.getLocalPlayer():getHealthPercent()

getLevel


getLevel ()

Returns character's level.

g_game.getLocalPlayer():getLevel()

getMagicLevel


getMagicLevel ()

Returns character's magic level.

g_game.getLocalPlayer():getMagicLevel()

getMana


getMana ()

Returns character's current mana.

g_game.getLocalPlayer():getMana()

getManaPercent


getManaPercent ()

Returns character's current mana percent.

g_game.getLocalPlayer():getManaPercent()

getMaxHealth


getMaxHealth ()

Returns character's max health.

g_game.getLocalPlayer():getMaxHealth()

getMaxMana


getMaxMana ()

Returns character's max mana.

g_game.getLocalPlayer():getMaxMana()

getPosition


getPosition ()

Returns character's position.

g_game.getLocalPlayer():getPosition()

getSkill


getSkill (number skillId )

Returns character's skill value from specified skillId.

g_game.getLocalPlayer():getSkill(2)

getSoul


getSoul ()

Returns character's soul.

g_game.getLocalPlayer():getSoul()

getSpeed


getSpeed ()

Returns character's speed.

g_game.getLocalPlayer():getSpeed()

getStates


getStates ()

Returns character's condition states.

g_game.getLocalPlayer():getStates()

hasState


hasState ()

Returns character's condition states.

g_game.getLocalPlayer():hasState(PlayerStates.Haste)

Available states:

PlayerStates = {
  None = 0,
  Poison = 1,
  Burn = 2,
  Energy = 4,
  Drunk = 8,
  ManaShield = 16,
  Paralyze = 32,
  Haste = 64,
  Swords = 128,
  Drowning = 256,
  Freezing = 512,
  Dazzled = 1024,
  Cursed = 2048,
  PartyBuff = 4096,
  PzBlock = 8192,
  Pz = 16384,
  Bleeding = 32768,
  Hungry = 65536
}

getDirection


getDirection ()

Returns character's current facing direction.

g_game.getLocalPlayer():getDirection()

getItemsCount


getItemsCount (number itemId )

Returns character's count of items specified by itemId.

g_game.getLocalPlayer():getItemsCount(3031)

getInventoryItem


getInventoryItem (InventorySlot slot )

Returns character's item in a specified slot.

g_game.getLocalPlayer():getInventoryItem(InventorySlots.Backpack)

Available slots:

InventorySlots = {
  Head = 0,
  Necklace = 1,
  Backpack = 2,
  Armor = 3,
  Right = 4,
  Left = 5,
  Legs = 6,
  Feet = 7,
  Ring = 8,
  Ammo = 9,
}

getItems


getItems ( )

Returns all character's items from the inventory and containers.

g_game.getLocalPlayer():getItems()

getItemsById


getItemsById (number itemId )

Returns all character's items from the inventory and containers with a given itemId.

g_game.getLocalPlayer():getItemsById(3031)

x


Position.x

Returns the "x" coordinate of given Position.

g_game.getLocalPlayer():getPosition().x

y


Position.y

Returns the "y" coordinate of given Position.

g_game.getLocalPlayer():getPosition().y

z


Position.z

Returns the "z" coordinate of given Position.

g_game.getLocalPlayer():getPosition().z

getDistance


Position.getDistance (Position toPos )

Returns distance between Position and toPos.

g_game.getLocalPlayer():getPosition():getDistance({x = 123, y = 456, z = 7})

isInRange


Position.isInRange (Position toPos , number xRange , number yRange )

Returns true if given Position is within xRange and yRange of toPos.

g_game.getLocalPlayer():getPosition():isInRange({x = 123, y = 456, z = 7}, 3, 5)

getHealthPercent


Creature.getHealthPercent ()

Returns current health percent of a given Creature.

g_game.getCreatures()[1]:getHealthPercent()

getId


Creature.getId ()

Returns ID of a given Creature.

g_game.getCreatures()[1]:getId()

getName


Creature.getName ()

Returns name of a given Creature.

g_game.getCreatures()[1]:getName()

getPosition


Creature.getPosition ()

Returns position of a given Creature.

g_game.getCreatures()[1]:getPosition()

getDirection


Creature.getDirection ()

Returns direction of a given Creature.

g_game.getCreatures()[1]:getDirection()

isMonster


Creature.isMonster ()

Returns true if a given Creature is monster, false otherwise.

local monstersOnScreen = 0
for _, creature in pairs(g_game.getCreatures()) do
  if creature:isMonster() then
    monstersOnScreen = monstersOnScreen + 1
  end
end
g_game.talk("Monsters on screen: " .. monstersOnScreen)

Sends the detected amount of monsters in the local chat.

isNpc


Creature.isNpc ()

Returns true if a given Creature is NPC, false otherwise.

local npcOnScreen = 0
for _, creature in pairs(g_game.getCreatures()) do
  if creature:isNpc() then
    npcOnScreen = npcOnScreen + 1
  end
end
g_game.talk("NPCs on screen: " .. npcOnScreen)

Sends the detected amount of NPCs in the local chat.

isPlayer


Creature.isPlayer ()

Returns true if a given Creature is player, false otherwise.

local playersOnScreen = 0
for _, creature in pairs(g_game.getCreatures()) do
  if creature:isPlayer() then
  playersOnScreen = playersOnScreen + 1
  end
end
g_game.talk("Players on screen: " .. playersOnScreen)

Sends the detected amount of players in the local chat.

getSize


Container.getSize ()

Returns size of a given Container.

g_game.getContainer(1):getSize()

getItems


Container.getItems ()

Returns table containing all items of a given Container.

g_game.getContainer(1):getItems()

getSlotPosition


Container.getSlotPosition ()

Returns position of given Container.

g_game.move(1234, g_game.getContainer(1):getSlotPosition())

Moves item with ID of 1234 to the first container's position.

getId


Container.getId ()

Returns id of a given Container.

g_game.getContainer(1):getId()

getCapacity


Container.getCapacity ()

Returns capacity of a given Container.

g_game.getContainer(1):getCapacity()

getName


Container.getName ()

Returns name of a given Container.

g_game.getContainer(1):getName()

getName


Container.hasParent ()

Returns true if a given Container is inside another container, false otherwise.

g_game.getContainer(1):hasParent()

findItemById


Container.findItemById (number itemId )

Returns the first found Item of a given itemId in a given Container.

g_game.useItem(g_game.getContainer(1):findItemById(1234))

Uses item with ID of 1234 from the first open container.

getItemsCount


Container.getItemsCount (number itemId )

Returns the amount of items with a given itemId in a given Container.

if g_game.getContainer(1):getItemsCount(1234) < 100 then
  gotolabel("EXIT", "gototown")
end

If amount of items with ID of 1234 is less than 100 then go to the cavebot section "EXIT" and label "gototown".

getPosition


Item.getPosition ()

Returns position of a given Item.

g_game.getContainer(1):getItems()[1]:getPosition()

getId


Item.getId ()

Returns ID of a given Item.

g_game.getContainer(1):getItems()[1]:getId()

getCount


Item.getCount ()

Returns count of a given Item.

g_game.getContainer(1):getItems()[1]:getCount()

getStackPos


Item.getStackPos ()

Returns stack position of a given Item.

g_game.getContainer(1):getItems()[1]:getStackPos()

isContainer


Item.isContainer ()

Returns true if a given Item is a Container, false otherwise.

g_game.getContainer(1):getItems()[1]:isContainer()

isStackable


Item.isStackable ()

Returns true if a given Item is stackable, false otherwise.

g_game.getContainer(1):getItems()[1]:isStackable()

message


TextMessage.message ()

Returns the message of a given TextMessage.

g_game.lastTextMessage().message

mode


TextMessage.mode ()

Returns the mode of a given TextMessage.

g_game.lastTextMessage().mode

channel


TalkMessage.channel ()

Returns the channelId of a given TalkMessage.

g_game.lastTalkMessage().channel

position


TalkMessage.position ()

Returns the position of a given TalkMessage.

g_game.lastTalkMessage().position

level


TalkMessage.level ()

Returns the level of a given TalkMessage.

g_game.lastTalkMessage().level

message


TalkMessage.message ()

Returns the message of a given TalkMessage.

g_game.lastTalkMessage().message

mode


TalkMessage.mode ()

Returns the mode of a given TalkMessage.

g_game.lastTalkMessage().mode

name


TalkMessage.name ()

Returns the name of a given TalkMessage.

g_game.lastTalkMessage().name

sleep


sleep (number millis , [number millisTo = millis] )

Delays the script of a given millis amout of time in milliseconds. If given a second argument, randomly picks a number between the two provided.

sleep(100, 200)

auto


auto (number millis , [number millisTo = millis] )

Allows the script to run periodically for a given millis amount of time in milliseconds. If given a second argument, randomly picks a number between the two provided.

auto(100, 200)

gotolabel


gotolabel (string sectionName , string labelName )

Sets the current waypoint to the one of labelName Label in sectionName Section.

gotolabel("HUNTING", "start-hunting")

setOption


setOption (string option , string value )

Sets the given option to the given value.

setOption("Cavebot/Enabled", "false")

Disables cavebot.


Available options:

options = {
  "Cavebot/ShovelID", 
  "Cavebot/RopeID", 
  "Cavebot/MacheteID", 
  "Cavebot/PickID",
  "Cavebot/Enabled", 
  "Cavebot/PauseBotOnDeath", 
  "Cavebot/MapWalkDistance", 
  "Cavebot/WalkThroughPlayers",
  "Cavebot/IgnoreNonPathable", 
  "SpellHealer/Enabled", 
  "ItemHealer/Enabled", 
  "ConditionHealer/Enabled",
  "Alerts/Enabled", 
  "Targeting/Enabled", 
  "Targeting/AllowDiagonalMovement", 
  "Targeting/AutoSwitchProfiles",
  "Targeting/NonPvpMode", 
  "Targeting/TargetReachable", 
  "Targeting/TargetShootable", 
  "Looting/Enabled",
  "Looting/LootingRange", 
  "Looting/LootingPolicy", 
  "Looting/EatFoodFromCorpse", 
  "Looting/OpenBPsAtLogin",
  "Looting/OpenNextBP", 
  "Global/BotPaused", 
  "Global/AlwaysOnTop"
}

getOption


getOption (string option )

Gets the given option value.

if getOption("Cavebot/Enabled") == "false" then
  setOption("Cavebot/Enabled", "true")
end

If cavebot is disabled, enable it.


Available options:

options = {
  "Cavebot/ShovelID", 
  "Cavebot/RopeID", 
  "Cavebot/MacheteID", 
  "Cavebot/PickID",
  "Cavebot/Enabled", 
  "Cavebot/PauseBotOnDeath", 
  "Cavebot/MapWalkDistance", 
  "Cavebot/WalkThroughPlayers",
  "Cavebot/IgnoreNonPathable", 
  "SpellHealer/Enabled", 
  "ItemHealer/Enabled", 
  "ConditionHealer/Enabled",
  "Alerts/Enabled", 
  "Targeting/Enabled", 
  "Targeting/AllowDiagonalMovement", 
  "Targeting/AutoSwitchProfiles",
  "Targeting/NonPvpMode", 
  "Targeting/TargetReachable", 
  "Targeting/TargetShootable", 
  "Looting/Enabled",
  "Looting/LootingRange", 
  "Looting/LootingPolicy", 
  "Looting/EatFoodFromCorpse", 
  "Looting/OpenBPsAtLogin",
  "Looting/OpenNextBP", 
  "Global/BotPaused", 
  "Global/AlwaysOnTop"
}

sendKey


sendKey (string key )

Sends the specified key to the client.

g_game.sendKey("F1")

Available keys:

Keys = {
  "F1",
  "F2",
  "F3",
  "F4",
  "F5",
  "F6",
  "F7",
  "F8",
  "F9",
  "F10",
  "F11",
  "F12"
}

playSound


playSound (string fileName )

Plays the specified sound with fileName from the sounds folder in bot's directory

playSound("alarm.wav")

walk


walk (Direction direction )

Walks to the specified direction.

g_game.walk(Directions.North)

Available Directions:

Directions = {
  North = 0,
  East = 1,
  South = 2,
  West = 3,
  NorthEast = 4,
  SouthEast = 5,
  SouthWest = 6,
  NorthWest = 7,
}