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

Problem autoloot

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
188
Reaction score
9
GitHub
Jarek123
Hello guys I have problem with autoloot I use Tfs 0.4 tibia 8. 6
I have error in console like that
[13:54:49] [Error - CreatureScript Interface]
[13:54:49] In a timer event called from:
[13:54:49] data/creaturescripts/scripts/autoloot.lua:eek:nKill
[13:54:49] Description:
[13:54:49] (luaGetCreatureName) Creature not found
My script is
Lua:
-- Sistema de auto loot criado por Henrique Matheus - HServers

local tabela = {}

local function getPlayerList(cid)
    local tab = {}
    if getPlayerStorageValue(cid, 0442002) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 0442002))
    end
    if getPlayerStorageValue(cid, 0442003) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 0442003))
    end
    if getPlayerStorageValue(cid, 0442004) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 0442004))
    end
    if getPlayerStorageValue(cid, 0442005) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 0442005))
    end
    if #tab > 0 then
        return tab
    end
    return false
end

local function autoLoot(cid, pos)
    local check = false
    local str = ""
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)       
        if corpse then
            for index, info in pairs(corpse) do
                if index < countTable(corpse) then
                        if tonumber(info.uid) and tonumber(info.itemid) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray(getPlayerList(cid), bag[i].itemid) then
                                    if bag[i].quant > 1 then
                                        doRemoveItem(bag[i].uid, bag[i].quant)
                                        doPlayerAddItem(cid, bag[i].itemid, bag[i].quant)
                                        str = str.." "..bag[i].quant.." "..getItemNameById(bag[i].itemid)..","
                                    else
                                        doRemoveItem(bag[i].uid)
                                        doPlayerAddItem(cid, bag[i].itemid, 1)
                                        str = str.." 1 "..getItemNameById(bag[i].itemid)..","
                                    end
                                end
                            end
                        end
                    end
                end
                if isInArray(getPlayerList(cid), info.itemid) then
                    if info.quant > 1 then
                        doRemoveItem(info.uid, info.quant)
                        doPlayerAddItem(cid, info.itemid, info.quant)
                        str = str.." "..info.quant.." "..getItemNameById(info.itemid)..","
                    else
                        doRemoveItem(info.uid)
                        doPlayerAddItem(cid, info.itemid, 1)
                        str = str.." 1 "..getItemNameById(info.itemid)..","
                    end
                end
            end
        end
    end
    tabela[getCreatureName(cid)] = {item = "[Auto Loot System] Collected: "..str, gold = 0}
end

