• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

[TFS 0.4, 8.6] AutoLoot Error

jeffaklumpen

Member
Joined
Jan 20, 2022
Messages
74
Solutions
2
Reaction score
14
GitHub
jeffaklumpen
I'm using a AutoLoot mod and it's working as intended. The same error message keeps appearing in the console however and I have no idea what's causing it and it doesn't appear to cause any issues in the game from what I have seen. Does anyone know what's causing this and how to solve it?

Namnlös.png

Here's the code I'm using:

XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="Autoloot Revolution BT" version="1.0" author="Millhiore BT" contact="none.com" enabled="yes">
<config name="AutolootRevolutionBT">
<![CDATA[
[email protected] You configurations:
autolootConfig = {}
autolootConfig.storageItems = 27000
autolootConfig.blockMonsters = {}
autolootConfig.goldToBank = false
autolootConfig.goldBankAnimation = false
autolootConfig.distanceLooting = 7
autolootConfig.freeSlots = 3
autolootConfig.premiumSlots = 6
autolootConfig.vipStorage = {0,0}
autolootConfig.playerLevel = 8
autolootConfig.corpseEffect = CONST_ME_NONE
autolootConfig.golds = {2148, 2152, 2160}
autolootConfig.tittle = "Options: add, remove, clear.\n\nExample: !autoloot add, gold coin\n\nYou can only add stackable items to the autoloot list.\n\n"
autolootConfig.notHaveCapDrop = false
[email protected] getPlayerPremiumEnabled(cid)
--# Return boolean
--# Create by Millhiore BT
function getPlayerPremiumEnabled(cid)
    if getConfigValue("freePremium") then
        return true
    end
    return getPlayerPremiumDays(cid) > 0
end
[email protected] getPlayerAutolootVip(cid)
--# Return boolean
--# Create by Millhiore BT
function getPlayerAutolootVip(cid)
    if autolootConfig.vipStorage[1] > 0 then
        if autolootConfig.vipStorage[2] > 0 then
            return getPlayerStorageValue(cid, autolootConfig.vipStorage[1]) == autolootConfig.vipStorage[2]
        else
            return getPlayerStorageValue(cid, autolootConfig.vipStorage[1]) >= os.time()
        end
    end
    return true
end
[email protected] getPositionDistance(position, positionEx)
--# Return number
--# Create by Millhiore BT
function getPositionDistance(position, positionEx)
    return math.max(math.max(math.abs(position.x - positionEx.x), math.abs(position.y - positionEx.y)), math.abs(position.z - positionEx.z))
end
[email protected] getPositionCorpse(pos [, itemid])
--# Return thing/nil
--# Create by Millhiore BT
function getPositionCorpse(pos, itemid)
    local tile = getTileInfo(pos)
    for index = 0, tile.things do
        pos.stackpos = index
        local corpse = getThingFromPos(pos, false)
        if corpse.itemid > 1 and isCorpse(corpse.uid) then
            local itemid = itemid or corpse.itemid
            if corpse.itemid == itemid then
                return corpse
            end
        end
    end
end
[email protected] getContainerItems(uid [, array])
--# Return array
--# Create by Millhiore BT
function getContainerItems(container, array, haveCap)
    array = array or {}
    haveCap = haveCap or false
    if not isContainer(container.uid) or getContainerSize(container.uid) == 0 then
        array[#array +1] = container
    else
        local size = getContainerSize(container.uid)
        haveCap = (getContainerCap(container.uid) -size) > 0
        for slot = 0, (size -1) do
            local item = getContainerItem(container.uid, slot)
            if item.itemid > 1 then
                getContainerItems(item, array, haveCap)
            end
        end
    end
    return #array >= 1 and array, haveCap
end
[email protected] getContainerItemsById(array/uid, itemid)
--# Return array
--# Create by Millhiore BT
function getContainerItemsById(container, itemid)
    local founds = {}
    local items = not container.uid and container or getContainerItems(container)
    for index, item in pairs(items) do
        if item.itemid == itemid then
            founds[#founds +1] = item
        end
    end
    return #founds >= 1 and founds
end
[email protected] doPlayerAddItemStackable(cid, itemid, count)
--# Return boolean
--# Create by Millhiore BT
function doPlayerAddItemStackable(cid, itemid, count)
    local container = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
    if container.itemid > 1 then
        local items = getContainerItemsById(container, itemid)
        if not items then
            return doPlayerAddItem(cid, itemid, count)
        else
            local piles = #items
            for index, item in pairs(items) do
                if item.type < 100 then
                    local sum = item.type + count
                    local result = doTransformItem(item.uid, itemid, sum)
                    if sum <= 100 then
                        return result
                    else
                        return doPlayerAddItem(cid, itemid, sum - 100)
                    end
                else
                    piles = piles - 1
                    if piles == 0 then
                        return doPlayerAddItem(cid, itemid, count)
                    end
                end
            end
        end
    end
    return false
end
[email protected] getContainerMoneys(items)
--# Return array/false
--# Create by Millhiore BT
function getContainerMoneys(items)
    local moneys = {}
    for slot, item in pairs(items) do
        if isInArray(autolootConfig.golds, item.itemid) then
            moneys[#moneys +1] = item
        end
    end
    return #moneys > 0 and moneys
end
[email protected] doCorpseAutoloot(cid, pos itemid)
--# Return boolean/nil
--# Create by Millhiore BT
function doCorpseAutoloot(cid, pos, itemid, moneys)
    if not getPlayerAutolootVip(cid) or getPositionDistance(getThingPosition(cid), pos) > autolootConfig.distanceLooting
    or getPlayerLevel(cid) < autolootConfig.playerLevel then
        return nil
    end
    local corpse = getPositionCorpse(pos, itemid)
    if corpse and isContainer(corpse.uid) then
        local items, haveCap = moneys or getContainerItems(corpse)
        local sendEffect = false
        if items then
            for slot, item in pairs(items) do
                if isInArray(getPlayerAutolootItems(cid), item.itemid) then
                    sendEffect = true
                    local removeIt = false
                    local goldToBank = autolootConfig.goldToBank and isInArray(autolootConfig.golds, item.itemid)
                    if not goldToBank then
                        if not haveCap and autolootConfig.notHaveCapDrop then
                            return doCorpseAutoloot(cid, pos, itemid, getContainerMoneys(items))
                        end
                        if isItemStackable(item.itemid) then
                            removeIt = doPlayerAddItemStackable(cid, item.itemid, item.type)
                        else
                            removeIt = doPlayerAddItem(cid, item.itemid)
                        end
                    else
                        local add = (getItemInfo(item.itemid).worth * item.type)
                        removeIt = doPlayerSetBalance(cid, getPlayerBalance(cid) + add)
                        if autolootConfig.goldBankAnimation then
                            doSendAnimatedText(pos, string.format("+%u gps", add), TEXTCOLOR_YELLOW, cid)
                        end
                    end
                    if removeIt then
                        doRemoveItem(item.uid)
                    end
                end
            end
            if sendEffect then
                doSendMagicEffect(pos, autolootConfig.corpseEffect, cid)
            end
            return true
        end
    end
end
[email protected] getPlayerAutolootItems(cid)
--# Return array
--# Create by Millhiore BT
function getPlayerAutolootItems(cid)
    local array = {}
    local content = tostring(getPlayerStorageValue(cid, autolootConfig.storageItems))
    for itemid in string.gmatch(content, "(%d+):") do
        array[#array +1] = tonumber(itemid)
    end
    return array
end
[email protected] getPlayerAutolootItem(cid, itemid)
--# Return number/nil
--# Create by Millhiore BT
function getPlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    for index, id in pairs(autolootItems) do
        if itemid == id then
            return index
        end
    end
end
[email protected] setPlayerAutolootItems(cid [, array])
--# Return boolean
--# Create by Millhiore BT
function setPlayerAutolootItems(cid, array)
    local array = array or {}
    local content = "&"
    for index, itemid in pairs(array) do
        content = string.format("%s%u:", content, itemid)
    end
    return setPlayerStorageValue(cid, autolootConfig.storageItems, content)
end
[email protected] addPlayerAutolootItem(cid, itemid)
--# Return boolean
--# Create by Millhiore BT
function addPlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    local found = getPlayerAutolootItem(cid, itemid)
    if not found then
        autolootItems[#autolootItems +1] = itemid
        return setPlayerAutolootItems(cid, autolootItems)
    end
end
[email protected] removePlayerAutolootItem(cid, itemid)
--# Return boolean/nil
--# Create by Millhiore BT
function removePlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    local found = getPlayerAutolootItem(cid, itemid)
    if found then
        table.remove(autolootItems, found)
        return setPlayerAutolootItems(cid, autolootItems)
    end
end
[email protected] showPlayerAutoloot(cid)
--# Return boolean
--# Create by Millhiore BT
function showPlayerAutoloot(cid)
    local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
    local content = string.format("%sYou available slots: %u\n\n%s", autolootConfig.tittle, maxItems, "Your autoloot items:\n")
    local autolootItems = getPlayerAutolootItems(cid)
    for index, itemid in pairs(autolootItems) do
        local it = getItemInfo(itemid)
        content = string.format("%s %c %s\n", content, 155, it.name)
    end
    return doShowTextDialog(cid, 2529, content)
end
[email protected] showPlayerAutolootHelp(cid)
--# Return boolean
--# Create by Millhiore BT
function showPlayerAutolootHelp(cid)
    local content = autolootConfig.tittle .. "For you info:\n"
    for key, value in pairs(autolootConfig) do
        if not isInArray({"storageItems", "blockMonsters", "vipStorage", "golds", "tittle"}, key) then
            content = string.format("%s%c %s: %s\n", content, 155, tostring(key), tostring(value))
        end
    end
    return doShowTextDialog(cid, 2529, content)
end
]]>
</config>
<event type="login" name="AutolootRBTLogin" event="script">
<![CDATA[
function onLogin(cid)
    local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
    local autolootItems = getPlayerAutolootItems(cid)
    if #autolootItems > maxItems then
        for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
            table.remove(autolootItems, index)
        end
        setPlayerAutolootItems(cid, autolootItems)
        doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
    end
    registerCreatureEvent(cid, "AutolootRBTCombat")
    return true
end
]]>
</event>
<event type="death" name="AutolootRBTDeath" event="script">
<![CDATA[
domodlib("AutolootRevolutionBT")
function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    local position = getThingPosition(cid)
    if corpse.itemid > 1 then
        addEvent(doCorpseAutoloot, 100, killer, position, corpse.itemid)
    end
    return true
end
]]>
</event>
<event type="combat" name="AutolootRBTCombat" event="script">
<![CDATA[
if isPlayer(cid) and isMonster(target) then
    registerCreatureEvent(target, "AutolootRBTDeath")
end
return true
]]>
</event>
<talkaction words="!autoloot;/autoloot" event="buffer">
<![CDATA[
domodlib("AutolootRevolutionBT")
local split = string.explode(param, ",") or {}
local action = tostring(split[1]):lower()
local name = tostring(split[2])
local itemid = getItemIdByName(name, false)
local it = getItemInfo(itemid and itemid or 0)
local position = getThingPosition(cid)
if action == "add" then
    if not it then
        doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
    else
        local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
        local autolootItems = getPlayerAutolootItems(cid)
        if #autolootItems > maxItems then
            for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
                table.remove(autolootItems, index)
            end
            setPlayerAutolootItems(cid, autolootItems)
            doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
        elseif #autolootItems == maxItems then
            doPlayerSendCancel(cid, string.format("Your maximum limit is %u items, you must eliminate one to add another.", maxItems))
        elseif addPlayerAutolootItem(cid, itemid) then
            doPlayerSendCancel(cid, string.format("You added the item %s in the list.", name))
        else
            doSendMagicEffect(position, CONST_ME_POFF, cid)
            doPlayerSendCancel(cid, string.format("This item %s already in the list.", name))
        end
    end
elseif action == "remove" then
    if not it then
        doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
    else
        if removePlayerAutolootItem(cid, itemid) then
            doPlayerSendCancel(cid, string.format("You removed the item %s from the list.", name))
        else
            doPlayerSendCancel(cid, string.format("This item %s is not in the list.", name))
        end
    end
elseif action == "help" then
    showPlayerAutolootHelp(cid)
elseif action == "clear" then
    setPlayerAutolootItems(cid)
    doPlayerSendCancel(cid, "The list of items is now empty.")
else
    showPlayerAutoloot(cid)
end
return true
]]>
</talkaction>
</mod>
 

Error 502

Member
Joined
Sep 25, 2022
Messages
54
Solutions
1
Reaction score
19
Location
Chile
for now you could use this xd I used this in 8.6 tfs 0.4
I think he did not take the coins, but the rest works
hope you can solve your problem
could you compare it, and fix it your script

XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="Loot System" version="1.0" author="Vodkart And Mkalo" contact="none.com" enabled="yes">
<config name="Loot_func"><![CDATA[

        info = {
            OnlyPremium = true,
            AutomaticDeposit = true,
            BlockMonsters = {},
            BlockItemsList = {2123,2515}
            }

function setPlayerStorageTable(cid, storage, tab)
    local tabstr = "&"
    for i,x in pairs(tab) do
            tabstr = tabstr .. i .. "," .. x .. ";"
    end
    setPlayerStorageValue(cid, storage, tabstr:sub(1, #tabstr-1))
end
function getPlayerStorageTable(cid, storage)
    local tabstr = getPlayerStorageValue(cid, storage)
    local tab = {}
    if type(tabstr) ~= "string" then
            return {}
    end
    if tabstr:sub(1,1) ~= "&" then
            return {}
    end
    local tabstr = tabstr:sub(2, #tabstr)
    local a = string.explode(tabstr, ";")
    for i,x in pairs(a) do
            local b = string.explode(x, ",")
            tab[tonumber(b[1]) or b[1]] = tonumber(b[2]) or b[2]
    end
    return tab
end

function isInTable(cid, item)
         for _,i in pairs(getPlayerStorageTable(cid, 27000))do
             if tonumber(i) == tonumber(item) then
                return true
             end
         end
return false
end
function addItemTable(cid, item)
         local x = {}
               for i = 1,#getPlayerStorageTable(cid, 27000) do
                   table.insert(x,getPlayerStorageTable(cid, 27000)[i])
               end
               if x ~= 0 then
                  table.insert(x,tonumber(item))
                  setPlayerStorageTable(cid, 27000, x)
               else
                   setPlayerStorageTable(cid, 27000, {item})
               end
end
function removeItemTable(cid, item)
         local x = {}
               for i = 1,#getPlayerStorageTable(cid, 27000) do
                   table.insert(x,getPlayerStorageTable(cid, 27000)[i])
               end
               for i,v in ipairs(x) do
                   if tonumber(v) == tonumber(item) then
                   table.remove(x,i)
               end
               end
         return setPlayerStorageTable(cid, 27000, x)
end
function ShowItemsTabble(cid)
local str,n = "-- My Loot List --\n\n",0
for i = 1,#getPlayerStorageTable(cid, 27000) do
n = n + 1
str = str..""..n.." - "..getItemNameById(getPlayerStorageTable(cid, 27000)[i]).."\n"
end
return doShowTextDialog(cid, 2529, str)
end
function getContainerItems(containeruid)
    local items = {}
    local containers = {}
    if type(getContainerSize(containeruid)) ~= "number" then
            return false
    end
    for slot = 0, getContainerSize(containeruid)-1 do
            local item = getContainerItem(containeruid, slot)
            if item.itemid == 0 then
                    break
            end
            if isContainer(item.uid) then
                    table.insert(containers, item.uid)
            end
            table.insert(items, item)
    end
    if #containers > 0 then
            for i,x in ipairs(getContainerItems(containers[1])) do
                    table.insert(items, x)
            end
            table.remove(containers, 1)
    end   
    return items
end
function getItemsInContainerById(container, itemid) -- Function By Kydrai
            local items = {}
            if isContainer(container) and getContainerSize(container) > 0 then
                            for slot=0, (getContainerSize(container)-1) do
                                            local item = getContainerItem(container, slot)
                                            if isContainer(item.uid) then
                                                            local itemsbag = getItemsInContainerById(item.uid, itemid)
                                                            for i=0, #itemsbag do
                                                                            table.insert(items, itemsbag[i])
                                                            end
                                            else
                                                            if itemid == item.itemid then
                                                                            table.insert(items, item.uid)
                                                            end
                                            end
                            end
            end
            return items
end
function doPlayerAddItemStacking(cid, itemid, quant) -- by mkalo
    local item = getItemsInContainerById(getPlayerSlotItem(cid, 3).uid, itemid)
    local piles = 0
    if #item > 0 then
            for i,x in pairs(item) do
                    if getThing(x).type < 100 then
                            local it = getThing(x)
                            doTransformItem(it.uid, itemid, it.type+quant)
                            if it.type+quant > 100 then
                                    doPlayerAddItem(cid, itemid, it.type+quant-100)
                            end
                    else
                           piles = piles+1
                    end
            end
    else
            return doPlayerAddItem(cid, itemid, quant)
    end
    if piles == #item then
            doPlayerAddItem(cid, itemid, quant)
    end
end
function AutomaticDeposit(cid,item,n)
local deposit = item == tonumber(2160) and (n*10000) or tonumber(item) == 2152 and (n*100) or (n*1)
return doPlayerDepositMoney(cid, deposit)
end
function corpseRetireItems(cid, pos)
    local check = false
    for i = 0, 255 do
    pos.stackpos = i
    tile = getTileThingByPos(pos)
        if tile.uid > 0 and isCorpse(tile.uid) then
            check = true break
        end
end
        if check == true then
            local items = getContainerItems(tile.uid)
                for i,x in pairs(items) do
                        if isInArray(getPlayerStorageTable(cid, 27000), tonumber(x.itemid)) then
                                if isItemStackable(x.itemid) then
                        doPlayerAddItemStacking(cid, x.itemid, x.type)
                        if info.AutomaticDeposit == true and isInArray({"2148","2152","2160"},tonumber(x.itemid)) then
                        AutomaticDeposit(cid,x.itemid,x.type)
                        end
                                else
                                        doPlayerAddItem(cid, x.itemid)
                                end
                                    doRemoveItem(x.uid)
                        end
                end
        end
end
]]></config>
<event type="login" name="LootLogin" event="script"><![CDATA[
function onLogin(cid)
registerCreatureEvent(cid, "MonsterAttack")
return true
end]]></event>
<event type="death" name="LootEventDeath" event="script"><![CDATA[
domodlib('Loot_func')
    function onDeath(cid, corpse, deathList)
    local killer,pos = deathList[1],getCreaturePosition(cid)
    addEvent(corpseRetireItems,1,killer,pos)
return true
end]]></event>
<event type="combat" name="MonsterAttack" event="script"><![CDATA[
domodlib('Loot_func')
        if isPlayer(cid) and isMonster(target) and not isInArray(info.BlockMonsters,string.lower(getCreatureName(target))) then
            registerCreatureEvent(target, "LootEventDeath")
                        end
return true]]></event>
<talkaction words="!autoloot;/autoloot" event="buffer"><![CDATA[
domodlib('Loot_func')
local t = string.explode(string.lower(param), ",")
if info.OnlyPremium == true and not isPremium(cid) then
doPlayerSendCancel(cid, "you must be a premium account.") return true
elseif not t[1] then
ShowItemsTabble(cid) return true
elseif tonumber(t[1]) or tonumber(t[2]) then
doPlayerSendCancel(cid, "enter!autoloot add,name or !autoloot remove,name") return true
elseif isInArray({"add","remove"}, tostring(t[1])) then
local func,check = tostring(t[1]) == "add" and addItemTable or removeItemTable, tostring(t[1]) == "add" and true or false
local item = getItemIdByName(tostring(t[2]), false)
if not item then
doPlayerSendCancel(cid, "This item does not exist.") return true
elseif check == true and isInArray(info.BlockItemsList, item) then
doPlayerSendCancel(cid, "You can not add this item in the list!") return true
elseif isInTable(cid, item) == check then
doPlayerSendCancel(cid, "This Item "..(check == true and "already" or "is not").." in your list.") return true
end
func(cid, item)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,check == true and "you added the item "..t[2].." in the list" or "you removed the item "..t[2].." from the list") return true
end
return true]]></talkaction>
</mod>
 

Svira

Member
Joined
Jan 27, 2008
Messages
206
Solutions
7
Reaction score
20
Add in ur mods/script:

aloot.lua
Lua:
function onLogin(cid)
    registerCreatureEvent(cid, "aloot_kill")
    return true
end
 
local stor = 7575
 
function autoloot(cid, target, pos)
    local function doStack(cid, itemid, new)
        local count = getPlayerItemCount(cid, itemid)
        if (count > 100) then
            count = count - math.floor(count / 100) * 100
        end
        local newCount = count + new
        if (count ~= 0) then
            local find = getPlayerItemById(cid, true, itemid, count).uid
            if (find > 0) then
                doRemoveItem(find)
            else
                newCount = new
            end
        end
        local item = doCreateItemEx(itemid, newCount)
        doPlayerAddItemEx(cid, item, true)
    end
 
    local function scanContainer(cid, uid, list)
        for k = (getContainerSize(uid) - 1), 0, -1 do
            local tmp = getContainerItem(uid, k)
            if (isInArray(list, tmp.itemid)) then
                if isItemStackable(tmp.itemid) and (getPlayerItemCount(cid, tmp.itemid) > 0) then
                    doStack(cid, tmp.itemid, tmp.type)
                else
                    local item = doCreateItemEx(tmp.itemid, tmp.type)
                    doPlayerAddItemEx(cid, item, true)
                end
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Looted ' .. tmp.type .. ' ' .. getItemNameById(tmp.itemid) .. '.')
                doRemoveItem(tmp.uid)
            elseif isContainer(tmp.uid) then
                scanContainer(cid, tmp.uid, list)
            end
        end
    end
 
    local items = {}
    for i = getTileInfo(pos).items, 1, -1 do
        pos.stackpos = i
        table.insert(items, getThingFromPos(pos))
    end
 
    if (#items == 0) then
        return
    end
 
    local corpse = -1
    for _, item in ipairs(items) do
        local name = getItemName(item.uid):lower()
        if name:find(target:lower()) then
            corpse = item.uid
            break
        end
    end
 
    if (corpse ~= -1) and isContainer(corpse) then
        scanContainer(cid, corpse, tostring(getPlayerStorageValue(cid, stor)):gsub('_', ''):explode(','))
    end
end
 
function onKill(cid, target, lastHit)
    if not isPlayer(target) then
        local infos = getPlayerStorageValue(cid, stor)
        if (infos == -1) then
            return true
        end
        local list = tostring(infos):explode(',')
        if (#list == 0) then
            return true
        end
        addEvent(autoloot, 150, cid, getCreatureName(target), getCreaturePosition(target))
    end
    return true
end
in talkactions auto loot.lua:
Code:
function ExistItemByName(name)
    local items = io.open("data/items/items.xml", "r"):read("*all")
    local get = items:match('name="' .. name ..'"')
    if get == nil or get == "" then
        return false
    end
    return true
end

local function getPlayerList(cid)
    local tab = {}
    if getPlayerStorageValue(cid, 04420021) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 04420021))
    end
    if getPlayerStorageValue(cid, 04420031) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 04420031))
    end
    if getPlayerStorageValue(cid, 04420041) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 04420041))
    end
    if getPlayerStorageValue(cid, 04420051) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 04420051))
    end
    if #tab > 0 then
        return tab
    end
    return false
end

local function addToList(cid, name)
    local itemid = getItemIdByName(name)
    if getPlayerList(cid) and isInArray(getPlayerList(cid), itemid) then
        return false
    end
    if getPlayerStorageValue(cid, 04420021) == -1 then
        return doPlayerSetStorageValue(cid, 04420021, itemid)
    elseif getPlayerStorageValue(cid, 04420031) == -1 then
        return doPlayerSetStorageValue(cid, 04420031, itemid)
    elseif getPlayerStorageValue(cid, 04420041) == -1 then   
        return doPlayerSetStorageValue(cid, 04420041, itemid)
    elseif getPlayerStorageValue(cid, 04420051) == -1 then
        return doPlayerSetStorageValue(cid, 04420051, itemid)
    end
end

local function removeFromList(cid, name)
    local itemid = getItemIdByName(name)
    if getPlayerStorageValue(cid, 04420021) == itemid then
        return doPlayerSetStorageValue(cid, 04420021, -1)
    elseif getPlayerStorageValue(cid, 04420031) == itemid then
        return doPlayerSetStorageValue(cid, 04420031, -1)
    elseif getPlayerStorageValue(cid, 04420041) == itemid then
        return doPlayerSetStorageValue(cid, 04420041, -1)
    elseif getPlayerStorageValue(cid, 04420051) == itemid then
        return doPlayerSetStorageValue(cid, 04420051, -1)
    end
    return false
end

function onSay(cid, words, param)
    if(not checkExhausted(cid, 666, 6)) then
        return true
    end
    if param == "" then
        local fi = getPlayerStorageValue(cid, 04420021) ~= -1 and getItemNameById(getPlayerStorageValue(cid, 04420021)) or ""
        local se = getPlayerStorageValue(cid, 04420031) ~= -1 and getItemNameById(getPlayerStorageValue(cid, 04420031)) or ""
        local th = not vip.hasVip(cid) and "Not available for free account" or getPlayerStorageValue(cid, 04420041) ~= -1 and getItemNameById(getPlayerStorageValue(cid, 04420041)) or ""
        local fo = not vip.hasVip(cid) and "Not available for free account" or getPlayerStorageValue(cid, 04420051) ~= -1 and getItemNameById(getPlayerStorageValue(cid, 04420051)) or ""
        local stt = getPlayerStorageValue(cid, 04421011) == 1 and "yes" or "no"
        local str = getPlayerStorageValue(cid, 04421001) == 1 and "yes" or "no"
        doPlayerPopupFYI(cid, "{Auto-Loot} ---Player Auto Loot Menu\n{Auto-Loot} ----------------\n{Auto-Loot} ---Collect money: "..stt..". To turn on/off: !autoloot gold \n{Auto-Loot} ---Collect unique items: "..str..". To turn on/off: !autoloot power\n{Auto-Loot} --Configuration of slots:\n{Auto-Loot} ---Slot 1: "..fi.."\n{Auto-Loot} ---Slot 2: "..se.."\n{Auto-Loot} ---Slot 3: "..th.."\n{Auto-Loot} ---Slot 4: "..fo.."\n{Auto-Loot} ---To add a new item to the slots: !autoloot add, <item name>\n{Auto-Loot} ---To remove an item from the slots: !autoloot remove, <item name>\n{Auto-Loot} ---To clear all slots use: !autoloot clear\n{Auto-Loot} ---For information on how much you've done using the money collection, use: !autoloot goldinfo\n\nIf your autoloot bugar use ! autoloot debug\n\n{Auto-Loot} ----------------")
        return true
    end
    
    local t = string.explode(param, ",")
    
    if t[1] == "power" then
        local check = getPlayerStorageValue(cid, 04421001) == -1 and "turn on" or "turn off"
        doPlayerSetStorageValue(cid, 04421001, getPlayerStorageValue(cid, 04421001) == -1 and 1 or -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You "..check.." the auto loot.")
    elseif t[1] == "gold" then
        local check = getPlayerStorageValue(cid, 04421011) == -1 and "turn on" or "turn off"
        doPlayerSetStorageValue(cid, 04421011, getPlayerStorageValue(cid, 04421011) == -1 and 1 or -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You "..check.." the collection of money.")
        doPlayerSetStorageValue(cid, 04421021, 0)
    elseif t[1] == "goldinfo" then
        local str = getPlayerStorageValue(cid, 04421011) == -1 and "The money collection system is turned off" or "The system has already collected "..getPlayerStorageZero(cid, 04421021).." gold coins"
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, str)
    elseif t[1] == "add" then
        if ExistItemByName(t[2]) then
            local item = getItemIdByName(t[2])
            if isInArray({2160, 2148, 2152}, item) then
                return doPlayerSendCancel(cid, "You cannot autoloot coins. To collect money use !autoloot gold")
            end
            if vip.hasVip(cid) then
                if getPlayerStorageValue(cid, 04420011) < 3 then
                    if addToList(cid, t[2]) then
                        doPlayerSetStorageValue(cid, 04420011, getPlayerStorageValue(cid, 04420011) + 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, t[2].." added to your auto loot list! To see your list say !autoloot list")
                    else
                        doPlayerSendCancel(cid, t[2].." is already on your list!")
                    end
                else
                    doPlayerSendCancel(cid, "Your list already has 4 items! You must remove one before adding another.")
                end
            else
                if getPlayerStorageValue(cid, 04420011) < 1 then
                    if addToList(cid, t[2]) then
                        doPlayerSetStorageValue(cid, 04420011, getPlayerStorageValue(cid, 04420011) + 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, t[2].." added to your auto loot list! To see your list say !autoloot")
                    else
                        doPlayerSendCancel(cid, t[2].." is already on your list!")
                    end
                else
                    doPlayerSendCancel(cid, "You already have an item added to the auto loot! To add another one, you must remove the current item.")
                end
            end
        else
            doPlayerSendCancel(cid, "This item does not exist!")
        end
    elseif t[1] == "remove" then
        if ExistItemByName(t[2]) then
            if removeFromList(cid, t[2]) then
                doPlayerSetStorageValue(cid, 04420011, getPlayerStorageValue(cid, 04420011) - 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, t[2].." removed from your auto loot list!")
            else
                doPlayerSendCancel(cid, "This item is not on your list!")
            end
        else
            doPlayerSendCancel(cid, "This item does not exist!")
        end
    elseif t[1] == "clear" then
        if getPlayerStorageValue(cid, 04420011) > -1 then
            doPlayerSetStorageValue(cid, 04420011, -1)
            doPlayerSetStorageValue(cid, 04420021, -1)
            doPlayerSetStorageValue(cid, 04420031, -1)
            doPlayerSetStorageValue(cid, 04420041, -1)
            doPlayerSetStorageValue(cid, 04420051, -1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "clean list!")
        else
            doPlayerSendCancel(cid, "Your list is now clean!")
        end
    elseif t[1] == "debug" or t[1] == "desbugar" then
        doPlayerSetStorageValue(cid, 04420011, -1)
        doPlayerSetStorageValue(cid, 04420021, -1)
        doPlayerSetStorageValue(cid, 04420031, -1)
        doPlayerSetStorageValue(cid, 04420041, -1)
        doPlayerSetStorageValue(cid, 04420051, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "buggy!")
    elseif t[1] == "list" then
        local fi = getPlayerStorageValue(cid, 04420021) ~= -1 and ""..getItemNameById(getPlayerStorageValue(cid, 04420021)).."\n" or ""
        local se = getPlayerStorageValue(cid, 04420031) ~= -1 and ""..getItemNameById(getPlayerStorageValue(cid, 04420031)).."\n" or ""
        local th = getPlayerStorageValue(cid, 04420041) ~= -1 and ""..getItemNameById(getPlayerStorageValue(cid, 04420041)).."\n" or ""
        local fo = getPlayerStorageValue(cid, 04420051) ~= -1 and ""..getItemNameById(getPlayerStorageValue(cid, 04420051)).."\n" or ""
        doPlayerPopupFYI(cid, "The auto loot system is collecting:\n "..fi..""..se..""..th..""..fo)
    end
    return true
end
[QUOTE]
and in xml:
<talkaction words="!autoloot" event="script" value="Auto Loot.lua"/>
[/QUOTE]
 
OP
OP
J

jeffaklumpen

Member
Joined
Jan 20, 2022
Messages
74
Solutions
2
Reaction score
14
GitHub
jeffaklumpen
Add in ur mods/script:

aloot.lua
Lua:
function onLogin(cid)
    registerCreatureEvent(cid, "aloot_kill")
    return true
end
 
local stor = 7575
 
function autoloot(cid, target, pos)
    local function doStack(cid, itemid, new)
        local count = getPlayerItemCount(cid, itemid)
        if (count > 100) then
            count = count - math.floor(count / 100) * 100
        end
        local newCount = count + new
        if (count ~= 0) then
            local find = getPlayerItemById(cid, true, itemid, count).uid
            if (find > 0) then
                doRemoveItem(find)
            else
                newCount = new
            end
        end
        local item = doCreateItemEx(itemid, newCount)
        doPlayerAddItemEx(cid, item, true)
    end
 
    local function scanContainer(cid, uid, list)
        for k = (getContainerSize(uid) - 1), 0, -1 do
            local tmp = getContainerItem(uid, k)
            if (isInArray(list, tmp.itemid)) then
                if isItemStackable(tmp.itemid) and (getPlayerItemCount(cid, tmp.itemid) > 0) then
                    doStack(cid, tmp.itemid, tmp.type)
                else
                    local item = doCreateItemEx(tmp.itemid, tmp.type)
                    doPlayerAddItemEx(cid, item, true)
                end
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Looted ' .. tmp.type .. ' ' .. getItemNameById(tmp.itemid) .. '.')
                doRemoveItem(tmp.uid)
            elseif isContainer(tmp.uid) then
                scanContainer(cid, tmp.uid, list)
            end
        end
    end
 
    local items = {}
    for i = getTileInfo(pos).items, 1, -1 do
        pos.stackpos = i
        table.insert(items, getThingFromPos(pos))
    end
 
    if (#items == 0) then
        return
    end
 
    local corpse = -1
    for _, item in ipairs(items) do
        local name = getItemName(item.uid):lower()
        if name:find(target:lower()) then
            corpse = item.uid
            break
        end
    end
 
    if (corpse ~= -1) and isContainer(corpse) then
        scanContainer(cid, corpse, tostring(getPlayerStorageValue(cid, stor)):gsub('_', ''):explode(','))
    end
end
 
function onKill(cid, target, lastHit)
    if not isPlayer(target) then
        local infos = getPlayerStorageValue(cid, stor)
        if (infos == -1) then
            return true
        end
        local list = tostring(infos):explode(',')
        if (#list == 0) then
            return true
        end
        addEvent(autoloot, 150, cid, getCreatureName(target), getCreaturePosition(target))
    end
    return true
end
in talkactions auto loot.lua:
Code:
function ExistItemByName(name)
    local items = io.open("data/items/items.xml", "r"):read("*all")
    local get = items:match('name="' .. name ..'"')
    if get == nil or get == "" then
        return false
    end
    return true
end

local function getPlayerList(cid)
    local tab = {}
    if getPlayerStorageValue(cid, 04420021) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 04420021))
    end
    if getPlayerStorageValue(cid, 04420031) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 04420031))
    end
    if getPlayerStorageValue(cid, 04420041) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 04420041))
    end
    if getPlayerStorageValue(cid, 04420051) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 04420051))
    end
    if #tab > 0 then
        return tab
    end
    return false
