Page 1 of 6

Cleanbag userfunction 2.5

Posted: Thu Aug 18, 2011 9:53 am
by botje
Finally done with it, thanx to rock and lisa for showing me most (if not all) of the workings xd

just thought i would share it.

Code: Select all

-- sell prize = value which drops all below it
-- rarity = / 0 = white / 1 = green / 2 = blue / 3 = purple / 4 = orange / 5 = gold
-- drop true/false = if allready learned recipes should be dropped
-- logg true/false enables log function
you call it like this:

Code: Select all

CleanBag(1000, 2, true, false)
1000 is how much it should sell for to be kept, 3 is as shown above, rarity color, true is for dropping recipies you allready have.

rest should be selfexplainatory.

oh, it also logs items it throws away, learns and use, in the logfolder ^^

Botje

Re: Cleanbag userfunction

Posted: Thu Aug 18, 2011 12:17 pm
by botje
anybody with suggestions please let me know, im not that good at lua ya know :P

Botje

edit: seems only first bag gets checked, anyone a idea?

code should work as far as i know >.<

edit2: nvm, found it xd

Re: Cleanbag userfunction

Posted: Thu Aug 18, 2011 1:57 pm
by Tamyra
I know off topic, but could not find somewhere to ask:

Okay not sure if it is my work firewall blocking it suddenly, but I'm asking just in case. Is the wiki down?

Re: Cleanbag userfunction

Posted: Thu Aug 18, 2011 5:15 pm
by botje
sigh... now second bag gets checked, but first isnt... xd

any help please? :P


oooooooooh, now i get it, the bot and game use different slots, it has a offset of 60 :)

Botje

Re: Cleanbag userfunction

Posted: Thu Aug 18, 2011 7:17 pm
by lisa
I would probably add in a

Code: Select all

inventory:update();
like this

Code: Select all

function CleanBag(sellprize, rarity)
inventory:update();
for i, item in pairs(inventory.BagSlot) do
Something to also keep in mind is arrows are in the Weapons type, so if a scout has arrows within the slot ranges they will get deleted and a scout without arrows = dead, just means people have to be very careful what they have within the from and to slot ranges in profile. I mention arrows because if they get bought from vendor they just go to first available slot, so if you clean bags later on you could delete the arrows you bought.
Could probably do a check for the RELOAD_AMMUNITION = arrows in profile and if so then to check for highest lvl of arrow in bag and ignore it.

Re: Cleanbag userfunction

Posted: Thu Aug 18, 2011 10:42 pm
by rock5
How about a default value for rarity?

Code: Select all

if rarity == nil then rarity = 2 end

Re: Cleanbag userfunction

Posted: Fri Aug 19, 2011 8:54 am
by botje
thanx guys, ill add those suggestions ^^

Botje

Re: Cleanbag userfunction

Posted: Sun Aug 21, 2011 8:55 pm
by kanta
Just to be sure I'm understanding correctly, the rarity value drops all colors up to the value you enter? Such as using 2 will drop white, green and blue under a certain gold value?

Re: Cleanbag userfunction

Posted: Mon Aug 22, 2011 2:10 am
by botje
no, everything beneath it, you tell what to keep sort of speak :)

Botje

Re: Cleanbag userfunction

Posted: Tue Aug 23, 2011 2:13 pm
by kanta
Ah ok, thank you very much. This is a much better option than adding every item to the Lootomatic drop filter :)

Re: Cleanbag userfunction

Posted: Tue Aug 23, 2011 5:20 pm
by botje
your very welcome, and yes, thats why i made/copied this.

i got sick of adding stuff in lootfilter, i even think i maxed it, it wont let me add anymore items xd

Botje

Re: Cleanbag userfunction

Posted: Wed Aug 24, 2011 9:56 am
by Shogun
Nice, I will switch to that.

Here is what I use to determine the rarity for a modified BagCleanerSeller:

Code: Select all

			local table_quality = {"white","green","blue","purple","orange","gold"};
			local nMaxQuality;
			for i,v in pairs(table_quality) do
				if nil ~= string.find(settings.profile.options.INV_AUTOSELL_QUALITY, v) then
					nMaxQuality = i - 1;
				end
			end

Re: Cleanbag userfunction

Posted: Wed Oct 05, 2011 11:35 am
by Nero
Say, how does this function deletes those items? It looks like it's via

Code: Select all

item:delete()
when certain requirements are met. Problem is - I didn't found any such function on wiki, and putting it into search option didn't really give me anything useful.

How should I go about it when I would want to delete item with particular ID? Or it's just enough to paste something like item:delete(ID)?

And when it is, would changing this line

Code: Select all

if (item:isType("Weapons") or item:isType("Armor")) and sellprize > item.Worth and item.Quality < rarity then
to something that would check for a list of ID's specified by me, and those items would get deleted as well? (well, I don't really know how to do this - but this, I should manage to find. And yes, I know that I would need to mess around with other settings along with it, but that shouldn't be too hard)


Just noticed - isType is, yet again, neither to be found on wiki, nor explained on forums. How the heck do you guys know what are it's uses? Am I missing some large trove of info?

