• 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!

Autoloot problem tfs 1.5

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
188
Reaction score
9
GitHub
Jarek123
Hello Everyone I have problem with Autoloot because I would like add to my server and I try and have errors like thats
When I say !loot add, gold or remove or something like that

Lua:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/auto_loot.lua:onSay
data/talkactions/scripts/auto_loot.lua:12: attempt to call method 'getVipDays' (a nil value)
stack traceback:
        [C]: in function 'getVipDays'
        data/talkactions/scripts/auto_loot.lua:12: in function 'addQuickItem'
        data/talkactions/scripts/auto_loot.lua:165: in function <data/talkactions/scripts/auto_loot.lua:141>

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/auto_loot.lua:onSay
data/talkactions/scripts/auto_loot.lua:12: attempt to call method 'getVipDays' (a nil value)
stack traceback:
        [C]: in function 'getVipDays'
        data/talkactions/scripts/auto_loot.lua:12: in function 'addQuickItem'
        data/talkactions/scripts/auto_loot.lua:165: in function <data/talkactions/scripts/auto_loot.lua:141>

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/auto_loot.lua:onSay
data/talkactions/scripts/auto_loot.lua:248: attempt to call global 'trim' (a nil value)
stack traceback:
        [C]: in function 'trim'
        data/talkactions/scripts/auto_loot.lua:248: in function <data/talkactions/scripts/auto_loot.lua:141>
my cripts is
Post automatically merged:

Can somebody help me?
Talkaction script
Lua:
local function addQuickItem(playerId, itemId, itemName)
    local player = Player(playerId)
    if not player then
        return false
    end

    local itemType = ItemType(itemId)
    if not itemType then
        return false
    end

    local maxItem = player:getVipDays() > 0 and AUTOLOOT_MAXITEM_VIP or AUTOLOOT_MAXITEM_FREE
    maxItem = maxItem + math.max(0, player:getStorageValue(AUTOLOOT_INCREASE))

    local itemId = itemType:getId()
    local playerGuid = player:getGuid()
    local resultId = db.storeQuery(string.format('SELECT `item_id` FROM `quick_loot_list` WHERE `item_id` = %d AND `player_id` = %d', itemId, playerGuid))
    if resultId then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, string.format("[AUTO LOOT] - O item %s já está em sua lista de Loot.", itemName))
        result.free(resultId)
        return false
    end

    -- Check max item count
    local count = 0
    local resultId = db.storeQuery(string.format('SELECT COUNT(*) as `count` FROM `quick_loot_list` WHERE `player_id` = %d', playerGuid))
    if resultId then
        count = result.getNumber(resultId, "count")
        result.free(resultId)
    end

    if count >= maxItem then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "[AUTO LOOT] - A sua lista já está completa, por favor remova algum item.")
        return false
    end

    db.query(string.format('INSERT INTO `quick_loot_list` (`player_id`, `item_id`, `date_added`) VALUES (%d, %d, %d)', playerGuid, itemId, os.time()))
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, string.format("[AUTO LOOT] - O item %s foi adicionado em sua lista de Loot.", itemName))
    AutoLootList:save(playerId)
    return true
end

local function removeQuickItem(playerId, itemId, itemName)
    local player = Player(playerId)
    if not player then
        return false
    end

    local playerGuid = player:getGuid()
    local resultId = db.storeQuery(string.format('SELECT `item_id` FROM `quick_loot_list` WHERE `player_id` = %d AND `item_id` = %d', playerGuid, itemId))
    if not resultId then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, string.format("[AUTO LOOT] - O item %s năo está em sua lista de Loot", itemName))
        return false
    end

    db.query(string.format('DELETE FROM `quick_loot_list` WHERE `player_id` = %d and `item_id` = %d', playerGuid, itemId))
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, string.format("[AUTO LOOT] - O item %s foi removido da sua lista de Loot.", itemName))
    AutoLootList:save(playerId)
    return true
end

