autoloot.lua

autoloot funfando DeuZOT
 avatar
unknown
plain_text
4 months ago
3.0 kB
3
Indexable
local hotkey = "9" -- deve ser colocada a hotkey para lootear em volta do boneco (exemplo: "ctrl+f1")
local intervalScan = 500 -- intervalo de scan para verificar a morte de criaturas (em milisegundos)




-- Aconselhável não alterar daqui pra baixo
local success, modifiers, key = HotkeyManager.parseKeyCombination(hotkey)

me = Map.getPlayerOnScreen(playerGetId())

creaturesAnterior = Map.getCreatureIds(true, false)
creaturesAnteriorPosition = {}

for i = 1, #creaturesAnterior do
    local creature = Creature.new(creaturesAnterior[i])

    if creature:getType() == Enums.CreatureTypes.CREATURETYPE_MONSTER then
        table.insert(creaturesAnteriorPosition, {creaturesAnterior[i], creature:getPosition().x, creature:getPosition().y, creature:getPosition().z})
    end
end

deadCreatures = {}

local timerLoot = Timer("loot", function()
    local creatures = Map.getCreatureIds(true, false)

    for i = 1, #creaturesAnteriorPosition do
        local achou = false
        
        for j = 1, #creatures do
            if creaturesAnteriorPosition[i][1] == creatures[j] then
                achou = true
                break
            end
        end

        if not achou then
            table.insert(deadCreatures, {x = creaturesAnteriorPosition[i][2], y = creaturesAnteriorPosition[i][3], z = creaturesAnteriorPosition[i][4], time = os.time(), tries = 0})
        end
    end

    local quantidadeMortosPerto = 0
    local creaturesToRemove = {}
    local agora = os.time()
    for i = 1, #deadCreatures do
        local posicaoCreatureMorta = deadCreatures[i]

        local distance = math.sqrt((posicaoCreatureMorta.x - me:getPosition().x)^2 + (posicaoCreatureMorta.y - me:getPosition().y)^2)

        if distance < 1.5 then
            quantidadeMortosPerto = quantidadeMortosPerto + 1

            if posicaoCreatureMorta.tries == 0 then
                posicaoCreatureMorta.tries = 1
            
                table.insert(creaturesToRemove, i)
            end
        else
            if agora - posicaoCreatureMorta.time > 600 then
                table.insert(creaturesToRemove, i)
            end
        end
    end

    if quantidadeMortosPerto > 0 then
        if success then
            Client.sendHotkey(key, modifiers)
        else
            Client.showMessage("Hotkey inválida")
        end
    end

    for i = #creaturesToRemove, 1, -1 do
        table.remove(deadCreatures, creaturesToRemove[i])
    end

    creaturesAnterior = creatures
    creaturesAnteriorPosition = {}

    for i = 1, #creaturesAnterior do
        local creature = Creature.new(creaturesAnterior[i])

        if creature:getType() == Enums.CreatureTypes.CREATURETYPE_MONSTER then
            table.insert(creaturesAnteriorPosition, {creaturesAnterior[i], creature:getPosition().x, creature:getPosition().y, creature:getPosition().z})
        end
    end
end, intervalScan)
Editor is loading...
Leave a Comment