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

HELP Autoloot system

dfs1

Member
Joined
Aug 27, 2011
Messages
82
Solutions
1
Reaction score
8
Good morning, I am installing an autoloot on my server, everything works, it adds objects to the list, deletes them but when killing them the monsters do not send the items to the backpack, could you help me? I provide the script.

Global.lua
Code:
-- AutoLoot config
    AUTO_LOOT_MAX_ITEMS = 5

    -- Reserved storage
    AUTOLOOT_STORAGE_START = 10000
    AUTOLOOT_STORAGE_END = AUTOLOOT_STORAGE_START + AUTO_LOOT_MAX_ITEMS
-- AutoLoot config end


TalkAction

Lua:
local autoloot = TalkAction("!loot")

function autoloot.onSay(player, words, param)
    local split = param:split(",")

    local action = split[1]
    if action == "add" then
        local item = split[2]:gsub("%s+", "", 1)
        local itemType = ItemType(item)
        if itemType:getId() == 0 then
            itemType = ItemType(tonumber(item))
            if itemType:getId() == 0 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There is no item with that id or name.")
                return false
            end
        end

        local itemName = tonumber(split[2]) and itemType:getName() or item
        local size = 0
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            local storage = player:getStorageValue(i)
            if size == AUTO_LOOT_MAX_ITEMS then
                 player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The list is full, please remove from the list to make some room..")
                break
            end

            if storage == itemType:getId() then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "s already in the list.")
                break
            end

            if storage <= 0 then
                player:setStorageValue(i, itemType:getId())
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "has been added to the list.")
                break
            end

            size = size + 1
        end
    elseif action == "remove" then
        local item = split[2]:gsub("%s+", "", 1)
        local itemType = ItemType(item)
        if itemType:getId() == 0 then
            itemType = ItemType(tonumber(item))
            if itemType:getId() == 0 then
                            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "here is no item with that id or name.")
                return false
            end
        end

        local itemName = tonumber(split[2]) and itemType:getName() or item
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            if player:getStorageValue(i) == itemType:getId() then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, " has been removed from the list.")
                player:setStorageValue(i, 0)
                return false
            end
        end
     
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, " was not founded in the list.")
    elseif action == "list" then
        local text = "-- Auto Loot List --\n"
        local count = 1
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            local storage = player:getStorageValue(i)
            if storage > 0 then
                text = string.format("%s%d. %s\n", text, count, ItemType(storage):getName())
                count = count + 1
            end
        end

        if text == "" then
            text = "Empty"
        end
 
        player:showTextDialog(1950, text, false)
    elseif action == "clear" then
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            player:setStorageValue(i, 0)
        end

        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, " he autoloot list has been cleared.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, " Use the commands: !loot {add, remove, list, clear}")
    end

    return false
end

autoloot:separator(" ")
autoloot:register()

Creaturescript


Lua:
local function scanContainer(cid, position)
    local player = Player(cid)
    if not player then
        return
    end
    local corpse = Tile(position):getTopDownItem()
    if not corpse or not corpse:isContainer() then
        return
    end
    if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then
        for a = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(a)
            if containerItem then
                for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(b) == containerItem:getId() then
                        containerItem:moveTo(player)
                    end
                end
        if player:isPremium() then
                if isItemStackable(containerItem:getId()) then
                                        local g = containerItem:getCount()
                                        local g2 = containerItem:getCount() * 1.1 / 10
                                        local g3 = containerItem:getCount()
                                        local g4 = (containerItem:getCount() * 100) * 1.1 / 10
                                        local g5 = containerItem:getCount()
                                        local g6 = (containerItem:getCount() * 1000) * 1.1 / 10

                    if containerItem:getId() == 2148 then
                        containerItem:remove()
                        doPlayerSetBalance(player, getPlayerBalance(player) + (containerItem:getCount() * 1.1))
                    player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Gold Coins: "..g.."(+"..g2..").")

                    end
                    if containerItem:getId() == 2152 then
                        containerItem:remove()
                        doPlayerSetBalance(player, getPlayerBalance(player) + ((containerItem:getCount() * 100) * 1.1))
                        player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Platinum Coins: "..g3.."(+"..g4.."Gold Coin).")


                    end
                    if containerItem:getId() == 2160 then
                        containerItem:remove()
                        doPlayerSetBalance(player, getPlayerBalance(player) + ((containerItem:getCount() * 1000) * 1.1))
                    player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Crystal Coins: "..g5.."(+"..g6.."Gold Coin).")


                    end
            end
        end
     
        if not player:isPremium() then
                if isItemStackable(containerItem:getId()) then

                    if containerItem:getId() == 2148 then
                        containerItem:remove()
                        doPlayerSetBalance(player, getPlayerBalance(player) + containerItem:getCount())
                    player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Gold Coins: "..g.."(+0).")
                    end
                    if containerItem:getId() == 2152 then
                        containerItem:remove()
                        doPlayerSetBalance(player, getPlayerBalance(player) + (containerItem:getCount() * 100))
                        player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Platinum Coins: "..g3.."(+0).")
                    end
                    if containerItem:getId() == 2160 then
                        containerItem:remove()
                        doPlayerSetBalance(player, getPlayerBalance(player) + (containerItem:getCount() * 1000))
                    player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Crystal Coins: "..g5.."(+0).")
                    end
            end
        end
         
         
         
         
        end
    end