local function autoGold(cid, pos)
    local check = false
    local total = 0
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)
        if corpse then
            for index, info in pairs(corpse) do
                if info.uid and info.itemid then
                    if index < countTable(corpse) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray({2148, 2152, 2160}, bag[i].itemid) then
                                    local multiplie = 1
                                    if bag[i].itemid == 2148 then
                                        multiplie = 1
                                    elseif bag[i].itemid == 2152 then
                                        multiplie = 100
                                    elseif bag[i].itemid == 2160 then
                                        multiplie = 10000
                                    end
                                    doRemoveItem(bag[i].uid, bag[i].quant)
                                    doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
                                    total = total + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0)
                                    doPlayerSetStorageValue(cid, 0442102, getPlayerStorageZero(cid, 0442102) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
                                end
                            end
                        end
                    end
                    if isInArray({2148, 2152, 2160}, info.itemid) then
                        local multiplie = 1
                        if info.itemid == 2148 then
                            multiplie = 1
                        elseif info.itemid == 2152 then
                            multiplie = 100
                        elseif info.itemid == 2160 then
                            multiplie = 10000
                        end
    doRemoveItem(info.uid, info.quant)
                        doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
                        doPlayerSetStorageValue(cid, 0442102, getPlayerStorageZero(cid, 0442102) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
                        total = total + (tonumber(info.quant) and tonumber(info.quant) * multiplie or 0)
                    end
                end
            end
        end
    end
    if tabela[getCreatureName(cid)] and tabela[getCreatureName(cid)].gold then
        tabela[getCreatureName(cid)].gold = total
    end
end

local function sendMsg(cid)
    if tabela[getCreatureName(cid)] and tabela[getCreatureName(cid)].gold then
        if tabela[getCreatureName(cid)].gold == 0 then
            doPlayerSendTextMessage(cid, 23, tabela[getCreatureName(cid)].item)
        else
            doPlayerSendTextMessage(cid, 23, tabela[getCreatureName(cid)].item.." "..tabela[getCreatureName(cid)].gold.." gold coins.")
        end
        tabela[getCreatureName(cid)] = nil
    end
end

function onKill(cid, target, lastHit)
    if isPlayer(cid) and isMonster(target) then
        if getPlayerStorageValue(cid, 0442100) == 1 and getPlayerList(cid) then
            local pos = getCreaturePosition(target)
            addEvent(autoLoot, 500, cid, pos)
        end
        if getPlayerStorageValue(cid, 0442101) == 1 then
            local pos = getCreaturePosition(target)
            addEvent(autoGold, 500, cid, pos)
        end
        if getPlayerStorageValue(cid, 0442100) == 1 or getPlayerStorageValue(cid, 0442101) == 1 then
            addEvent(sendMsg, 540, cid)
        end
    end
    return true
end
Post automatically merged:

[16:18:06] [Error - CreatureScript Interface]
[16:18:06] In a timer event called from:
[16:18:06] data/creaturescripts/scripts/autoloot.lua:eek:nKill
[16:18:06] Description:
[16:18:06] (luaGetCreatureName) Creature not found

[16:18:06] [Error - CreatureScript Interface]
[16:18:06] In a timer event called from:
[16:18:06] data/creaturescripts/scripts/autoloot.lua:eek:nKill
[16:18:06] Description:
[16:18:06] (luaGetCreatureName) Creature not found

[16:18:06] [Error - CreatureScript Interface]
[16:18:06] In a timer event called from:
[16:18:06] data/creaturescripts/scripts/autoloot.lua:eek:nKill
[16:18:06] Description:
[16:18:06] (luaGetCreatureName) Creature not found

[16:18:06] [Error - CreatureScript Interface]
[16:18:06] In a timer event called from:
[16:18:06] data/creaturescripts/scripts/autoloot.lua:eek:nKill
[16:18:06] Description:
[16:18:06] (luaDoPlayerSendTextMessage) Player not found

[16:18:06] [Error - CreatureScript Interface]
[16:18:06] In a timer event called from:
[16:18:06] data/creaturescripts/scripts/autoloot.lua:eek:nKill
[16:18:06] Description:
[16:18:06] (luaGetCreatureName) Creature not found
Post automatically merged:

Please help me :(
 
Last edited:
try delete this for test
local function sendMsg(cid)
if tabela[getCreatureName(cid)] and tabela[getCreatureName(cid)].gold then
if tabela[getCreatureName(cid)].gold == 0 then
doPlayerSendTextMessage(cid, 23, tabela[getCreatureName(cid)].item)
else
doPlayerSendTextMessage(cid, 23, tabela[getCreatureName(cid)].item.." "..tabela[getCreatureName(cid)].gold.." gold coins.")
end
tabela[getCreatureName(cid)] = nil
end
end
 
Lua:
local tabela = {}

local function getPlayerList(cid)
    local tab = {}
    if getPlayerStorageValue(cid, 442002) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442002))
    end
    if getPlayerStorageValue(cid, 442003) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442003))
    end
    if getPlayerStorageValue(cid, 442004) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442004))
    end
    if getPlayerStorageValue(cid, 442005) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442005))
    end
    if #tab > 0 then
        return tab
    end
    return false
end

