Resources Scripts
TFS 1.x Auto Loot System - Tibia OTS

How Looks commands in game:
!autoloot add, itemId or name
!autoloot remove, itemId or name
!autoloot show
!autoloot clear

Add code to data/global.lua

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

Add code to talkactions/talkactions.xml

<talkaction words="!autoloot" separator=" " script="autoloot.lua"/>

Make file in talkactions/scripts called autoloot.lua and paste

function 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_STATUS_CONSOLE_BLUE, "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_STATUS_CONSOLE_BLUE, "The list is full, please remove from the list to make some room.")
                break
            end

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

            if storage <= 0 then
                player:setStorageValue(i, itemType:getId())
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." 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_STATUS_CONSOLE_BLUE, "There 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_STATUS_CONSOLE_BLUE, itemName .." has been removed from the list.")
                player:setStorageValue(i, 0)
                return false
            end
        end

        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." was not founded in the list.")
    elseif action == "show" 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_STATUS_CONSOLE_BLUE, "The autoloot list has been cleared.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Use the commands: !autoloot {add, remove, show, clear}")
    end

    return false
end

Add to creaturescripts/creaturescripts.xml

<event type="kill" name="AutoLoot" script="autoloot.lua" />

Create new file in creaturescripts/scripts called autoloot.lua and paste

local function scanContainer(cid, position)
    local player = Player(cid)
    if not player then
        return
    end

    local corpse = Tile(position):getTopDownItem()
    if not corpse 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
            end
        end
    end
end

function onKill(player, target)
    if not target:isMonster() then
        return true
    end

    addEvent(scanContainer, 100, player:getId(), target:getPosition())
    return true
end

Go to creaturescripts/scripts/login.lua and save

player:registerEvent("AutoLoot")
http://3.1m.yt/Zwo99Sdx.png ```` How Looks commands in game: !autoloot add, itemId or name !autoloot remove, itemId or name !autoloot show !autoloot clear ```` Add code to data/global.lua ```` -- 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 ```` Add code to talkactions/talkactions.xml ```` &lt;talkaction words=&quot;!autoloot&quot; separator=&quot; &quot; script=&quot;autoloot.lua&quot;/&gt; ```` Make file in talkactions/scripts called autoloot.lua and paste ```` function onSay(player, words, param) local split = param:split(&quot;,&quot;) local action = split[1] if action == &quot;add&quot; then local item = split[2]:gsub(&quot;%s+&quot;, &quot;&quot;, 1) local itemType = ItemType(item) if itemType:getId() == 0 then itemType = ItemType(tonumber(item)) if itemType:getId() == 0 then player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, &quot;There is no item with that id or name.&quot;) 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_STATUS_CONSOLE_BLUE, &quot;The list is full, please remove from the list to make some room.&quot;) break end if storage == itemType:getId() then player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName ..&quot; is already in the list.&quot;) break end if storage &lt;= 0 then player:setStorageValue(i, itemType:getId()) player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName ..&quot; has been added to the list.&quot;) break end size = size + 1 end elseif action == &quot;remove&quot; then local item = split[2]:gsub(&quot;%s+&quot;, &quot;&quot;, 1) local itemType = ItemType(item) if itemType:getId() == 0 then itemType = ItemType(tonumber(item)) if itemType:getId() == 0 then player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, &quot;There is no item with that id or name.&quot;) 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_STATUS_CONSOLE_BLUE, itemName ..&quot; has been removed from the list.&quot;) player:setStorageValue(i, 0) return false end end player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName ..&quot; was not founded in the list.&quot;) elseif action == &quot;show&quot; then local text = &quot;-- Auto Loot List --\n&quot; local count = 1 for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do local storage = player:getStorageValue(i) if storage &gt; 0 then text = string.format(&quot;%s%d. %s\n&quot;, text, count, ItemType(storage):getName()) count = count + 1 end end if text == &quot;&quot; then text = &quot;Empty&quot; end player:showTextDialog(1950, text, false) elseif action == &quot;clear&quot; then for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do player:setStorageValue(i, 0) end player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, &quot;The autoloot list has been cleared.&quot;) else player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, &quot;Use the commands: !autoloot {add, remove, show, clear}&quot;) end return false end ```` Add to creaturescripts/creaturescripts.xml ```` &lt;event type=&quot;kill&quot; name=&quot;AutoLoot&quot; script=&quot;autoloot.lua&quot; /&gt; ```` Create new file in creaturescripts/scripts called autoloot.lua and paste ```` local function scanContainer(cid, position) local player = Player(cid) if not player then return end local corpse = Tile(position):getTopDownItem() if not corpse 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 end end end end function onKill(player, target) if not target:isMonster() then return true end addEvent(scanContainer, 100, player:getId(), target:getPosition()) return true end ```` Go to creaturescripts/scripts/login.lua and save ```` player:registerEvent(&quot;AutoLoot&quot;) ````
1.05k
0
1
live preview
enter atleast 20 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft