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.
| Parameter | Type | Description |
|---|---|---|
| sameFloor | boolean, optional | true (default) only your floor; false all floors |
| onlyPlayers | boolean, optional | true only players; false (default) players, monsters, NPCs and summons |
Returns nil when there are none.
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
endMap.getPlayerOnScreen(nameOrId)#
Map.getPlayerOnScreen(nameOrId) → Creature or nil
Looks for a visible player by name (case-insensitive) or by id.
local friend = Map.getPlayerOnScreen("Friend Name")
if friend then print(friend:getHealthPercent()) endMap: 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}.
local p = Player.getPosition()
for _, t in ipairs(Map.getThings(p.x, p.y, p.z) or {}) do print(t.id, t.isCreature) endMap.getThingsCount(x, y, z)#
Map.getThingsCount(x, y, z) → number or nil
How many things are on the tile.
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.
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.
local id = Map.getTopCreatureId(32000, 32000, 7)
if id then print(Creature.new(id):getName()) endMap.getTiles()#
Map.getTiles() → list
Every known tile on your floor in the visible area, as {x, y, z, things} (things in the getThings format).
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.
-- 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) endMap.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.
| Option | Default | Description |
|---|---|---|
ignoreBlockPath | true | Ignores tiles the bot would avoid (field, hole) |
ignoreMagicField | true | Ignores magic fields |
ignoreFloorChange | true | Accepted, but the bot does not tell floor changes apart |
ignoreMonsters | false | Monsters do not block |
ignoreNpcs | false | NPCs do not block |
Tiles the bot would avoid only pass when ignoreBlockPath and ignoreMagicField are true. You yourself never block.
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.
print(Map.canWalk(32000, 32000, 7))Map.getCameraPosition()#
Map.getCameraPosition() → {x, y, z}
Center of the client's map, which is your position.
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.
if not Map.goTo(32369, 32241, 7) then print("no path") endMap.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.
Map.lookAt(32000, 32000, 7)Map.browseField(x, y, z)#
Map.browseField(x, y, z)
Opens the tile's browse field.
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).
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.
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.
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.
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.
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.
Map.useItemWithContainer(32000, 32000, 7, 0, 0)Map.collectRewardChest(x, y, z)#
→ true or nil
Collects the reward chest on the tile.
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).
local target = Creature.new(Player.getTargetId())
print(target:getName(), target:getHealthPercent(), target:getDistance())creature:getId()#
→ number
The id used to create the object.
print(Creature.new(Player.getTargetId()):getId())creature:getName()#
→ text or nil
The creature's name.
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.
if Creature.new(id):getType() == Enums.CreatureTypes.CREATURETYPE_PLAYER then print("player") endcreature:getHealthPercent()#
→ number or nil
Health as a percentage.
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.
local pos = Creature.new(id):getPosition()
if pos then print(pos.x, pos.y, pos.z) endcreature:getDistance()#
→ number or nil (extra)
Distance to you in tiles (the larger of the x and y differences).
if Creature.new(id):getDistance() <= 1 then print("adjacent") endcreature:isOnScreen()#
→ boolean (extra)
true if the creature is alive, on your floor and up to 7 tiles from you.
if Creature.new(Player.getTargetId()):isOnScreen() then print("target on screen") endcreature: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).
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).
if Creature.new(id):getSkull() == Enums.Skulls.SKULL_WHITE then print("PK") endcreature: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.
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.
print(Creature.new(id):getIcon())
Comments
to comment.