Documentation › Lua

Map and Creature

Map reads the map the client knows (tiles, items, creatures) and acts on it: move items, use, look, walk to a point. Creature is an object that represents a creature by its id.

A tile the bot does not know returns nil. Map.getTiles and Map.getAllPositionsWithTopItemId only look at the client's visible area on your floor: 8 tiles west, 9 east, 6 north and 7 south.

Map: creatures#

Map.getCreatureIds(sameFloor, onlyPlayers)#

Map.getCreatureIds(sameFloor, onlyPlayers) → list or nil

Ids of the visible creatures.

ParameterTypeDescription
sameFloorboolean, optionaltrue (default) only your floor; false all floors
onlyPlayersboolean, optionaltrue only players; false (default) players, monsters, NPCs and summons

Returns nil when there are none.

lua
for _, id in ipairs(Map.getCreatureIds(true, false) or {}) do
  local c = Creature.new(id)
  if c:getType() == Enums.CreatureTypes.CREATURETYPE_MONSTER then print(c:getName()) end
end

Map.getPlayerOnScreen(nameOrId)#

Map.getPlayerOnScreen(nameOrId) → Creature or nil

Looks for a visible player by name (case-insensitive) or by id.

lua
local friend = Map.getPlayerOnScreen("Friend Name")
if friend then print(friend:getHealthPercent()) end

Map: tiles#

Map.getThings(x, y, z)#

Map.getThings(x, y, z) → list or nil

What is on a tile, from bottom to top (up to 10). Item: {id, count, isCreature = false, stackPos}. Creature: {id, isCreature = true, creatureId, stackPos}.

lua
local p = Player.getPosition()
for _, t in ipairs(Map.getThings(p.x, p.y, p.z) or {}) do print(t.id, t.isCreature) end

Map.getThingsCount(x, y, z)#

Map.getThingsCount(x, y, z) → number or nil

How many things are on the tile.

lua
print(Map.getThingsCount(32000, 32000, 7))

Map.getTopItemId(x, y, z)#

Map.getTopItemId(x, y, z) → number or nil

Id of the top item on the tile.

lua
print(Map.getTopItemId(32000, 32000, 7))

Map.getTopCreatureId(x, y, z)#

Map.getTopCreatureId(x, y, z) → number or nil

Id of the first creature on the tile.

lua
local id = Map.getTopCreatureId(32000, 32000, 7)
if id then print(Creature.new(id):getName()) end

Map.getTiles()#

Map.getTiles() → list

Every known tile on your floor in the visible area, as {x, y, z, things} (things in the getThings format).