Cheers


Edit - I've searched around in various things in bot files, and found item:delete() in item.lua. There are two lines
RoMScript("PickupBagItem("..self.BagId..");");
RoMScript("DeleteCursorItem();");

So.. it deletes specified item.. although how is it specified? self.BagId means ID?

Re: Cleanbag userfunction

Posted: Wed Oct 05, 2011 11:50 am
by botje
oh thats easy, the big trove of info is called Rock5 and Lisa :)

They helped a LOT with this, because im not that good at Lua :P

EDIT:
btw, i think you can take that part out of the lootfilter addon, that uses a list too :)

Botje

Re: Cleanbag userfunction

Posted: Wed Oct 05, 2011 11:56 am
by Nero
Thanks for the quick reply.

So, to make it short - using Item:delete(50000) will delete item with ID 50,000 as long as I have it in my bag?

Thanks for the idea of checking out lootfilter - would probably help me in it

Re: Cleanbag userfunction

Posted: Wed Oct 05, 2011 12:03 pm
by botje
as far as i know that should work, but yeah.

lootfilter is your pall in this case, good luck ^^

botje

Re: Cleanbag userfunction

Posted: Wed Oct 05, 2011 9:15 pm
by rock5
You have to understand about classes. You can think of a class as a pattern or template. The CItem object never gets created as CItem. It's used to create the items. Items created in the inventory are based on CItem and have thier own version of all the attributes and function CItem has.

So for example:

Code: Select all

feed = inventory:findItem("Feed Bag")
Will create an item "feed" that has all the attributes and functions you find in item.lua. So "feed" will be a particular item. The function associated with "feed" are for acting upon that item. So

Code: Select all

feed:delete()
will delete that item.

Other items or objects based on classes are:
  • inventory - based on CInventory
    player - based on CPlayer and CPawn
    When mobs objects are created - based on CPawn
    __WPL - based on CWaypointList
    The actual points in the waypointlist - based on CWaypoint
I hope that helps.

Re: Cleanbag userfunction

Posted: Thu Sep 13, 2012 10:44 am
by xrozhija
How would i go about making this userfunction also delete runes, amulet of light, ammo and potions up to a cetain level?

The potion part, I would like it to only delete potions lower than level 46, as those are the ones i use. (Elemental Spirit Stone, if name has anything to say)

Re: Cleanbag userfunction

Posted: Fri Sep 14, 2012 4:23 am
by Jandrana
What you are looking for, is a not so easy because you are looking at items of different types and you want to take usage level into account.

If you want to keep the code to trash these item simple, you can do this:

Lookup the ids in runes database and add them into a table and use a function like this:

Code: Select all

stuffToDelete = { }   -- add ids here


function MyCleanBag(idsToDelete)
   local name;
	local k;
	inventory:update()
   for i, item in pairs(inventory.BagSlot) do
	   if item.Id ~= 0 and item.SlotNumber > 60 then
			name = GetIdName(item.Id);
			if name == nil then
			   name = "(no name found)";
			end
		   -- delete items marked for delete
			for j, element in pairs(idsToDelete) do
            if item.Id == element then 
					print("dropping "..name);
               item:delete()
				end
         end         
		end
	end
end

...
 MyCleanBag(stuffToDelete)
To find a group of items of a certain type you can use this function:

Code: Select all

function buildItemTableOfType(nameOfType)
   local result = {};
   local count = 1;
   inventory:update()
   for i, item in pairs(inventory.BagSlot) do
	   if item.Id ~= 0 then
			if item:isType(nameOfType) then 
				result[count]=item;
            count = count + 1;
			end
	   end
   end
   return result;
end

function getIdsFrom(items)
   local result = {};
   local count = 1;
   for j, element in pairs(items) do
      result[count]=element.Id;
      count = count + 1;
   end
   return result;
end
To delete all runes you can use something like this:

Code: Select all

items = buildItemTableOfType("Runes");
ids = getIdsFrom(items);
MyCleanBag(ids);
I'm not familiar with types, but I think there is something similar is available for "Potions" and "Ammo".

The functions above are parts of my scripts, so they should work.

This would be function that would filter items according to there usage level (this is untested):

Code: Select all

function filterItems(idsToFilter, requiredLevel)
   local result = {};
   local count = 1;
	for j, element in pairs(idsToFilter) do
		if requiredLevel > item.RequiredLvl  then 
			result[count]=item.Id;
         count = count + 1;
		end
	end
	return result;
end
Then something like this could work to drop potions with a level below 41:

Code: Select all

potions = buildTableOfType("Potions");
potions = filterItems(potions, 41);
ids = getIdsFrom(potions);
MyCleanBag(ids);
Edit: tested the last functions myself and found, that I made a mistake. buildTableOfType returns ids, but you cannot determine any attributes from the id. So you must return an array of items and you need another helper function to collect ids from items.

Re: Cleanbag userfunction 2.0

Posted: Tue Nov 27, 2012 10:33 am
by botje
updated to version 2.0

recipies and cards are getting used now, if you dont have them.