• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

candy-bot looting

tibia for live

New Member
Joined
Jan 26, 2018
Messages
8
Reaction score
3
hi, everyone and thanks for joining this thread.
first of all i'm sorry for my terrible english

i'm new to otland but otclient is somthing i use sins 2015.
but lately all server i do enjoy to play are pritty mucht based on collecting as mucht money as posible and thows servers do allow to bot. witch makes the servers inpossible to play if u don't bot becaus u compeating agest botters (for example there is a guy online for 17 days.....)

and for this reaseon i looked at candy bot by: BenDol
:https://codeload.github.com/BenDol/otclient-candybot/zip/master
witch is a amazing tool to help.

but now i'm wondering if it is posible to rewrite/ add so u can choose witch items it picks up

[
Code:
--[[
  @Authors: Ben Dol (BeniS)
  @Details: Auto loot logic
]]

TargetsModule.AutoLoot = {}
AutoLoot = TargetsModule.AutoLoot

-- Variables

AutoLoot.lootList = {}
AutoLoot.looting = false
AutoLoot.lootProc = nil

-- Methods

function AutoLoot.init()

end

function AutoLoot.terminate()

end

function AutoLoot.onStopped()

end

function AutoLoot.onTargetDeath(creature)
  if AutoLoot.canLoot(creature) then
    local creatureId = creature:getId()
    local creaturePos = creature:getPosition()
   
    AutoLoot.lootList[creatureId] = {
      id = creatureId,
      position = creaturePos,
      corpse = nil
    }

    local tile = g_map.getTile(creaturePos)
    if tile then
      local topThing = tile:getTopThing()
      if topThing and topThing:isContainer() then
        AutoLoot.lootList[creatureId].corpse = topThing
      end
    end
  end
end

function AutoLoot.isLooting()
  return AutoLoot.looting
end

function AutoLoot.removeLoot(creatureId)
  print("AutoLoot.removeLoot: "..tostring(creatureId))
  AutoLoot.lootList[creatureId] = nil
end

function AutoLoot.hasUncheckedLoot()
  for _,loot in pairs(AutoLoot.lootList) do
    if loot then
      return true
    end
  end
  return false
end

function AutoLoot.getClosestLoot()
  local player = g_game.getLocalPlayer()
  local playerPos = player:getPosition()

  local corpse = {distance=nil, loot = nil, creatureId=nil}
  for id,loot in pairs(AutoLoot.lootList) do
    if loot then
      print(postostring(loot.position))
      local distance = Position.distance(playerPos, loot.position)
      print(distance)
      if not corpse.loot or distance < corpse.distance then
        print("Found loot to go to")
        corpse.distance = distance
        corpse.loot = loot
        corpse.creatureId = id
      end
    end
  end
  return corpse
end

function AutoLoot.startLooting()
  print("AutoLoot.startLooting")
  AutoLoot.looting = true

  AutoLoot.lootNext()
end

function AutoLoot.lootNext()
  local player = g_game.getLocalPlayer()
  local data = AutoLoot.getClosestLoot()

  if data.loot and player:getFreeCapacity() > 0 then
    AutoLoot.lootProc = LootProcedure.create(data.creatureId,
      data.loot.position, data.loot.corpse)
   
    -- Loot procedure finished
    connect(AutoLoot.lootProc, { onFinished = function(id)
      AutoLoot.removeLoot(id)
      AutoLoot.lootNext()
    end })

    -- Loot procedure timed out
    connect(AutoLoot.lootProc, { onTimedOut = function(id)
      AutoLoot.removeLoot(id)
      AutoLoot.lootNext()
    end })

    -- Loot procedure failed
    connect(AutoLoot.lootProc, { onFailed = function(id)
      AutoLoot.lootNext()
    end })

    -- Loot procedure cancelled
    connect(AutoLoot.lootProc, { onCancelled = function(id)
      AutoLoot.lootProc = nil -- dereference
    end })

    AutoLoot.lootProc:start()
  else
    AutoLoot.stopLooting()
  end
end

function AutoLoot.pauseLooting()
  AutoLoot.looting = false

  if AutoLoot.lootProc then
    -- stop looting loot
    AutoLoot.lootProc:stop()
    AutoLoot.lootProc = nil
  end
end

function AutoLoot.stopLooting()
  print("AutoLoot.stopLooting")
  AutoLoot.looting = false

  if AutoLoot.lootProc then
    -- attempt to cancel loot
    AutoLoot.lootProc:cancel()
  end

  -- Clean up loot data
  AutoLoot.lootList = {}
end

function AutoLoot.canLoot(creature)
  local target = TargetsModule.getTarget(creature:getName())
  if target then
    return target:getLoot()
  end
  return false
end

function AutoLoot.onStopped()
  AutoLoot.pauseLooting()
end

function AutoLoot.Event(event)
  -- Cannot continue if still attacking or looting
  if g_game.isAttacking() or AutoLoot.isLooting() then
    return Helper.safeDelay(500, 800)
  end

  -- Try loot if not attacking still
  if not g_game.isAttacking() and AutoLoot.hasUncheckedLoot() then
    AutoLoot.startLooting()
  end

  -- Keep the event live
  return Helper.safeDelay(500, 800)
end
]

if this is posible, i would be very grateful if u can post and explane my how to do it.
i have a few attempts witch ended up with parts of the bot not being able to load when starting the client.
 
you guys can always play with some codes inside it, I mean its Lua and documentation is on the website :p
 
i did try fixing it but me programming skills are very limited, and the few time's i tryed it ends up crashing the whole bot
or the targeting part.

