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

CreatureEvent Autoloot

Jano

oturhaN
Joined
Feb 21, 2008
Messages
876
Solutions
1
Reaction score
68
Location
Chile
Autoloot command is present in most of the online games but not in tibia, there are bots for tibia for autolooting, but i wanted to make a command <_<

i cant say its totally free-bug, but was testing and worked ok with most of the tests.

Features for now:

- Autostack if possible
- Check your autoloot list
- Add / remove from autoloot list
- Limit for autoloot list
- Deep search in corpse

Not ready -> loot container with items inside (not sure if is a good idea)


Creaturescripts
Lua:
local stor = 7575

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

Talkaction
Lua:
local stor, limit = 7575, 5 --storage, limit to add.
 
local allow_container = false --empty! not looted with items, atleast for now.
 
function onSay(cid, words, param)	
	local expl = param:explode(':')
	local action, rst = expl[1], expl[2]
	
	if (action:lower() == 'check') then
		local infos, list = getPlayerStorageValue(cid, stor), {}
		if (infos ~= -1) then
			list = tostring(infos):explode(',')
		end
		
		local txt = 'Autoloot List:\n'
		if (#list > 0) then
			for k, id in ipairs(list) do
				id = id:gsub('_', '')
				if tonumber(id) then
					txt = txt .. getItemNameById(tonumber(id)) .. ((k < #list) and '\n' or '')
				end
			end
		else
			txt = 'Empty'
		end
		doPlayerPopupFYI(cid, txt)
		
	elseif (action:lower() == 'add') then
		local infos, list = getPlayerStorageValue(cid, stor), {}
		if (infos ~= -1) then
			list = tostring(infos):gsub('_', ''):explode(',')
		end
		
		if (#list >= limit) then
			return doPlayerSendCancel(cid, 'You already have ' .. limit .. ' autolooting items.')
		end
		
		local item = tonumber(rst)
		if not item then
			item = getItemIdByName(rst, false)
			if not item then
				return doPlayerSendCancel(cid, 'not valid item.')
			end
		end
		
		if not allow_container and isItemContainer(item) then
			return doPlayerSendCancel(cid, 'this item can not be autolooted.')
		end
		
		local attrs = getItemInfo(item)
		if not attrs then
			return doPlayerSendCancel(cid, 'not valid item.')
		elseif not attrs.movable or not attrs.pickupable then
			return doPlayerSendCancel(cid, 'this item can not be autolooted.')
		end
		
		if isInArray(list, item) then
			return doPlayerSendCancel(cid, 'This item is already added in your list.')
		end
		table.insert(list, tostring(item))
		
		local new = ''
		for v, id in ipairs(list) do
			new = new .. '_' .. id:gsub('_' ,'') .. ((v < #list) and ',' or '')
		end
		doPlayerSetStorageValue(cid, stor, tostring(new))
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Item >>' .. getItemNameById(item) .. '<< has been added to the autoloot list.')
	elseif (action:lower() == 'remove') then
		local infos, list = getPlayerStorageValue(cid, stor), {}
		if (infos ~= -1) then
			list = tostring(infos):gsub('_', ''):explode(',')
		end
		
		if (#list == 0) then
			return doPlayerSendCancel(cid, 'You dont have any item added.')
		end

		local item = tonumber(rst)
		if not item then
			item = getItemIdByName(rst, false)
			if not item then
				return doPlayerSendCancel(cid, 'not valid item.')
			end
		end
		
		if not isInArray(list, item) then
			return doPlayerSendCancel(cid, 'This item is not in the list.')
		end

		local new = ''
		for v, id in ipairs(list) do
			if (tonumber(id) ~= item) then
				new = new .. '_' .. id:gsub('_' ,'') .. ((v < #list) and ',' or '')
			end
		end
		doPlayerSetStorageValue(cid, stor, tostring(new))
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Item >>' .. getItemNameById(item) .. '<< removed from the autoloot list.')
	
	elseif (action:lower() == 'clean') then
		doPlayerSetStorageValue(cid, stor, -1)
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Autoloot list cleaned.')
	end        
	return true
end

usage ~

/aloot check
*shows your autoloot list

/aloot add:itemid or item name

example:
/aloot add:worm
/aloot add:2170

16:42 Item >>worm<< has been added to the autoloot list.

/aloot remove:itemid or item name

example:
/aloot remove:worm
/aloot remove:2170

16:46 Item >>worm<< removed from the autoloot list.


my super hunt of rats

16:41 Looted 2 gold coin.
16:41 Looted 1 cheese.

reported bugs will be fixed ^^
 
Last edited:
its not boting, that feature its present in most of online rpg games =P
 
good, i saw this requested
:p i misread autobot
 
can you make an auto loot without talkaction? say for example gold, auto loots to backpack, auto stacks, and auto converts to platinums and crystals? :p
 
can you make an auto loot without talkaction? say for example gold, auto loots to backpack, auto stacks, and auto converts to platinums and crystals? :p

to make it work withtout talkaction just change

Code:
    if (corpse ~= -1) and  isContainer(corpse) then
        scanContainer(cid, corpse, tostring(getPlayerStorageValue(cid, stor)):gsub('_', ''):explode(','))
    end
Code:
    [COLOR=Red]local list = {2148, 2170}[/COLOR]
    if (corpse ~= -1) and  isContainer(corpse) then
        scanContainer(cid, corpse, list)
    end
and insert your "autolooteable" items in that array, auto transforming will need extra edits.
 
Dude, this is exactly was Cip was planning to do after they dropped another 10k players...

Anyways, this pwnz!
 
i love you lol been waiting for an auto loot script xD (too lazy to write my own atm :) ) thanks dude.
 
it's very cool, but I'm against that people is getting more and more lazy everyday...
 
it's very cool, but I'm against that people is getting more and more lazy everyday...

looting is so unnecessary in tibia ;/ takes so long and there's no need to focus on opening a corpse to get money 24/7 lol
 
doesnt works perfect with me, doesnt loot more if i have 100 of a stackable item like if i looted 100 gold coins then it doesnt add more in bp but keep saying looted 4 gp etc
 
Thank you for this script, it's great!
I'am waiting for script upgrades!
Nice
PS. sorry for my english, i am learning it :p
 
Dud I Have This Error Hope Can Help Me
Well When I Kill Monster I Doesnt Grav 2160[Crystal Coin] Like I Added
And It Says This On Default Channel:
Item >>crystal coin<< has been added to the autoloot list.
Plis Help Me );
 
@Up [Myself xp]
Fixed Error ;D Just That When I Have 100gps gont get any more );
 
Back
Top