Video demonstrando o que faz o script:
Para usar a talkaction eh simples:
!autoloot itens (itens separados por virgula)
Exemplo: !autoloot mastermind shield, gold coin
Na pasta mods, bote esse xml, e pronto estara funcionando direitinho.
autoLoot.xml:
<?xml version="1.0" encoding="UTF-8"?> <mod name="autoLoot" enabled="yes" author="MatheusMkalo" forum="XTibia.com"> <config name="autoLootLib"><![CDATA[ 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 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) 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 corpseRetireItems(corpsepos, killer, itemsarray) local corpse = nil for i = 1, 254 do corpsepos.stackpos = i corpse = getThingFromPos(corpsepos) if corpse.uid > 0 and isCorpse(corpse.uid) then break end end local items = getContainerItems(corpse.uid) for i,x in pairs(items) do if isInArray(itemsarray, tonumber(x.itemid)) then if isItemStackable(x.itemid) then doPlayerAddItemStacking(killer, x.itemid, x.type) else doPlayerAddItem(killer, x.itemid) end doRemoveItem(x.uid, x.type) end end end ]]></config> <creaturescript type="kill" name="autoLootKill" event="script"><![CDATA[ domodlib("autoLootLib") local loots = getPlayerStorageTable(cid, 6616) if lastHit and #loots >= 1 then addEvent(corpseRetireItems, 100, getCreaturePosition(target), cid, loots) end return true ]]></creaturescript> <talkaction words="!autoloot;/autoloot" event="script"><![CDATA[ domodlib("autoLootLib") local t = string.explode(param, ",") for i,x in pairs(t) do if not getItemIdByName(x, false) then return doPlayerSendCancel(cid, "Some of these items don't exist.") end t[i] = getItemIdByName(x, false) end setPlayerStorageTable(cid, 6616, t) doPlayerSendTextMessage(cid, 25, "Auto Looting: " .. param) return true ]]></talkaction> <creaturescript type="login" name="autoLootRegister" event="script"><![CDATA[ registerCreatureEvent(cid, "autoLootKill") return true ]]></creaturescript> </mod>