UserFunction autoDeleteItems V1.1
Posted: Fri May 28, 2010 6:01 pm
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)
Example blacklist.xml file:
-Must be name "blacklist.xml" without quotes
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
-Must be name "blacklist.xml" without quotes
Code: Select all
<blacklist>
<item value="Magic Hormone"/>
<item value="Magic I"/>
</blacklist>