local function autoLoot(cid, pos, targetName)
    local check = false
    local str = ""
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)       
        if corpse then
            for index, info in pairs(corpse) do
                if index < countTable(corpse) then
                    if tonumber(info.uid) and tonumber(info.itemid) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray(getPlayerList(cid), bag[i].itemid) then
                                    if bag[i].quant > 1 then
                                        doRemoveItem(bag[i].uid, bag[i].quant)
                                        doPlayerAddItem(cid, bag[i].itemid, bag[i].quant)
                                        str = str.." "..bag[i].quant.." "..getItemNameById(bag[i].itemid)..","
                                    else
                                        doRemoveItem(bag[i].uid)
                                        doPlayerAddItem(cid, bag[i].itemid, 1)
                                        str = str.." 1 "..getItemNameById(bag[i].itemid)..","
                                    end
                                end
                            end
                        end
                    end
                end
                if isInArray(getPlayerList(cid), info.itemid) then
                    if info.quant > 1 then
                        doRemoveItem(info.uid, info.quant)
                        doPlayerAddItem(cid, info.itemid, info.quant)
                        str = str.." "..info.quant.." "..getItemNameById(info.itemid)..","
                    else
                        doRemoveItem(info.uid)
                        doPlayerAddItem(cid, info.itemid, 1)
                        str = str.." 1 "..getItemNameById(info.itemid)..","
                    end
                end
            end
        end
    end
    tabela[targetName] = {item = "[Auto Loot System] Collected: "..str, gold = 0}
end

local function autoGold(cid, pos, targetName)
    local check = false
    local total = 0
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)
        if corpse then
            for index, info in pairs(corpse) do
                if info.uid and info.itemid then
                    if index < countTable(corpse) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray({2148, 2152, 2160}, bag[i].itemid) then
                                    local multiplie = 1
                                    if bag[i].itemid == 2148 then
                                        multiplie = 1
                                    elseif bag[i].itemid == 2152 then
                                        multiplie = 100
                                    elseif bag[i].itemid == 2160 then
                                        multiplie = 10000
                                    end
                                    doRemoveItem(bag[i].uid, bag[i].quant)
                                    doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
                                    total = total + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0)
                                    doPlayerSetStorageValue(cid, 442102, getPlayerStorageZero(cid, 442102) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
                                end
                            end
                        end
                    end
                    if isInArray({2148, 2152, 2160}, info.itemid) then
                        local multiplie = 1
                        if info.itemid == 2148 then
                            multiplie = 1
                        elseif info.itemid == 2152 then
                            multiplie = 100
                        elseif info.itemid == 2160 then
                            multiplie = 10000
                        end
                        doRemoveItem(info.uid, info.quant)
                        doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
                        doPlayerSetStorageValue(cid, 442102, getPlayerStorageZero(cid, 442102) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
                        total = total + (tonumber(info.quant) and tonumber(info.quant) * multiplie or 0)
                    end
                end
            end
        end
    end
    if tabela[targetName] and tabela[targetName].gold then
        tabela[targetName].gold = total
    end
end

local function sendMsg(cid, targetName)
    if tabela[targetName] and tabela[targetName].gold then
        if tabela[targetName].gold == 0 then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, tabela[targetName].item)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, tabela[targetName].item.." "..tabela[targetName].gold.." gold coins.")
        end
        tabela[targetName] = nil
    end
end

function onKill(cid, target, lastHit)
    if isPlayer(cid) and isMonster(target) then
        local targetName = getCreatureName(target)
        if getPlayerStorageValue(cid, 442100) == 1 and getPlayerList(cid) then
            local pos = getCreaturePosition(target)
            addEvent(autoLoot, 500, cid, pos, targetName)
        end
        if getPlayerStorageValue(cid, 442101) == 1 then
            local pos = getCreaturePosition(target)
            addEvent(autoGold, 500, cid, pos, targetName)
        end
        if getPlayerStorageValue(cid, 442100) == 1 or getPlayerStorageValue(cid, 442101) == 1 then
            addEvent(sendMsg, 540, cid, targetName)
        end
    end
    return true