local function quickLootIsInList(playerId, itemId)
    local resultId = db.storeQuery(string.format('SELECT `item_id` FROM `quick_loot_list` WHERE `player_id` = %d AND `item_id` = %d', playerId, itemId))
    if resultId then
        result.free(resultId)
        return ' - Adicionado!'
    end

    return ''
end

local function itemListMonsterModal(playerId, monsterName)
    local player = Player(playerId)
    if not player then
        return false
    end

    local monsterType = MonsterType(monsterName)
    if not monsterType then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] - Esse monstro năo existe ou năo está no mapa.")
        return false
    end

    if monsterType:isRewardBoss() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] - Vocę năo pode visualizar os Loot de Bosses de Reward Chest.")
        return false
    end

    local monsterName = monsterType:getName()
    local window = ModalWindow {
        title = string.format('Loot do monstro %s', monsterName:lower()),
        message = 'Adiciona ou remova itens desse monstro da sua lista de loot.',
    }

    local windowCount = 0
    local t = {}
    local playerGuid = player:getGuid()
    if monsterType:getLoot() then
        for _, v in pairs(monsterType:getLoot()) do
            if windowCount < 255 then
                local itemId = v.itemId
                if not isInArray(t, itemId) then
                    local itemType = ItemType(itemId)
                    if itemType then
                        local itemName = itemType:getName()
                        local choice = window:addChoice(itemName .. quickLootIsInList(playerGuid, itemId))
                        windowCount = windowCount + 1

                        choice.itemId = itemId
                        choice.itemName = itemName
                        table.insert(t, itemId)
                    end
                end
            end
        end
    end

    window:addButton("Remover",
        function(button, choice)
            if player and choice then
                removeQuickItem(player:getId(), choice.itemId, choice.itemName)
                itemListMonsterModal(playerId, monsterName)
            end
        end
    )

    window:addButton("Adicionar",
        function(button, choice)
            if player and choice then
                addQuickItem(player:getId(), choice.itemId, choice.itemName)
                itemListMonsterModal(playerId, monsterName)
            end
        end
    )

    window:addButton("Sair")
    window:setDefaultEscapeButton("Sair")
    window:sendToPlayer(player)
end

function onSay(player, words, param)
    local split = param:split(",")
    local action = split[1]
    local playerGuid = player:getGuid()

    if action == "add" then
        if not split[2] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] - Use o comando: !loot add, itemName")
            return false
        end

        local item = split[2]:gsub("%s+", "", 1)
        local itemType = ItemType(item)
        local itemId = itemType:getId()
        if itemId == 0 then
            itemType = ItemType(tonumber(item))
            if itemId == 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] - Năo existe nenhum item com esse nome.")
                return false
            end
        end

        -- Checar se o item já está na lista do jogador.
        local itemName = tonumber(split[2]) and itemType:getName() or item
        addQuickItem(player:getId(), itemId, itemName)
    elseif action == "remove" then
        if not split[2] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Use o comando: !loot remove, itemName")
            return false
        end

        local item = split[2]:gsub("%s+", "", 1)
        local itemType = ItemType(item)
        local itemId = itemType:getId()
        if itemId == 0 then
            itemType = ItemType(tonumber(item))
            if itemId == 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Năo existe nenhum item com esse nome.")
                return false
            end
        end

        local itemName = tonumber(split[2]) and itemType:getName() or item
        local resultId = db.storeQuery(string.format('SELECT `item_id` FROM `quick_loot_list` WHERE `item_id` = %d', itemId))
        if not resultId then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." năo foi encontrado em sua lista.")
            return false
        end
        result.free(resultId)

        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." foi removido de sua lista.")
        removeQuickItem(player:getId(), itemId, itemName)
    elseif action == "list" then
        local count = 0
        local resultId = db.storeQuery(string.format('SELECT COUNT(*) as `count` FROM `quick_loot_list` WHERE `player_id` = %d', playerGuid))
        if resultId then
            count = result.getNumber(resultId, "count")
            result.free(resultId)
        end

        if count == 0 then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] - Vocę năo possui nenhum item em sua lista.")
            return false
        end

        local resultId = db.storeQuery(string.format('SELECT `item_id` FROM `quick_loot_list` WHERE `player_id` = %d', playerGuid))
        if not resultId then
            return false
        end

        local window = ModalWindow {
            title = "Sua lista de itens",
            message = 'Essa é sua lista de itens!\nAssim que algum desses itens forem dropados, e ao clicar no corpo do monstro\no item será enviado para a sua backpack!',
        }

        local lootList = queryToTable(resultId, {'item_id:number'})
        for _, loot in pairs(lootList) do
            local itemType = ItemType(loot.item_id)
            if itemType then
                local itemName = itemType:getName()
                local choice = window:addChoice(itemName)

                choice.itemId = itemType:getId()
                choice.itemName = itemName
            end
        end

        window:addButton("Remover",
            function(button, choice)
                if player and choice then
                    removeQuickItem(player:getId(), choice.itemId, choice.itemName)
                end
            end
        )

        window:addButton("Sair")
        window:setDefaultEscapeButton("Sair")
        window:sendToPlayer(player)
    elseif (action == "gold info") then
        local obtainedMoney = player:getObtainedMoneyAutoLoot()
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT - GOLD]: Atualmente no sistema de Auto Loot Gold vocę já fez %s gold coin%s.", comma_value(obtainedMoney), obtainedMoney ~= 1 and 's' or ''))
    else
        if not split[1] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[Auto Loot] - Os itens serăo movidos para a sua Backpack quando vocę abrir o corpo:\n!autoloot list - irá listar todos os itens na sua lista.\n!autoloot monsterName - verificar o loot de um monstro (exemplo: !autoloot rat)\n!autoloot add, itemName - adicionar um item pelo o nome\n!autoloot remove, itemName - remover o item pelo o nome")
            return false
        end

        local monsterName = trim(split[1])
        itemListMonsterModal(player:getId(), monsterName)
    end

    return false
