UserFunction autoDeleteItems V1.1

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

UserFunction autoDeleteItems V1.1

#1 Post 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>
Last edited by KillerTHC on Sat Jul 24, 2010 11:09 pm, edited 3 times in total.
filipsworks
Posts: 53
Joined: Mon May 10, 2010 10:37 am

Re: User function autoDeleteItems

#2 Post 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 ;)
KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

Re: User function autoDeleteItems

#3 Post 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.
filipsworks
Posts: 53
Joined: Mon May 10, 2010 10:37 am

Re: User function autoDeleteItems

#4 Post 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 :/
User avatar
Administrator
Site Admin
Posts: 5344
Joined: Sat Jan 05, 2008 4:21 pm

Re: User function autoDeleteItems

#5 Post 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
filipsworks
Posts: 53
Joined: Mon May 10, 2010 10:37 am

Re: User function autoDeleteItems

#6 Post by filipsworks »

Good to know...
KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

Re: User function autoDeleteItems V1.1

#7 Post by KillerTHC »

Updated to version 1.1 added a blacklist capability.
VoidMain
Posts: 187
Joined: Wed Apr 21, 2010 12:21 pm

Re: UserFunction autoDeleteItems V1.1

#8 Post 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 ^^
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: UserFunction autoDeleteItems V1.1

#9 Post 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?
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
VoidMain
Posts: 187
Joined: Wed Apr 21, 2010 12:21 pm

Re: UserFunction autoDeleteItems V1.1

#10 Post 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...
KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

Re: UserFunction autoDeleteItems V1.1

#11 Post 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.
Post Reply