end
 
Lua:
local tabela = {}

local function getPlayerList(cid)
    local tab = {}
    if getPlayerStorageValue(cid, 442002) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442002))
    end
    if getPlayerStorageValue(cid, 442003) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442003))
    end
    if getPlayerStorageValue(cid, 442004) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442004))
    end
    if getPlayerStorageValue(cid, 442005) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442005))
    end
    if #tab > 0 then
        return tab
    end
    return false
end

local function autoLoot(cid, pos, targetName)
    local check = false
    local str = ""
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)      
        if corpse then
            for index, info in pairs(corpse) do
                if index < countTable(corpse) then
                    if tonumber(info.uid) and tonumber(info.itemid) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray(getPlayerList(cid), bag[i].itemid) then
                                    if bag[i].quant > 1 then
                                        doRemoveItem(bag[i].uid, bag[i].quant)
                                        doPlayerAddItem(cid, bag[i].itemid, bag[i].quant)
                                        str = str.." "..bag[i].quant.." "..getItemNameById(bag[i].itemid)..","
                                    else
                                        doRemoveItem(bag[i].uid)
                                        doPlayerAddItem(cid, bag[i].itemid, 1)
                                        str = str.." 1 "..getItemNameById(bag[i].itemid)..","
                                    end
                                end
                            end
                        end
                    end
                end
                if isInArray(getPlayerList(cid), info.itemid) then
                    if info.quant > 1 then
                        doRemoveItem(info.uid, info.quant)
                        doPlayerAddItem(cid, info.itemid, info.quant)
                        str = str.." "..info.quant.." "..getItemNameById(info.itemid)..","
                    else
                        doRemoveItem(info.uid)
                        doPlayerAddItem(cid, info.itemid, 1)
                        str = str.." 1 "..getItemNameById(info.itemid)..","
                    end
                end
            end
        end
    end
    tabela[targetName] = {item = "[Auto Loot System] Collected: "..str, gold = 0}
end

local function autoGold(cid, pos, targetName)
    local check = false
    local total = 0
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)
        if corpse then
            for index, info in pairs(corpse) do
                if info.uid and info.itemid then
                    if index < countTable(corpse) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray({2148, 2152, 2160}, bag[i].itemid) then
                                    local multiplie = 1
                                    if bag[i].itemid == 2148 then
                                        multiplie = 1
                                    elseif bag[i].itemid == 2152 then
                                        multiplie = 100
                                    elseif bag[i].itemid == 2160 then
                                        multiplie = 10000
                                    end
                                    doRemoveItem(bag[i].uid, bag[i].quant)
                                    doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
                                    total = total + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0)
                                    doPlayerSetStorageValue(cid, 442102, getPlayerStorageZero(cid, 442102) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
                                end
                            end
                        end
                    end
                    if isInArray({2148, 2152, 2160}, info.itemid) then
                        local multiplie = 1
                        if info.itemid == 2148 then
                            multiplie = 1
                        elseif info.itemid == 2152 then
                            multiplie = 100
                        elseif info.itemid == 2160 then
                            multiplie = 10000
                        end
                        doRemoveItem(info.uid, info.quant)
                        doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
                        doPlayerSetStorageValue(cid, 442102, getPlayerStorageZero(cid, 442102) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
                        total = total + (tonumber(info.quant) and tonumber(info.quant) * multiplie or 0)
                    end
                end
            end
        end
    end
    if tabela[targetName] and tabela[targetName].gold then
        tabela[targetName].gold = total
    end
end

local function sendMsg(cid, targetName)
    if tabela[targetName] and tabela[targetName].gold then
        if tabela[targetName].gold == 0 then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, tabela[targetName].item)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, tabela[targetName].item.." "..tabela[targetName].gold.." gold coins.")
        end
        tabela[targetName] = nil
    end
end