end
Post automatically merged:

I have from here

 

Attachments

Last edited:
I find This script

data/scripts/autoloot

Lua:
-- !autoloot clear
-- !autoloot list
-- !autoloot add, itemName          / ex: !autoloot add, fire sword
-- !autoloot remove, itemName       / ex: !autoloot remove, fire sword

local autoloot = {
    freeAccountLimit = 10,
    storageBase = 50000,
    premiumAccountLimit = 20,
}

local autolootCache = {}

local function getPlayerLimit(player)
    if player then
        return player:isPremium() and autoloot.premiumAccountLimit or autoloot.freeAccountLimit
    end
    return false
end

local function getPlayerAutolootItems(player)
    local limits = getPlayerLimit(player)
    if limits then
        local guid = player:getGuid()
        if guid then
            local itemsCache = autolootCache[guid]
            if itemsCache then
                if #itemsCache > limits then
                    local newChache = {unpack(itemsCache, 1, limits)}
                    autolootCache[guid] = newChache
                    return newChache
                end
                return itemsCache
            end

            local items = {}
            for i = 1, limits do
                local itemType = ItemType(math.max(player:getStorageValue(Storage.autolootBase + i)), 0)
                if itemType then
                    if itemType:getId() ~= 0 then
                        items[#items +1] = itemType:getId()
                    end
                end
            end

            autolootCache[guid] = items
            return items
        end
    end
    return false
end

local function setPlayerAutolootItems(player, items)
    if items then
        local limit = getPlayerLimit(player)
        if limit then
            for i = limit, 1, -1 do
                player:setStorageValue(Storage.autolootBase + i, (items[i] and items[i] or -1))
            end
        end
        return true
    end
    return false
end

local function addPlayerAutolootItem(player, itemId)
    local items = getPlayerAutolootItems(player)
    if items then
        for _, id in pairs(items) do
            if itemId == id then
                return false
            end
        end
        items[#items +1] = itemId
        return setPlayerAutolootItems(player, items)
    end
    return false
end

local function removePlayerAutoAlllootItem(player)
    local items = getPlayerAutolootItems(player)
    if items then
        for i, id in pairs(items) do
            table.remove(items, i)
        end
        return setPlayerAutolootItems(player, items)
    end
    return false
end

local function removePlayerAutolootItem(player, itemId)
    local items = getPlayerAutolootItems(player)
    if items then
        for i, id in pairs(items) do
            if itemId == id then
                table.remove(items, i)
                return setPlayerAutolootItems(player, items)
            end
        end
    end
    return false
end

local function hasPlayerAutolootItem(player, itemId)
    local items = getPlayerAutolootItems(player)
    if items then
        for _, id in pairs(items) do
            if itemId then
                if itemId == id then
                    return true
                end
            end
        end
    end
    return false
end

local ec = EventCallback

function ec.onDropLoot(monster, corpse)
    if not corpse:getType():isContainer() then
        return
    end

    local corpseOwner = Player(corpse:getCorpseOwner())
    if not corpseOwner then
        return
    end
    local items = corpse:getItems()
    local mType = monster:getType()
    local text = "Autoloot ".. mType:getNameDescription() ..":"
    if items then
        for _, item in pairs(items) do
            local itemId = item:getId()
            local amount = item:getCount()
            if table.contains({ITEM_GOLD_COIN, ITEM_PLATINUM_COIN, ITEM_CRYSTAL_COIN, 2157}, itemId) and corpseOwner:getStorageValue(Storage.autolootGoldAtive) == 1 then
                if amount then
                    item:remove(amount)
                    if itemId == ITEM_PLATINUM_COIN then
                        amount = amount * 100
                    elseif itemId == ITEM_CRYSTAL_COIN then
                        amount = amount * 10000
                    elseif itemId == 2157 then
                        amount = amount * 1000000
                    end
                    corpseOwner:setBankBalance(corpseOwner:getBankBalance() + amount)
                    corpseOwner:sendTextMessage(MESSAGE_INFO_DESCR, text .." ".. amount .. " gold ".. (amount > 1 and "coins were transferred" or "coin has been transferred") .." to your bank account.")
                end
            else
                if hasPlayerAutolootItem(corpseOwner, itemId) then
                    local itemName = amount > 1 and item:getPluralName() or item:getName()
                    local itemArticle = item:getArticle() ~= "" and item:getArticle() or "a"
                    if not item:moveTo(corpseOwner) then
                        corpseOwner:sendTextMessage(MESSAGE_EVENT_ADVANCE, "[AUTO LOOT] You don't have capacity.")
                        break
                    else
                        corpseOwner:sendTextMessage(MESSAGE_INFO_DESCR, text .." ".. (amount > 1 and amount or itemArticle) .. " ".. itemName ..".")
                    end
                end
            end
        end
    end
end

ec:register(3)

local talkAction = TalkAction("!autoloot")

function talkAction.onSay(player, words, param, type)
    local split = param:splitTrimmed(",")
    local action = split[1]
    if not action then
        player:showTextDialog(8977, "Commands:" .. "\n\n"
            .. "!autoloot clear" .. "\n"
            .. "!autoloot list" .. "\n"
            .. "!autoloot add, itemName" .. "\n"
            .. "!autoloot remove, itemName".. "\n"
            .. "!autoloot gold".. "\n\n"
            .. "Number of slots: ".. "\n"
            .. autoloot.freeAccountLimit .." free account".. "\n"
            .. autoloot.premiumAccountLimit .." premium account")
        return false
    end

    if not table.contains({"clear", "list", "add", "remove", "gold"}, action) then
        player:showTextDialog(8977, "[AUTO LOOT] Commands:" .. "\n\n"
            .. "!autoloot clear" .. "\n"
            .. "!autoloot list" .. "\n"
            .. "!autoloot add, itemName" .. "\n"
            .. "!autoloot remove, itemName".. "\n"
            .. "!autoloot gold".. "\n\n"
            .. "Quantidade de slots: ".. "\n"
            .. autoloot.freeAccountLimit .." free account".. "\n"
            .. autoloot.premiumAccountLimit .." premium account")
        return false
    end

    -- !autoloot clear
    if action == "clear" then
        removePlayerAutoAlllootItem(player)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] Clean autoloot list.")
        return false

    -- !autoloot list
    elseif action == "list" then
        local items = getPlayerAutolootItems(player)
        if items then
            local limit = getPlayerLimit(player)
            if limit then
                local description = {string.format('[AUTO LOOT] Capacity: %d/%d ~\n\nList of items:\n-----------------------------', #items, limit)}
                for i, itemId in pairs(items) do
                    description[#description +1] = string.format("%d) %s", i, ItemType(itemId):getName())
                end
                player:showTextDialog(8977, table.concat(description, '\n'), false)
            end
        end
        return false
    end

    local function getItemType()
        local itemType = ItemType(split[2])
        if not itemType or itemType:getId() == 0 then
            itemType = ItemType(tonumber(split[2]) or 0)
            if not itemType or itemType:getId() == 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] The item %s does not exist!", split[2]))
                return false
            end
        end
        return itemType
    end

    -- !autoloot add, itemName
    if action == "add" then
        local itemType = getItemType()
        if itemType then
            local limits = getPlayerLimit(player)
            if limits then
                local items = getPlayerAutolootItems(player)
                if items then
                    if #items >= limits then
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Your autoloot only allows you to add %d items.", limits))
                        return false
                    end

                    if addPlayerAutolootItem(player, itemType:getId()) then
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Perfect, you added the autoloot list: %s", itemType:getName()))
                    else
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Item %s is already on the list!", itemType:getName()))
                    end
                end
            end
        end
        return false

    -- !autoloot remove, itemName
    elseif action == "remove" then
        local itemType = getItemType()
        if itemType then
            if removePlayerAutolootItem(player, itemType:getId()) then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Perfect, you removed it from the autoloot list: %s", itemType:getName()))
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Item %s is not in your list.", itemType:getName()))
            end
        end
        return false

    -- !autoloot gold
    elseif action == "gold" then
        player:setStorageValue(Storage.autolootGoldAtive, player:getStorageValue(Storage.autolootGoldAtive) == 1 and 0 or 1)
        local check = player:getStorageValue(Storage.autolootGoldAtive) == 1 and "activated" or "disabled"
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] You ".. check .." collecting money by autoloot.")
        return false
    end

    return false
end

talkAction:separator(" ")
talkAction:register()

local creatureEvent = CreatureEvent("autolootCleanCache")

function creatureEvent.onLogout(player)
    local items = getPlayerAutolootItems(player)
    if items then
        setPlayerAutolootItems(player, items)
        autolootCache[player:getGuid()] = nil
    end
    return true
end

error
Code:
Lua Script Error: [Event Interface]
data/events/scripts/monster.lua:Monster@onDropLoot
/home/ots/data/scripts/loot.lua:38: attempt to index global 'Storage' (a nil value)
stack traceback:
        [C]: in function '__index'
        /home/ots/data/scripts/loot.lua:38: in function 'getPlayerAutolootItems'
        /home/ots/data/scripts/loot.lua:105: in function 'hasPlayerAutolootItem'
        /home/ots/data/scripts/loot.lua:150: in function 'callback'
        /home/ots/data/scripts/lib/event_callbacks.lua:131: in function 'EventCallback'
        data/events/scripts/monster.lua:3: in function <data/events/scripts/monster.lua:1>
Post automatically merged:

Can anyone help me please?
 
Try this:
Lua:
-- !autoloot clear
-- !autoloot list
-- !autoloot add, itemName          / ex: !autoloot add, fire sword
-- !autoloot remove, itemName       / ex: !autoloot remove, fire sword
local autoloot = {
    freeAccountLimit = 10,
    storageBase = 50000,
    premiumAccountLimit = 20,
}
local autolootCache = {}
local function getPlayerLimit(player)
    if player then
        return player:isPremium() and autoloot.premiumAccountLimit or autoloot.freeAccountLimit
    end
    return false
end
local function getPlayerAutolootItems(player)
    local limits = getPlayerLimit(player)
    if limits then
        local guid = player:getGuid()
        if guid then
            local itemsCache = autolootCache[guid]
            if itemsCache then
                if #itemsCache > limits then
                    local newChache = {unpack(itemsCache, 1, limits)}
                    autolootCache[guid] = newChache
                    return newChache
                end
                return itemsCache
            end
            local items = {}
            for i = 1, limits do
                local itemType = ItemType(math.max(player:getStorageValue(autoloot.storageBase + i)), 0)
                if itemType then
                    if itemType:getId() ~= 0 then
                        items[#items +1] = itemType:getId()
                    end
                end
            end
            autolootCache[guid] = items
            return items
        end
    end
    return false
end
local function setPlayerAutolootItems(player, items)
    if items then
        local limit = getPlayerLimit(player)
        if limit then
            for i = limit, 1, -1 do
                player:setStorageValue(autoloot.storageBase + i, (items[i] and items[i] or -1))
            end
        end
        return true
    end
    return false
end
local function addPlayerAutolootItem(player, itemId)
    local items = getPlayerAutolootItems(player)
    if items then
        for _, id in pairs(items) do
            if itemId == id then
                return false
            end
        end
        items[#items +1] = itemId
        return setPlayerAutolootItems(player, items)
    end
    return false
end
local function removePlayerAutoAlllootItem(player)
    local items = getPlayerAutolootItems(player)
    if items then
        for i, id in pairs(items) do
            table.remove(items, i)
        end
        return setPlayerAutolootItems(player, items)
    end
    return false
end
local function removePlayerAutolootItem(player, itemId)
    local items = getPlayerAutolootItems(player)
    if items then
        for i, id in pairs(items) do
            if itemId == id then
                table.remove(items, i)
                return setPlayerAutolootItems(player, items)
            end
        end
    end
    return false
end
local function hasPlayerAutolootItem(player, itemId)
    local items = getPlayerAutolootItems(player)
    if items then
        for _, id in pairs(items) do
            if itemId then
                if itemId == id then
                    return true
                end
            end
        end
    end
    return false
end
local ec = EventCallback
function ec.onDropLoot(monster, corpse)
    if not corpse:getType():isContainer() then
        return
    end
    local corpseOwner = Player(corpse:getCorpseOwner())
    if not corpseOwner then
        return
    end
    local items = corpse:getItems()
    local mType = monster:getType()
    local text = "Autoloot ".. mType:getNameDescription() ..":"
    if items then
        for _, item in pairs(items) do
            local itemId = item:getId()
            local amount = item:getCount()
            if table.contains({ITEM_GOLD_COIN, ITEM_PLATINUM_COIN, ITEM_CRYSTAL_COIN, 2157}, itemId) and corpseOwner:getStorageValue(Storage.autolootGoldAtive) == 1 then
                if amount then
                    item:remove(amount)
                    if itemId == ITEM_PLATINUM_COIN then
                        amount = amount * 100
                    elseif itemId == ITEM_CRYSTAL_COIN then
                        amount = amount * 10000
                    elseif itemId == 2157 then
                        amount = amount * 1000000
                    end
                    corpseOwner:setBankBalance(corpseOwner:getBankBalance() + amount)
                    corpseOwner:sendTextMessage(MESSAGE_INFO_DESCR, text .." ".. amount .. " gold ".. (amount > 1 and "coins were transferred" or "coin has been transferred") .." to your bank account.")
                end
            else
                if hasPlayerAutolootItem(corpseOwner, itemId) then
                    local itemName = amount > 1 and item:getPluralName() or item:getName()
                    local itemArticle = item:getArticle() ~= "" and item:getArticle() or "a"
                    if not item:moveTo(corpseOwner) then
                        corpseOwner:sendTextMessage(MESSAGE_EVENT_ADVANCE, "[AUTO LOOT] You don't have capacity.")
                        break
                    else
                        corpseOwner:sendTextMessage(MESSAGE_INFO_DESCR, text .." ".. (amount > 1 and amount or itemArticle) .. " ".. itemName ..".")
                    end
                end
            end
        end
    end
end
ec:register(3)
local talkAction = TalkAction("!autoloot")
function talkAction.onSay(player, words, param, type)
    local split = param:splitTrimmed(",")
    local action = split[1]
    if not action then
        player:showTextDialog(8977, "Commands:" .. "\n\n"
            .. "!autoloot clear" .. "\n"
            .. "!autoloot list" .. "\n"
            .. "!autoloot add, itemName" .. "\n"
            .. "!autoloot remove, itemName".. "\n"
            .. "!autoloot gold".. "\n\n"
            .. "Number of slots: ".. "\n"
            .. autoloot.freeAccountLimit .." free account".. "\n"
            .. autoloot.premiumAccountLimit .." premium account")
        return false
    end
    if not table.contains({"clear", "list", "add", "remove", "gold"}, action) then
        player:showTextDialog(8977, "[AUTO LOOT] Commands:" .. "\n\n"
            .. "!autoloot clear" .. "\n"
            .. "!autoloot list" .. "\n"
            .. "!autoloot add, itemName" .. "\n"
            .. "!autoloot remove, itemName".. "\n"
            .. "!autoloot gold".. "\n\n"
            .. "Quantidade de slots: ".. "\n"
            .. autoloot.freeAccountLimit .." free account".. "\n"
            .. autoloot.premiumAccountLimit .." premium account")
        return false
    end
    -- !autoloot clear
    if action == "clear" then
        removePlayerAutoAlllootItem(player)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] Clean autoloot list.")
        return false
    -- !autoloot list
    elseif action == "list" then
        local items = getPlayerAutolootItems(player)
        if items then
            local limit = getPlayerLimit(player)
            if limit then
                local description = {string.format('[AUTO LOOT] Capacity: %d/%d ~\n\nList of items:\n-----------------------------', #items, limit)}
                for i, itemId in pairs(items) do
                    description[#description +1] = string.format("%d) %s", i, ItemType(itemId):getName())
                end
                player:showTextDialog(8977, table.concat(description, '\n'), false)
            end
        end
        return false
    end
    local function getItemType()
        local itemType = ItemType(split[2])
        if not itemType or itemType:getId() == 0 then
            itemType = ItemType(tonumber(split[2]) or 0)
            if not itemType or itemType:getId() == 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] The item %s does not exist!", split[2]))
                return false
            end
        end
        return itemType
    end
    -- !autoloot add, itemName
    if action == "add" then
        local itemType = getItemType()
        if itemType then
            local limits = getPlayerLimit(player)
            if limits then
                local items = getPlayerAutolootItems(player)
                if items then
                    if #items >= limits then
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Your autoloot only allows you to add %d items.", limits))
                        return false
                    end
                    if addPlayerAutolootItem(player, itemType:getId()) then
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Perfect, you added the autoloot list: %s", itemType:getName()))
                    else
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Item %s is already on the list!", itemType:getName()))
                    end
                end
            end
        end
        return false
    -- !autoloot remove, itemName
    elseif action == "remove" then
        local itemType = getItemType()
        if itemType then
            if removePlayerAutolootItem(player, itemType:getId()) then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Perfect, you removed it from the autoloot list: %s", itemType:getName()))
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[AUTO LOOT] Item %s is not in your list.", itemType:getName()))
            end
        end
        return false
    -- !autoloot gold
    elseif action == "gold" then
        player:setStorageValue(Storage.autolootGoldAtive, player:getStorageValue(Storage.autolootGoldAtive) == 1 and 0 or 1)
        local check = player:getStorageValue(Storage.autolootGoldAtive) == 1 and "activated" or "disabled"
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "[AUTO LOOT] You ".. check .." collecting money by autoloot.")
        return false
    end
    return false
end
talkAction:separator(" ")
talkAction:register()
local creatureEvent = CreatureEvent("autolootCleanCache")
function creatureEvent.onLogout(player)
    local items = getPlayerAutolootItems(player)
    if items then
        setPlayerAutolootItems(player, items)
        autolootCache[player:getGuid()] = nil
    end
    return true
end
 
Back
Top