Your browser does not support JavaScript or its disabled!
Please turn it on, or be aware that some features on this website will not work correctly.
419
Shovel - vBot extension #73
This allows you to add a shovel button inside the bot. (face the hole and press the button)
Edit your CONFIGNAME\vBot\cavebot.lua add this line as you would with other extensions.
dofile("/cavebot/shovel.lua")
create a file CONFIGNAME\cavebot\shovel.lua and add code below.
File: shovel.lua | 2.38kb | 89 lines.
-- Lee

-- This function only is needed once across all extensions add somewhere in your bot.
function getPosByDir(withItem)
  -- if withItem is set to true, it will get the first item in the tile items list such as rope hole.
  local dir = player:getDirection()
  local dir_pos = pos()

  if dir == 0 then
    dir_pos.y = dir_pos.y - 1
  elseif dir == 1 then
    dir_pos.x = dir_pos.x + 1
  elseif dir == 2 then
    dir_pos.y = dir_pos.y + 1
  elseif dir == 3 then
    dir_pos.x = dir_pos.x - 1
  end

  local ret =  dir_pos.x .. "," .. dir_pos.y .. "," .. dir_pos.z
  if withItem then
    local tile = g_map.getTile(dir_pos)
    local item = tile:getItems()[1]
    ret = ret .. ','.. item:getId()
  end
  return ret
end

CaveBot.Extensions.Shovel = {}

CaveBot.Extensions.Shovel.setup = function()
  CaveBot.registerAction("Shovel", "orange", function(value, retries)
    local pos = string.split(value, ",")
    local hole = nil
    local tries = nil
    if #pos >= 4 then
      hole = tonumber(pos[4])
    end
    if #pos >= 5 then
      shovel = tonumber(pos[5])
    end
    if #pos == 6 then
      tries = tonumber(pos[6])
    end

    if not pos[1] or not pos[2] or not pos[3] then
      warn("CaveBot[Shovel]: invalid value. It should be position (x,y,z), is: " .. value)
      return false
    end

    if retries >= (tries and tries or 20) then
      print("CaveBot[Shovel]: too many tries, can't open hole")
      return false -- tried 20 times, can't open
    end

    pos = {x=tonumber(pos[1]), y=tonumber(pos[2]), z=tonumber(pos[3])}  

    local playerPos = player:getPosition()
    if not playerPos.z == pos.z then 
      return true
    end

    local shovelTile = g_map.getTile(pos)
    if not shovelTile then
      return "retry"
    end

    local holeitem = shovelTile:getItems()[1]
    if holeitem and holeitem:getId() == hole then
      if not shovel then
        useWith(3457, holeitem)
      else
        useWith(shovel, holeitem)
      end
        delay(200)
        return "retry"
    else
      CaveBot.walkTo(pos)
      return "retry"
    end
    return "retry"
  end)

  CaveBot.Editor.registerAction("shovel", "shovel", {
    value=function() return getPosByDir(true) end,
    title="Shovel Hole",
    description="hole position (x,y,z ,closeId) and shovel id (optional) and retries (optional)",
    multiline=false,
})
end

24 Dec 2021