function onKill(cid, target, lastHit)
    if isPlayer(cid) and isMonster(target) then
        local targetName = getCreatureName(target)
        if getPlayerStorageValue(cid, 442100) == 1 and getPlayerList(cid) then
            local pos = getCreaturePosition(target)
            addEvent(autoLoot, 500, cid, pos, targetName)
        end
        if getPlayerStorageValue(cid, 442101) == 1 then
            local pos = getCreaturePosition(target)
            addEvent(autoGold, 500, cid, pos, targetName)
        end
        if getPlayerStorageValue(cid, 442100) == 1 or getPlayerStorageValue(cid, 442101) == 1 then
            addEvent(sendMsg, 540, cid, targetName)
        end
    end
    return true
end
When Player Died I have error in console like taht
Lua:
[22:31:20] [Error - CreatureScript Interface]
[22:31:20] In a timer event called from:
[22:31:20] data/creaturescripts/scripts/autoloot.lua:onKill
[22:31:20] Description:
[22:31:20] (internalGetPlayerInfo) Player not found when requesting player info #22

[22:31:20] [Error - CreatureScript Interface]
[22:31:20] In a timer event called from:
[22:31:20] data/creaturescripts/scripts/autoloot.lua:onKill
[22:31:20] Description:
[22:31:20] data/creaturescripts/scripts/autoloot.lua:124: attempt to perform arithmetic on a boolean value
[22:31:20] stack traceback:
[22:31:20]      data/creaturescripts/scripts/autoloot.lua:124: in function <data/creaturescripts/scripts/autoloot.lua:76>
Post automatically merged:

How I can fix it guys?
 
Last edited:
try.
Lua:
local tabela = {}

local function getPlayerList(cid)
    local tab = {}
    if getPlayerStorageValue(cid, 442002) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442002))
    end
    if getPlayerStorageValue(cid, 442003) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442003))
    end
    if getPlayerStorageValue(cid, 442004) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442004))
    end
    if getPlayerStorageValue(cid, 442005) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 442005))
    end
    if #tab > 0 then
        return tab
    end
    return false
end

local function autoLoot(cid, pos, targetName)
    local check = false
    local str = ""
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)       
        if corpse then
            for index, info in pairs(corpse) do
                if index < countTable(corpse) then
                    if tonumber(info.uid) and tonumber(info.itemid) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray(getPlayerList(cid), bag[i].itemid) then
                                    if tonumber(bag[i].quant) then
                                        if bag[i].quant > 1 then
                                            doRemoveItem(bag[i].uid, bag[i].quant)
                                            doPlayerAddItem(cid, bag[i].itemid, bag[i].quant)
                                            str = str.." "..bag[i].quant.." "..getItemNameById(bag[i].itemid)..","
                                        else
                                            doRemoveItem(bag[i].uid)
                                            doPlayerAddItem(cid, bag[i].itemid, 1)
                                            str = str.." 1 "..getItemNameById(bag[i].itemid)..","
                                        end
                                    end
                                end
                            end
                        end
                    end
                end
                if isInArray(getPlayerList(cid), info.itemid) then
                    if tonumber(info.quant) then
                        if info.quant > 1 then
                            doRemoveItem(info.uid, info.quant)
                            doPlayerAddItem(cid, info.itemid, info.quant)
                            str = str.." "..info.quant.." "..getItemNameById(info.itemid)..","
                        else
                            doRemoveItem(info.uid)
                            doPlayerAddItem(cid, info.itemid, 1)
                            str = str.." 1 "..getItemNameById(info.itemid)..","
                        end
                    end
                end
            end
        end
    end
    tabela[targetName] = {item = "[Auto Loot System] Collected: "..str, gold = 0}
end

