backpack

 avatar
unknown
lua
2 months ago
1.3 kB
4
Indexable
local backpackId = {}

local moveTrashItem = function(startTile, topThing)
  for x = -maxDistance, maxDistance do
    for y = -maxDistance, maxDistance do
      local tile = g_map.getTile({x = posx() + x, y = posy() + y, z = posz()})
      local playerTile = g_map.getTile({x = posx(), y = posy(), z = posz()})
      if tile and tile ~= startTile and tile ~= playerTile then
        if tile:isWalkable() then
          return g_game.move(topThing, tile:getPosition(), topThing:getCount())
        end
      end
    end
  end
end

local moveBackpackToFoot = function()
   local storageBackpacks = backpackId
   for x = -maxDistance, maxDistance do
    for y = -maxDistance, maxDistance do
      local tile = g_map.getTile({x = posx() + x, y = posy() + y, z = posz()})
      if tile then
        local things = tile:getThings()
        for i, item in pairs(things) do
          if table.find(storageBackpacks, item:getId()) then
            local topThing = tile:getTopUseThing()
            if table.find(storageBackpacks, topThing:getId()) then              
              return g_game.move(item, pos(), item:getCount())
            end
            moveTrashItem(tile, topThing)
          end
        end
      end
    end
  end
end


macro(100, "Move Backpack", function()
    moveBackpackToFoot()
end)
Editor is loading...
Leave a Comment