Page 1 of 1

UserFunction autoDeleteItems V1.1

Posted: Fri May 28, 2010 6:01 pm
by KillerTHC
Add this function to your userfunctions.lua file and then call it after every fight to filter your 2nd bag of items designated by the color you provided, or use the blacklist option to filter your whole bag of items with the names provided in a "blacklist" file. Partial matches will be made with the blacklist option.

autoDeleteItems(option)

Code: Select all

function autoDeleteItems(option)--WHITE GREEN BLUE PURPLE ORANGE GOLD BLACKLIST
	if ( type(option) ~= "string" ) then
		return false;
	else 
		if ( string.upper(option) == "WHITE" or
			string.upper(option) == "GREEN" or
			string.upper(option) == "BLUE" or
			string.upper(option) == "PURPLE" or
			string.upper(option) == "ORANGE" or
			string.upper(option) == "GOLD" ) then
			local deletedItems = 0;
			for i=1,60,1 do		--Loop to go through the whole bag and get the info.
				local slotitem = inventory.BagSlot[i];
				local printed = false;
				if ( i > 30 and slotitem.Id ~= 0 ) then --Make sure that the item is in the 2nd bag and there is an item in that slot
					if ( slotitem.Color == ITEMCOLOR[string.upper(option)] ) then
						if( printed ~= true ) then 
							cprintf(cli.white, "Deleting the following items by color "..string.upper(option).." : \n");
							printed = true;
						end
						cprintf(cli.white, slotitem.Name);
						printf("\n");
						RoMScript("PickupBagItem("..slotitem.BagId..");");
						RoMScript("DeleteCursorItem();");
						deletedItems = deletedItems + 1;
					end
				end
			end
			if( deletedItems > 0 ) then
				inventory:update();
			else
				cprintf(cli.white, "No items deleted skipping bag update \n");
			end
		elseif (string.upper(option) == "BLACKLIST") then
			local filename = getExecutionPath() .. "/blacklist.xml";
			local root = xml.open(filename);
			local elements = root:getElements();
			local badItems = { };
			
			local loadBlackListItem = function (node)
				local name = node:getAttribute("value");
				table.insert(badItems,string.upper(name));
			end
				
			for i,v in pairs(elements) do
				local name = v:getName();

				if( string.upper(name) == "ITEM" ) then
					loadBlackListItem(v);
				end
			end
				
			local deletedItems = 0;
			for i=1,60,1 do		--Loop to go through the whole bag and get the info.
				local slotitem = inventory.BagSlot[i];
				local printed = false;
				if ( slotitem.Id ~= 0 ) then --Make sure that there is an item in that slot
					for a,b in pairs(badItems) do
						local temp = string.find(string.upper(slotitem.Name), badItems[a])
						if ( temp ) then
							if( printed ~= true ) then 
								cprintf(cli.white, "Deleting the following items in the blacklist : \n");
								printed = true;
							end
							cprintf(cli.white, slotitem.Name);
							printf("\n");
							RoMScript("PickupBagItem("..slotitem.BagId..");");
							RoMScript("DeleteCursorItem();");
							deletedItems = deletedItems + 1;
						end
					end
				end
			end
			if( deletedItems > 0 ) then
				inventory:update();
			else
				cprintf(cli.white, "No items deleted skipping bag update \n");
			end
		else
			cprintf(cli.white, "Bad variable input! \n");
			return false;
		end
	end
end
Example blacklist.xml file:
-Must be name "blacklist.xml" without quotes

Code: Select all

<blacklist>
	<item value="Magic Hormone"/>
        <item value="Magic I"/>
</blacklist>

Re: User function autoDeleteItems

Posted: Sun May 30, 2010 2:19 am
by filipsworks
nice, but can U use language codes in these lines:

Code: Select all

cprintf(cli.white, "Deleting the following items: ");

cprintf(cli.white, "No items deleted skip bag update");
??

It will makes it easier to translate ;)

Re: User function autoDeleteItems

Posted: Sun May 30, 2010 7:19 pm
by KillerTHC
I don't quite understand what you mean by language codes? The code provided can be edited with the translation you want, however I will not do it as I do not read/speak other languages and would not want to provide an incorrect translation.

Re: User function autoDeleteItems

Posted: Mon May 31, 2010 8:52 am
by filipsworks
1) Go into \micromacro\scripts\rom\language\english.lua

after last language code add something like that

Code: Select all

-- autoDeleteItems
	[9990] = "Deleting the following items: \n",
then it can be easy translated from one file

2) Modify your code like that:

Instead of

Code: Select all

cprintf(cli.white, "Deleting the following items: ");
use

Code: Select all

cprintf(cli.white, language[9990]);
-----------------------------------------------------------
It really can be useful when making "repacks" for friends and others;)

Hopefully U understand what I mean :/

Re: User function autoDeleteItems

Posted: Mon May 31, 2010 9:43 am
by Administrator
For a non-standard function (ie. one that is placed into userfunctions.lua), it is not recommended to add it to the language files. Instead, you can include this in the top of your userfunctions.lua file.

Code: Select all

if( bot.ClientLanguage == "ENEU" or bot.ClientLanguage == "ENUS" ) then
 -- English texts
  language[9990] = "Some text";
elseif( bot.ClientLanguage == "DE" ) then
  -- German texts
elseif( bot.ClientLanguage == "RU" ) then
  -- Russian texts
end

Re: User function autoDeleteItems

Posted: Tue Jun 01, 2010 1:07 am
by filipsworks
Good to know...

Re: User function autoDeleteItems V1.1

Posted: Sat Jul 24, 2010 8:50 pm
by KillerTHC
Updated to version 1.1 added a blacklist capability.

Re: UserFunction autoDeleteItems V1.1

Posted: Sat Jul 24, 2010 11:29 pm
by VoidMain
Neat stuff killer, only 2 things to notice:
1) You should update inv before starting the loop...
2) With the upcoming inventory handling the slots are not going to be in "inventory order", it means the BagId is gonna match the BagId ingame but the order of the slots is something we can't check or control anymore, so i > 30 doesn't mean is gonna be on bagslot 30+

I'll say its nice and would be better if you add a whitelist so you can always keep the items you want, also white and black lists can be cached the first time the function is called so is cheap and fast to call it after every kill...

Just my 2 cents ^^

Re: UserFunction autoDeleteItems V1.1

Posted: Sat Jul 24, 2010 11:42 pm
by rock5
I think the problem with this is it only deals with a specific need. What if you want to delete items by worth?

Re: UserFunction autoDeleteItems V1.1

Posted: Sun Jul 25, 2010 1:37 am
by VoidMain
rock5 wrote:I think the problem with this is it only deals with a specific need. What if you want to delete items by worth?
Yea, like shoulders and belts...

Re: UserFunction autoDeleteItems V1.1

Posted: Sun Jul 25, 2010 12:43 pm
by KillerTHC
I will update the method to work with the new inventory system when it is released along with adding a "whitelist" option and other options for deleting by value etc... I cant wait for the new inventory system to be implemented, along with the improved loot methods this bot has come a long way it's so much more efficient and less bot like now.