local function autoGold(cid, pos, targetName)
    local check = false
    local total = 0
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)
        if corpse then
            for index, info in pairs(corpse) do
                if info.uid and info.itemid and tonumber(info.quant) then
                    if index < countTable(corpse) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray({2148, 2152, 2160}, bag[i].itemid) then
                                    local multiplie = 1
                                    if bag[i].itemid == 2148 then
                                        multiplie = 1
                                    elseif bag[i].itemid == 2152 then
                                        multiplie = 100
                                    elseif bag[i].itemid == 2160 then
                                        multiplie = 10000
                                    end
                                    doRemoveItem(bag[i].uid, bag[i].quant)
                                    doPlayerSetBalance(cid, getPlayerBalance(cid) + (bag[i].quant * multiplie))
                                    total = total + (bag[i].quant * multiplie)
                                    doPlayerSetStorageValue(cid, 442102, getPlayerStorageZero(cid, 442102) + (bag[i].quant * multiplie))
                                end
                            end
                        end
                    end
                    if isInArray({2148, 2152, 2160}, info.itemid) then
                        local multiplie = 1
                        if info.itemid == 2148 then
                            multiplie = 1
                        elseif info.itemid == 2152 then
                            multiplie = 100
                        elseif info.itemid == 2160 then
                            multiplie = 10000
                        end
                        doRemoveItem(info.uid, info.quant)
                        doPlayerSetBalance(cid, getPlayerBalance(cid) + (info.quant * multiplie))
                        doPlayerSetStorageValue(cid, 442102, getPlayerStorageZero(cid, 442102) + (info.quant * multiplie))
                        total = total + (info.quant * multiplie)
                    end
                end
            end
        end
    end
    if tabela[targetName] and tabela[targetName].gold then
        tabela[targetName].gold = total
    end
end

local function sendMsg(cid, targetName)
    if tabela[targetName] and tabela[targetName].gold then
        if tabela[targetName].gold == 0 then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, tabela[targetName].item)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, tabela[targetName].item.." "..tabela[targetName].gold.." gold coins.")
        end
        tabela[targetName] = nil
    end
end

function onKill(cid, target, lastHit)
    if isPlayer(cid) and isMonster(target) then
        local targetName = getCreatureName(target)
        if getPlayerStorageValue(cid, 442100) == 1 and getPlayerList(cid) then
            local pos = getCreaturePosition(target)
            addEvent(autoLoot, 500, cid, pos, targetName)
        end
        if getPlayerStorageValue(cid, 442101) == 1 then
            local pos = getCreaturePosition(target)
            addEvent(autoGold, 500, cid, pos, targetName)
        end
        if getPlayerStorageValue(cid, 442100) == 1 or getPlayerStorageValue(cid, 442101) == 1 then
            addEvent(sendMsg, 540, cid, targetName)
        end
    end
    return true
end
 
lmk, just added checks if the creature exists
Lua:
-- Sistema de auto loot criado por Henrique Matheus - HServers

local tabela = {}

local function creatureExists(cid)
    return isCreature(cid) == TRUE
end

local function getPlayerList(cid)
    local tab = {}
    if getPlayerStorageValue(cid, 0442002) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 0442002))
    end
    if getPlayerStorageValue(cid, 0442003) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 0442003))
    end
    if getPlayerStorageValue(cid, 0442004) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 0442004))
    end
    if getPlayerStorageValue(cid, 0442005) ~= -1 then
        table.insert(tab, getPlayerStorageValue(cid, 0442005))
    end
    if #tab > 0 then
        return tab
    end
    return false
end