lua
print(#Map.getTiles() .. " visible tiles")

Map.getAllPositionsWithTopItemId(itemId)#

Map.getAllPositionsWithTopItemId(itemId) → list or nil

Positions on your floor, in the visible area, where the top item is itemId.

lua
-- replace 1948 with the id of the item you are looking for
for _, pos in ipairs(Map.getAllPositionsWithTopItemId(1948) or {}) do print(pos.x, pos.y) end

Map.isTileWalkable(x, y, z, options)#

Map.isTileWalkable(x, y, z, options) → boolean

Whether you can step on the tile. false for an unknown tile, one with no ground, or a blocked one.

OptionDefaultDescription
ignoreBlockPathtrueIgnores tiles the bot would avoid (field, hole)
ignoreMagicFieldtrueIgnores magic fields
ignoreFloorChangetrueAccepted, but the bot does not tell floor changes apart
ignoreMonstersfalseMonsters do not block
ignoreNpcsfalseNPCs do not block

Tiles the bot would avoid only pass when ignoreBlockPath and ignoreMagicField are true. You yourself never block.

lua
local p = Player.getPosition()
print(Map.isTileWalkable(p.x + 1, p.y, p.z, { ignoreMonsters = true }))

Map.canWalk(x, y, z, ignoreBlockPath, ignoreMagicField, ignoreMonsters, ignoreNpcs)#

Map.canWalk(x, y, z, ...) → boolean

The same as isTileWalkable, with the options as parameters in the order above. Defaults: true, true, false, false.

lua
print(Map.canWalk(32000, 32000, 7))

Map.getCameraPosition()#

Map.getCameraPosition() → {x, y, z}

Center of the client's map, which is your position.

lua
print(Map.getCameraPosition().z)

Map: actions#

Map.goTo(x, y, z)#

Map.goTo(x, y, z) → boolean

Computes the path to the position and starts walking. Returns false when there is no path.

lua
if not Map.goTo(32369, 32241, 7) then print("no path") end

Map.lookAt(x, y, z)#

Map.lookAt(x, y, z) → true or nil

Looks at the top item on the tile. The answer arrives in the TEXT_MESSAGE event.

lua
Map.lookAt(32000, 32000, 7)

Map.browseField(x, y, z)#

Map.browseField(x, y, z)

Opens the tile's browse field.

lua
local p = Player.getPosition()
Map.browseField(p.x, p.y, p.z)

Map.moveItemToGround(x, y, z, count, toX, toY, toZ)#

→ true or nil

Moves the top item from one tile to another. count is optional (default: the whole stack).

lua
local p = Player.getPosition()
Map.moveItemToGround(p.x + 1, p.y, p.z, nil, p.x, p.y, p.z)

Map.moveItemToInventory(x, y, z, count, slot)#

→ true or nil

Moves the top item on the tile to an equipment slot.

lua
Map.moveItemToInventory(32000, 32000, 7, nil, Enums.InventorySlot.CONST_SLOT_AMMO)

Map.moveItemToContainer(x, y, z, count, container, slot)#

→ true or nil

Moves the top item on the tile to an open container.

lua
Map.moveItemToContainer(32000, 32000, 7, nil, 0, 0)

Map.moveCreatureToGround(x, y, z, toX, toY, toZ)#

→ true or nil

Pushes the creature on the tile to another tile.

lua
local p = Player.getPosition()
Map.moveCreatureToGround(p.x + 1, p.y, p.z, p.x + 2, p.y, p.z)

Map.useItemWithInventory(x, y, z, slot)#

→ true or nil

Uses the top item on the tile on the item in an equipment slot.

lua
Map.useItemWithInventory(32000, 32000, 7, Enums.InventorySlot.CONST_SLOT_LEFT)

Map.useItemWithContainer(x, y, z, container, slot)#

→ true or nil

Uses the top item on the tile on a container item.

lua
Map.useItemWithContainer(32000, 32000, 7, 0, 0)

Map.collectRewardChest(x, y, z)#

→ true or nil

Collects the reward chest on the tile.

lua
Map.collectRewardChest(32000, 32000, 7)

Creature#

Creature.new(id) (or Creature(id)) creates the object; methods use :. All of them return nil if the bot does not know the creature (it left the screen a long time ago or the id is wrong).

lua
local target = Creature.new(Player.getTargetId())
print(target:getName(), target:getHealthPercent(), target:getDistance())

creature:getId()#

→ number

The id used to create the object.

lua
print(Creature.new(Player.getTargetId()):getId())

creature:getName()#

→ text or nil

The creature's name.

lua
print(Creature.new(Player.getTargetId()):getName())

creature:getType()#

→ number or nil

Type, as in Enums.CreatureTypes: 0 player, 1 monster, 2 NPC, 3 your summon, 4 someone else's summon.

lua
if Creature.new(id):getType() == Enums.CreatureTypes.CREATURETYPE_PLAYER then print("player") end

creature:getHealthPercent()#

→ number or nil

Health as a percentage.

lua
print(Creature.new(Player.getTargetId()):getHealthPercent() .. "%")

creature:getPosition()#

→ {x, y, z} or nil

The creature's position. For yourself, it is always the right position, even after a teleport.

lua
local pos = Creature.new(id):getPosition()
if pos then print(pos.x, pos.y, pos.z) end

creature:getDistance()#

→ number or nil (extra)

Distance to you in tiles (the larger of the x and y differences).

lua
if Creature.new(id):getDistance() <= 1 then print("adjacent") end

creature:isOnScreen()#

→ boolean (extra)

true if the creature is alive, on your floor and up to 7 tiles from you.

lua
if Creature.new(Player.getTargetId()):isOnScreen() then print("target on screen") end

creature:getSpeed(), creature:getDirection() and creature:getVocation()#

→ number or nil

Speed; the direction it faces (0 north, 1 east, 2 south, 3 west); vocation (as the server sends it).

lua
print(Creature.new(id):getDirection())

creature:getSkull(), creature:getGuildEmblem() and creature:getPartyIcon()#

→ number or nil

Skull (Enums.Skulls), guild emblem (Enums.GuildEmblem) and party icon (Enums.PartyIcons).

lua
if Creature.new(id):getSkull() == Enums.Skulls.SKULL_WHITE then print("PK") end

creature:getOutfit()#

→ table or nil

Outfit and mount: type, typeEx (item, when the creature shows up as an item), head, body, legs, feet, addons, mountId, mountHead, mountBody, mountLegs, mountFeet.

lua
print(Creature.new(Player.getId()):getOutfit().type)

creature:getIcon() and creature:getIcons()#

→ 0 / → empty list

They exist for ZeroBot scripts, but today they always return 0 and an empty list.

lua
print(Creature.new(id):getIcon())