but i might have a idea with the help of you all. (becaus i'm terible and all of them fail if i tried it)
to creat a extra butten (partin the candybot)

1564414191848.png



first of all we need to change the looting part (so it just opens bodys and next etc.)
[
Lua:
--[[
  @Authors: Ben Dol (BeniS)
  @Details: Auto loot logic
]]

TargetsModule.AutoLoot = {}
AutoLoot = TargetsModule.AutoLoot

-- Variables

AutoLoot.lootList = {}
AutoLoot.looting = false
AutoLoot.lootProc = nil

-- Methods

function AutoLoot.init()
  AutoLoot.lootList = {}
  AutoLoot.looting = false
  AutoLoot.lootProc = nil
end

function AutoLoot.terminate()
  AutoLoot.onStopped()
end

function AutoLoot.onStopped()
  AutoLoot.stopLooting()
end

function AutoLoot.onTargetDeath(creature)
  if AutoLoot.canLoot(creature) then
    local creatureId = creature:getId()
    local creaturePos = creature:getPosition()
 
    AutoLoot.lootList[creatureId] = {
      id = creatureId,
      position = creaturePos,
      corpse = nil
    }

    local tile = g_map.getTile(creaturePos)
    if tile then
      local topThing = tile:getTopThing()
      if topThing and topThing:isContainer() then
        AutoLoot.lootList[creatureId].corpse = topThing
      end
    end
  end
end

function AutoLoot.isLooting()
  return AutoLoot.looting
end

function AutoLoot.removeLoot(creatureId)
  BotLogger.debug("AutoLoot: removeLoot: "..tostring(creatureId))
  AutoLoot.lootList[creatureId] = nil
end

function AutoLoot.hasUncheckedLoot()
  for _,loot in pairs(AutoLoot.lootList) do
    if loot then
      return true
    end
  end
  return false
end

function AutoLoot.getClosestLoot()
  local player = g_game.getLocalPlayer()
  local playerPos = player:getPosition()

  local corpse = {distance=nil, loot = nil, creatureId=nil}
  for id,loot in pairs(AutoLoot.lootList) do
    if loot then
      BotLogger.debug("AutoLoot: "..postostring(loot.position))
      local distance = Position.distance(playerPos, loot.position)
      BotLogger.debug("AutoLoot: "..tostring(distance))
      if not corpse.loot or distance < corpse.distance then
        BotLogger.debug("AutoLoot: Found closest loot")
        corpse.distance = distance
        corpse.loot = loot
        corpse.creatureId = id
      end
    end
  end
  return corpse
end

function AutoLoot.startLooting()
  BotLogger.debug("AutoLoot.startLooting() called")
  AutoLoot.looting = true

  AutoLoot.lootNext()
end

function AutoLoot.lootNext()
  local player = g_game.getLocalPlayer()
  local data = AutoLoot.getClosestLoot()

  if data.loot and player:getFreeCapacity() > 0 then
    AutoLoot.lootProc = LootProcedure.create(data.creatureId,
      data.loot.position, data.loot.corpse)
 
    -- Loot procedure finished
    connect(AutoLoot.lootProc, { onFinished = function(id)
      AutoLoot.removeLoot(id)
      AutoLoot.lootNext()
    end })

    -- Loot procedure timed out
    connect(AutoLoot.lootProc, { onTimedOut = function(id)
      AutoLoot.removeLoot(id)
      AutoLoot.lootNext()
    end })

    -- Loot procedure failed
    connect(AutoLoot.lootProc, { onFailed = function(id)
      AutoLoot.lootNext()
    end })

    -- Loot procedure cancelled
    connect(AutoLoot.lootProc, { onCancelled = function(id)
      AutoLoot.lootProc = nil -- dereference
    end })

    AutoLoot.lootProc:start()
  else
    AutoLoot.stopLooting()
  end
end

function AutoLoot.pauseLooting()
  AutoLoot.looting = false

  if AutoLoot.lootProc then
    -- stop looting loot
    AutoLoot.lootProc:stop()
    AutoLoot.lootProc = nil
  end
end

function AutoLoot.stopLooting()
  BotLogger.debug("AutoLoot.stopLooting() called")
  AutoLoot.looting = false

  if AutoLoot.lootProc then
    -- attempt to cancel loot
    AutoLoot.lootProc:cancel()
  end

  -- Clean up loot data
  AutoLoot.lootList = {}
end

function AutoLoot.canLoot(creature)
  local target = TargetsModule.getTarget(creature:getName())
  if target then
    return target:getLoot()
  end
  return false
end

function AutoLoot.onStopped()
  AutoLoot.pauseLooting()
end

function AutoLoot.Event(event)
  -- Cannot continue if still attacking or looting
  if g_game.isAttacking() or AutoLoot.isLooting() then
    return Helper.safeDelay(500, 800)
  end

  -- Try loot if not attacking still
  if not g_game.isAttacking() and AutoLoot.hasUncheckedLoot() then
    AutoLoot.startLooting()
  end

  -- Keep the event live
  return Helper.safeDelay(500, 800)
end
]

this looting butten would then open a part of "the kingdom bot" created by GustavoBlaze
(tried this bot but it gives a list of errors about not finding files. but they are there)

just the looting part of this bot (this way it shouldn't need the initalisation)

1564415975200.png

already a big Thanks to everyone who tried creating (not only my dream but the dream of many candyboy uses)
 
Last edited:
Last edited:
how to activate walking. everything is working just I dont know how to activate walking (waypoints). Its not working for me. I have disabled bot preotection.
 
Back
Top