local function autoLoot(cid, pos)
    if not creatureExists(cid) then return end

    local check = false
    local str = ""
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)       
        if corpse then
            for index, info in pairs(corpse) do
                if index < countTable(corpse) then
                        if tonumber(info.uid) and tonumber(info.itemid) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray(getPlayerList(cid), bag[i].itemid) then
                                    if bag[i].quant > 1 then
                                        doRemoveItem(bag[i].uid, bag[i].quant)
                                        doPlayerAddItem(cid, bag[i].itemid, bag[i].quant)
                                        str = str.." "..bag[i].quant.." "..getItemNameById(bag[i].itemid)..","
                                    else
                                        doRemoveItem(bag[i].uid)
                                        doPlayerAddItem(cid, bag[i].itemid, 1)
                                        str = str.." 1 "..getItemNameById(bag[i].itemid)..","
                                    end
                                end
                            end
                        end
                    end
                end
                if isInArray(getPlayerList(cid), info.itemid) then
                    if info.quant > 1 then
                        doRemoveItem(info.uid, info.quant)
                        doPlayerAddItem(cid, info.itemid, info.quant)
                        str = str.." "..info.quant.." "..getItemNameById(info.itemid)..","
                    else
                        doRemoveItem(info.uid)
                        doPlayerAddItem(cid, info.itemid, 1)
                        str = str.." 1 "..getItemNameById(info.itemid)..","
                    end
                end
            end
        end
    end
    if creatureExists(cid) then
        tabela[getCreatureName(cid)] = {item = "[Auto Loot System] Collected: "..str, gold = 0}
    end
end

local function autoGold(cid, pos)
    if not creatureExists(cid) then return end

    local check = false
    local total = 0
    local position = {}
    for i = 1, 255 do
        pos.stackpos = i
        if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
            position = pos
            check = true
            break
        end
    end
    if check then
        local corpse = getContainerItemsInfo(getThingFromPos(position).uid)
        if corpse then
            for index, info in pairs(corpse) do
                if info.uid and info.itemid then
                    if index < countTable(corpse) then
                        if isContainer(info.uid) then
                            local bag = getContainerItemsInfo(info.uid)
                            for i = 1, countTable(bag) - 1 do
                                if isInArray({2148, 2152, 2160}, bag[i].itemid) then
                                    local multiplie = 1
                                    if bag[i].itemid == 2148 then
                                        multiplie = 1
                                    elseif bag[i].itemid == 2152 then
                                        multiplie = 100
                                    elseif bag[i].itemid == 2160 then
                                        multiplie = 10000
                                    end
                                    doRemoveItem(bag[i].uid, bag[i].quant)
                                    doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
                                    total = total + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0)
                                    doPlayerSetStorageValue(cid, 0442102, getPlayerStorageZero(cid, 0442102) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
                                end
                            end
                        end
                    end
                    if isInArray({2148, 2152, 2160}, info.itemid) then
                        local multiplie = 1
                        if info.itemid == 2148 then
                            multiplie = 1
                        elseif info.itemid == 2152 then
                            multiplie = 100
                        elseif info.itemid == 2160 then
                            multiplie = 10000
                        end
                        doRemoveItem(info.uid, info.quant)
                        doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
                        doPlayerSetStorageValue(cid, 0442102, getPlayerStorageZero(cid, 0442102) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
                        total = total + (tonumber(info.quant) and tonumber(info.quant) * multiplie or 0)
                    end
                end
            end
        end
    end
    if creatureExists(cid) and tabela[getCreatureName(cid)] and tabela[getCreatureName(cid)].gold then
        tabela[getCreatureName(cid)].gold = total
    end
end

local function sendMsg(cid)
    if creatureExists(cid) and tabela[getCreatureName(cid)] and tabela[getCreatureName(cid)].gold then
        if tabela[getCreatureName(cid)].gold == 0 then
            doPlayerSendTextMessage(cid, 23, tabela[getCreatureName(cid)].item)
        else
            doPlayerSendTextMessage(cid, 23, tabela[getCreatureName(cid)].item..", "..tabela[getCreatureName(cid)].gold.." gold.")
        end
    end
end

function onDeath(cid, corpse, deathList)
    if isPlayer(cid) and getCreatureOutfit(cid).lookType ~= 97 then
        addEvent(autoLoot, 500, cid, corpse.position)
        addEvent(autoGold, 500, cid, corpse.position)
        addEvent(sendMsg, 2000, cid)
    end
    return true
end
 
Back
Top