end
end

local AutoLoot = CreatureEvent("AutoLoot")
function AutoLoot.onKill(player, target)
    if not target:isMonster() then
        return true
    end
    addEvent(scanContainer, 100, player:getId(), target:getPosition())
    return true
end


AutoLoot:register()
 
Last edited:
Solution
You need to register the creatureevent to the player, otherwise the onKill method will never trigger.

Lua:
local creatureevent = CreatureEvent("login_RegisterAutoloot")

function creatureevent.onLogin(player)
    player:registerEvent("AutoLoot")
    return true
end

creatureevent:register()
You need to register the creatureevent to the player, otherwise the onKill method will never trigger.

Lua:
local creatureevent = CreatureEvent("login_RegisterAutoloot")

function creatureevent.onLogin(player)
    player:registerEvent("AutoLoot")
    return true
end

creatureevent:register()
 
Solution
xiniki, you are the best there is no doubt thank you there are few who help, I wait for your game :p
Post automatically merged:

Captura.PNG


I felt so good, until I put party and this happened. @Xikini
 
Last edited:
xiniki, you are the best there is no doubt thank you there are few who help, I wait for your game :p
Post automatically merged:

View attachment 69027


I felt so good, until I put party and this happened. @Xikini
This isn't specific to being in a party, this is due to one of the characters not having premium, therefore going into an if statement you never triggered before.

Feels like someone inexperienced modified the original autoloot system before you found it

This should fix it.
Lua:
local function scanContainer(cid, position)
    local player = Player(cid)
    if not player then
        return
    end
    local corpse = Tile(position):getTopDownItem()
    if not corpse or not corpse:isContainer() then
        return
    end
    if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then
        for a = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(a)
            if containerItem then
                for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(b) == containerItem:getId() then
                        containerItem:moveTo(player)
                    end
                end
                if isItemStackable(containerItem:getId()) then
                    local g = containerItem:getCount()
                    local g2 = containerItem:getCount() * 1.1 / 10
                    local g3 = containerItem:getCount()
                    local g4 = (containerItem:getCount() * 100) * 1.1 / 10
                    local g5 = containerItem:getCount()
                    local g6 = (containerItem:getCount() * 1000) * 1.1 / 10
   
                    if player:isPremium() then
                        if containerItem:getId() == 2148 then
                            containerItem:remove()
                            doPlayerSetBalance(player, getPlayerBalance(player) + (containerItem:getCount() * 1.1))
                            player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Gold Coins: "..g.."(+"..g2..").")
                        end
                        if containerItem:getId() == 2152 then
                            containerItem:remove()
                            doPlayerSetBalance(player, getPlayerBalance(player) + ((containerItem:getCount() * 100) * 1.1))
                            player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Platinum Coins: "..g3.."(+"..g4.."Gold Coin).")
                        end
                        if containerItem:getId() == 2160 then
                            containerItem:remove()
                            doPlayerSetBalance(player, getPlayerBalance(player) + ((containerItem:getCount() * 1000) * 1.1))
                            player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Crystal Coins: "..g5.."(+"..g6.."Gold Coin).")
                        end
                    else
                        if containerItem:getId() == 2148 then
                            containerItem:remove()
                            doPlayerSetBalance(player, getPlayerBalance(player) + containerItem:getCount())
                            player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Gold Coins: "..g.."(+0).")
                        end
                        if containerItem:getId() == 2152 then
                            containerItem:remove()
                            doPlayerSetBalance(player, getPlayerBalance(player) + (containerItem:getCount() * 100))
                            player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Platinum Coins: "..g3.."(+0).")
                        end
                        if containerItem:getId() == 2160 then
                            containerItem:remove()
                            doPlayerSetBalance(player, getPlayerBalance(player) + (containerItem:getCount() * 1000))
                            player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Crystal Coins: "..g5.."(+0).")
                        end
                    end
                end
            end
        end
    end
end
 
Back
Top