end

local function addToList(cid, name)
    local itemid = getItemIdByName(name)
    if getPlayerList(cid) and isInArray(getPlayerList(cid), itemid) then
        return false
    end
    if getPlayerStorageValue(cid, 04420021) == -1 then
        return doPlayerSetStorageValue(cid, 04420021, itemid)
    elseif getPlayerStorageValue(cid, 04420031) == -1 then
        return doPlayerSetStorageValue(cid, 04420031, itemid)
    elseif getPlayerStorageValue(cid, 04420041) == -1 then  
        return doPlayerSetStorageValue(cid, 04420041, itemid)
    elseif getPlayerStorageValue(cid, 04420051) == -1 then
        return doPlayerSetStorageValue(cid, 04420051, itemid)
    end
end

local function removeFromList(cid, name)
    local itemid = getItemIdByName(name)
    if getPlayerStorageValue(cid, 04420021) == itemid then
        return doPlayerSetStorageValue(cid, 04420021, -1)
    elseif getPlayerStorageValue(cid, 04420031) == itemid then
        return doPlayerSetStorageValue(cid, 04420031, -1)
    elseif getPlayerStorageValue(cid, 04420041) == itemid then
        return doPlayerSetStorageValue(cid, 04420041, -1)
    elseif getPlayerStorageValue(cid, 04420051) == itemid then
        return doPlayerSetStorageValue(cid, 04420051, -1)
    end
    return false
