avatar
Untitled

Guest 84 29th Sep, 2024

MARKUP 3.70 KB
                                           
                         local target
local targetTile

DoublePushConfig = {
  tab= "War",
  markHotkey="F9",
  triggerHotkey = "F10"
}

setDefaultTab(DoublePushConfig.tab)
local function matchPosition(p1, p2)
  return (p1.x == p2.x and p1.y == p2.y)
end
local function isInFront(pos1, pos2)
  if pos1.x == pos2.x and pos1.y + 1 == pos2.y then
    return true
  elseif pos1.x == pos2.x and pos1.y - 1 == pos2.y then
    return true
  elseif pos1.y == pos2.y and pos1.x + 1 == pos2.x then
    return true
  elseif pos1.y == pos2.y and pos1.x - 1 == pos2.x then
    return true
  end
  return false
end
local function findFirstTileToPush(targetPos, targetTilePos)
  for i, tile in pairs(g_map.getTiles(posz())) do
    if tile:isWalkable() and not tile:hasCreature() then
      if getDistanceBetween(targetPos, tile:getPosition()) == 1 and getDistanceBetween(targetTilePos, tile:getPosition()) == 1 then
        if isInFront(targetPos, tile:getPosition()) then
          return tile
        end
      end
    end
  end
end
local function clearTarget()
  if target then
    for i, tile in pairs(g_map.getTiles(posz())) do
      tile:setText("")
    end
    target = nil
  end
end
local function clearDestination()
  if targetTile then
    targetTile:setText("")
    targetTile = nil
  end
end
hotkey(DoublePushConfig.triggerHotkey, "Double Push", function()
  if target and targetTile then
    if not matchPosition(target:getPosition(), targetTile:getPosition()) then
      local distance = getDistanceBetween(target:getPosition(), targetTile:getPosition())
      if distance >= 2 then
        if findPath(player:getPosition(), target:getPosition(), 15, { ignoreNonPathable = false, precision = 1, ignoreCreatures = false }) then
          local firstTile = findFirstTileToPush(target:getPosition(), targetTile:getPosition())
          if not firstTile then
            return
          end
          g_game.move(target, targetTile:getPosition())
          schedule(200, function()
            g_game.move(target, firstTile:getPosition())
            clearTarget()
          end)
          delay(1300)
          clearDestination()
        end
      elseif distance == 1 then
        g_game.move(target, targetTile:getPosition())
        delay(1100)
        clearTarget()
        clearDestination()
      end
    end
  end
end)
local resetTimer = now
local resetTiles = false
onKeyDown(function(keys)
  if keys == DoublePushConfig.markHotkey and resetTimer == 0 then
    if not target then
      local tile = getTileUnderCursor()
      if tile:getCreatures()[1] then
        target = tile:getCreatures()[1]
        tile:setText("TARGET")
      end
    elseif not targetTile then
      local tile = getTileUnderCursor()
      if tile and not tile:getCreatures()[1] then
        targetTile = tile
        tile:setText("PUSH HERE")
      end
    end
    resetTimer = now
  end
end)
onKeyPress(function(keys)
  if keys == DoublePushConfig.markHotkey and (resetTimer - now) < -1000 then
    if target then
      g_map.getTile(target:getPosition()):setText("")
    end
    clearTarget()
    clearDestination()
    resetTimer = 0
  else
    resetTimer = 0
  end
end)
onCreaturePositionChange(function(creature, newPos, oldPos)
  if target then
    if creature:getId() == target:getId() then
      if oldPos and newPos then
        local oldTile = g_map.getTile(oldPos)
        local newTile = g_map.getTile(newPos)
        oldTile:setText("")
        newTile:setText("TARGET")
      end
    end
  end
end)
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes
Ta strona używa plików cookie w celu usprawnienia i ułatwienia dostępu do serwisu oraz prowadzenia danych statystycznych. Dalsze korzystanie z tej witryny oznacza akceptację tego stanu rzeczy.
Wykorzystywanie plików Cookie
Jak wyłączyć cookies?
ROZUMIEM