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

Lua Autoloot small and rare isue??

Nubaza

LUA Scripter
Joined
Jun 5, 2011
Messages
330
Solutions
1
Reaction score
22
Location
New Zeland
Hello, i've a rare problem with my Autoloot!

This is my autoloot.lua
Code:
local stor = 7590
function autoloot(cid, target, pos)
    if not isPlayer(cid) then
        return
    end
    local function doStack(cid, itemid, new)
        local count = getPlayerItemCount(cid, itemid)
        if ((count % 100) == 0) then
            return doPlayerAddItemEx(cid, doCreateItemEx(itemid, new), true)
        elseif (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
        if (newCount > 100) then
            for i = 1, math.floor(newCount / 100) do
                doPlayerAddItemEx(cid, doCreateItemEx(itemid, 100), true)
            end
            newCount = (newCount % 100)
        end
        doPlayerAddItemEx(cid, doCreateItemEx(itemid, newCount), 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, 26, "Usted ha obtenido algunos objetos.")
                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
        items[i] = getThingFromPos(pos)
    end
    if (#items == 0) then
        return
    end
    local corpse = -1
    for _, item in pairs(items) do
        if not isCreature(item.uid) then
            local name = getItemName(item.uid):lower()
            if name:find(target:lower()) then
                corpse = item.uid
                break
            end
        end
    end
    if (corpse ~= -1) and isContainer(corpse) and (getItemAttribute(corpse, "corpseowner") == cid) 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

I don't know the reason but it only works if the monster and the corpse have the same ename

Example: i kill a "Golem" with his corpse's name: "defeated golem".
That works, allright... BUT.

When i kill a monster like "Hard Golem" with his corpse's name: "defeated golem" the script don't work... I can't duplicate the item to only rename, because i've aprox 200. creatures with names "Hard", "Ancient" etc... that is like bosses..

Can u help? it's something of the function name:find but i tried and nothing

Thanks otland,
 
Back
Top