end

function onSay(cid, words, param)
    if(not checkExhausted(cid, 666, 6)) then
        return true
    end
    if param == "" then
        local fi = getPlayerStorageValue(cid, 04420021) ~= -1 and getItemNameById(getPlayerStorageValue(cid, 04420021)) or ""
        local se = getPlayerStorageValue(cid, 04420031) ~= -1 and getItemNameById(getPlayerStorageValue(cid, 04420031)) or ""
        local th = not vip.hasVip(cid) and "Not available for free account" or getPlayerStorageValue(cid, 04420041) ~= -1 and getItemNameById(getPlayerStorageValue(cid, 04420041)) or ""
        local fo = not vip.hasVip(cid) and "Not available for free account" or getPlayerStorageValue(cid, 04420051) ~= -1 and getItemNameById(getPlayerStorageValue(cid, 04420051)) or ""
        local stt = getPlayerStorageValue(cid, 04421011) == 1 and "yes" or "no"
        local str = getPlayerStorageValue(cid, 04421001) == 1 and "yes" or "no"
        doPlayerPopupFYI(cid, "{Auto-Loot} ---Player Auto Loot Menu\n{Auto-Loot} ----------------\n{Auto-Loot} ---Collect money: "..stt..". To turn on/off: !autoloot gold \n{Auto-Loot} ---Collect unique items: "..str..". To turn on/off: !autoloot power\n{Auto-Loot} --Configuration of slots:\n{Auto-Loot} ---Slot 1: "..fi.."\n{Auto-Loot} ---Slot 2: "..se.."\n{Auto-Loot} ---Slot 3: "..th.."\n{Auto-Loot} ---Slot 4: "..fo.."\n{Auto-Loot} ---To add a new item to the slots: !autoloot add, <item name>\n{Auto-Loot} ---To remove an item from the slots: !autoloot remove, <item name>\n{Auto-Loot} ---To clear all slots use: !autoloot clear\n{Auto-Loot} ---For information on how much you've done using the money collection, use: !autoloot goldinfo\n\nIf your autoloot bugar use ! autoloot debug\n\n{Auto-Loot} ----------------")
        return true
    end
   
    local t = string.explode(param, ",")
   
    if t[1] == "power" then
        local check = getPlayerStorageValue(cid, 04421001) == -1 and "turn on" or "turn off"
        doPlayerSetStorageValue(cid, 04421001, getPlayerStorageValue(cid, 04421001) == -1 and 1 or -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You "..check.." the auto loot.")
    elseif t[1] == "gold" then
        local check = getPlayerStorageValue(cid, 04421011) == -1 and "turn on" or "turn off"
        doPlayerSetStorageValue(cid, 04421011, getPlayerStorageValue(cid, 04421011) == -1 and 1 or -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You "..check.." the collection of money.")
        doPlayerSetStorageValue(cid, 04421021, 0)
    elseif t[1] == "goldinfo" then
        local str = getPlayerStorageValue(cid, 04421011) == -1 and "The money collection system is turned off" or "The system has already collected "..getPlayerStorageZero(cid, 04421021).." gold coins"
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, str)
    elseif t[1] == "add" then
        if ExistItemByName(t[2]) then
            local item = getItemIdByName(t[2])
            if isInArray({2160, 2148, 2152}, item) then
                return doPlayerSendCancel(cid, "You cannot autoloot coins. To collect money use !autoloot gold")
            end
            if vip.hasVip(cid) then
                if getPlayerStorageValue(cid, 04420011) < 3 then
                    if addToList(cid, t[2]) then
                        doPlayerSetStorageValue(cid, 04420011, getPlayerStorageValue(cid, 04420011) + 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, t[2].." added to your auto loot list! To see your list say !autoloot list")
                    else
                        doPlayerSendCancel(cid, t[2].." is already on your list!")
                    end
                else
                    doPlayerSendCancel(cid, "Your list already has 4 items! You must remove one before adding another.")
                end
            else
                if getPlayerStorageValue(cid, 04420011) < 1 then
                    if addToList(cid, t[2]) then
                        doPlayerSetStorageValue(cid, 04420011, getPlayerStorageValue(cid, 04420011) + 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, t[2].." added to your auto loot list! To see your list say !autoloot")
                    else
                        doPlayerSendCancel(cid, t[2].." is already on your list!")
                    end
                else
                    doPlayerSendCancel(cid, "You already have an item added to the auto loot! To add another one, you must remove the current item.")
                end
            end
        else
            doPlayerSendCancel(cid, "This item does not exist!")
        end
    elseif t[1] == "remove" then
        if ExistItemByName(t[2]) then
            if removeFromList(cid, t[2]) then
                doPlayerSetStorageValue(cid, 04420011, getPlayerStorageValue(cid, 04420011) - 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, t[2].." removed from your auto loot list!")
            else
                doPlayerSendCancel(cid, "This item is not on your list!")
            end
        else
            doPlayerSendCancel(cid, "This item does not exist!")
        end
    elseif t[1] == "clear" then
        if getPlayerStorageValue(cid, 04420011) > -1 then
            doPlayerSetStorageValue(cid, 04420011, -1)
            doPlayerSetStorageValue(cid, 04420021, -1)
            doPlayerSetStorageValue(cid, 04420031, -1)
            doPlayerSetStorageValue(cid, 04420041, -1)
            doPlayerSetStorageValue(cid, 04420051, -1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "clean list!")
        else
            doPlayerSendCancel(cid, "Your list is now clean!")
        end
    elseif t[1] == "debug" or t[1] == "desbugar" then
        doPlayerSetStorageValue(cid, 04420011, -1)
        doPlayerSetStorageValue(cid, 04420021, -1)
        doPlayerSetStorageValue(cid, 04420031, -1)
        doPlayerSetStorageValue(cid, 04420041, -1)
        doPlayerSetStorageValue(cid, 04420051, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "buggy!")
    elseif t[1] == "list" then
        local fi = getPlayerStorageValue(cid, 04420021) ~= -1 and ""..getItemNameById(getPlayerStorageValue(cid, 04420021)).."\n" or ""
        local se = getPlayerStorageValue(cid, 04420031) ~= -1 and ""..getItemNameById(getPlayerStorageValue(cid, 04420031)).."\n" or ""
        local th = getPlayerStorageValue(cid, 04420041) ~= -1 and ""..getItemNameById(getPlayerStorageValue(cid, 04420041)).."\n" or ""
        local fo = getPlayerStorageValue(cid, 04420051) ~= -1 and ""..getItemNameById(getPlayerStorageValue(cid, 04420051)).."\n" or ""
        doPlayerPopupFYI(cid, "The auto loot system is collecting:\n "..fi..""..se..""..th..""..fo)
    end
    return true
end
[QUOTE]
and in xml:
<talkaction words="!autoloot" event="script" value="Auto Loot.lua"/>
[/QUOTE]
Got alot of errors with that script :/
 
Top