Cleanbag userfunction 2.5

Additional botting resources. Addons may be either for the game itself or for the RoM bot.
Forum rules
Only post additional bot resources here. Please do not ask unrelated questions.
Message
Author
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Cleanbag userfunction 2.4

#61 Post by lisa » Sat Jan 05, 2013 7:06 pm

Ok I just got file off first post, V 2.4

First thing I notice is there might be an issue with the logic of the code.

So for each slot you first do the forcedrop check, issue I see with that code is if the item is deleted it still continues on and does the rest of the code for that item slot even though the item has been deleted.

Next you check the forcekeep table, you check if the item.Name is the same as the item in the first spot of the table but what if it the third name in the table, basically if it isn't the first name then it doesn't get to check the second and onwards becuase of the else.


Ok so in a nutshell

Code: Select all

			for k, v in ipairs(forcedrop) do
				if v == item.Name then
					printf("Deleting Item:  "..item.Name.."\n");
					item:delete();
				end
			end
need to stop it from going further in code for that slot if the item has been deleted.

Code: Select all

			for j, l in ipairs(forcekeep) do
				--printf("force Item:  "..l.."\n");
				--printf("Item name:  "..item.Name.."\n");
				if l == item.Name then
					--keep it
					printf("Keeping Item:  "..item.Name.."\n");
				else
the else is a bad thing in this situation, basically if it isn't the item in first spot of table then it will probably be deleted by the code after the else.


So to sum up, work out how to break from the checking table if item is deleted and then rethink how you are dealing with the forcekeep table =)
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.4

#62 Post by botje » Sat Jan 05, 2013 7:24 pm

hmm... i see about that logic part on the deleting yes, although i cant figure out right now how to stop it from processing.

ill check if lua has a goto command, that would work.

but that other part i dont get

Code: Select all

for j, l in ipairs(forcekeep) do
loops true the number of items in the table right? so why do you say it checks only first item?

edit: aww... goto is only in newest Lua :(

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Cleanbag userfunction 2.4

#63 Post by lisa » Sat Jan 05, 2013 8:03 pm

*screams stupid net*
Ok so I had it all typed out explaining everything and hit post but net died, soooooo you get the short verion.

Do something like this

Code: Select all

	local forcedrop = {
		"Unknown Gift",
		"Lost Gift",
		"Sled Fragment",
	}
	local forcekeep = {
		"Link Rune",
	}	
	for i = 1,5 do -- for i, item in pairs(inventory.BagSlot) do
		local keep, deleted
		for k,v in pairs(forcedrop) do
			if v == "Lost Gift" then --item.Name instead of "Lost Gift"
				--item:delete();
				deleted = true
				break -- stops looking through rest of table
			end
		end
		for k,v in pairs(forcekeep) do
			if v == "Link Rune" then --item.Name instead of "Link Rune"
				keep = true
				break -- stops looking through rest of table
			end
		end	
		if not keep and not deleted then
		-- all the other delete item checks here
		end
	end
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.4

#64 Post by botje » Sat Jan 05, 2013 8:16 pm

nice, thanx lisa, ill see what i can do with that ^^

just curious though, whats that i = 1,5

part? what does that 1,5 stand for?

also, the way you posted it there, doesn use item, so how would i get item.name?

oh wait, thats just for testing purposes xd

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Cleanbag userfunction 2.4

#65 Post by lisa » Sat Jan 05, 2013 8:44 pm

botje wrote:oh wait, thats just for testing purposes xd
Yup

If you ever want to know how things work, make some simple and put in lots of print messages, that is how I learn =)
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.4

#66 Post by botje » Sun Jan 06, 2013 9:20 am

ok, updated to 2.5, very much credit to lisa, that helped me optimize and fix my mess :oops:

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Cleanbag userfunction 2.4

#67 Post by lisa » Sun Jan 06, 2013 9:53 am

looks like it should work now.

on a side note you can write this

Code: Select all

if sellprize == nil then sellprize = 750 end;
like this

Code: Select all

sellprize = sellprize or 750
they both do exactly the same thing but I just think the second looks nicer and less typing ;)
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.4

#68 Post by botje » Sun Jan 06, 2013 9:54 am

nice, ill fix that ^^

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Cleanbag userfunction 2.4

#69 Post by lisa » Sun Jan 06, 2013 10:16 am

I'll probably start to nitpick now but anyway.

Since you only check if this is true or not you shouldn't need to define it as false if it is nil because if it is nil then it's not true anyway, no need for this bit.

Code: Select all

if drop == nil then drop = false end;

I made a userfunction called logInfo() a while back, so same name might cause a conflict if they have that userfunction aswell.
Ohh it is exactly the same lol
If you wanted you could make the one in your userfunction local, that way if it is called from inside that file it will use yours regardless, so any changes you make won't have any issues elsewhere.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.4

#70 Post by botje » Sun Jan 06, 2013 10:26 am

lol, it is yours :)

i just included it so there wont be any, "errors" due to people missing it :P

ill make them locally just to be sure :)

i see, i was just covering all bases with that code, ill take it out ^^

any other nitpicking? :lol:

im open for suggestions ^^

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Cleanbag userfunction 2.4

#71 Post by kenzu38 » Sun Jan 06, 2013 11:23 am

And I'll wait for the most optimized version. Not gonna download yet. :D

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.4

#72 Post by botje » Sun Jan 06, 2013 11:48 am

think you should download it anyway mate, its much better allready , those things dont make a huge difference

also, things work now :lol:

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Cleanbag userfunction 2.5

#73 Post by kenzu38 » Sun Jan 06, 2013 12:20 pm

Lol yep, already downloaded it. Might I suggest, though, that you also make the function check for transmutor charges and use all of them.

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.5

#74 Post by botje » Sun Jan 06, 2013 12:45 pm

but those are in itemshop bag, thats not the thing im trying to clean :P

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Cleanbag userfunction 2.5

#75 Post by kenzu38 » Sun Jan 06, 2013 1:29 pm

You don't play minigames? They're rewards from minigames and automatically go into your bag. So I think many people would want them "cleaned" from there as well.

Well anyway, I downloaded your new file and it still doesn't work. It even has one "end" more than needed so I had to delete one before I could use it. And when I tested it, it's still deleting items in the forcekeep table.

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.5

#76 Post by botje » Sun Jan 06, 2013 1:48 pm

no it does'nt O.o

Code: Select all

function CleanBag(sellprize, rarity, drop, logg)
	inventory:update();
	
	-- custom database for user added items to trow out
	local forcedrop = {
		"Unknown Gift",
		"Lost Gift",
		"Sled Fragment",
	}
	
	-- custom database for user added items to keep
	local forcekeep = {
		"none",
	}
	
	sellprize = sellprize or 750;
	rarity = rarity or 1;
	logg = logg or true;
	
	for i, item in pairs(inventory.BagSlot) do
		if item.SlotNumber >= settings.profile.options.INV_AUTOSELL_FROMSLOT + 60 and
		settings.profile.options.INV_AUTOSELL_TOSLOT + 60 >= item.SlotNumber then
			
			local keep, deleted
			for k,v in pairs(forcedrop) do
				if v == item.Name then --item.Name instead of "Lost Gift"
					printf("Forcefully Deleting Item:  "..item.Name.."\n");
					item:delete();
					deleted = true
					break -- stops looking through rest of table
				end
			end
			for k,v in pairs(forcekeep) do
				if v == item.Name then --item.Name instead of "Link Rune"
					keep = true
					break -- stops looking through rest of table
				end
			end   
			if not keep and not deleted then
				-- all the other delete item checks here
				if (item:isType("Weapons") or item:isType("Armor")) and sellprize > item.Worth and item.Quality < rarity then
					printf("Deleting Item:  "..item.Name.."\n");
					if logg == true then
						logInfo("CleanBag", "" ..player.Name.. ": Deleted: " ..item.Name.. "." , true)
					end
					item:delete();
				elseif item:isType("Recipes") then
					if RoMScript("GetCraftItemInfo("..item.Id..")") == nil and item.Quality < rarity then -- Don't have it
						printf("Learning recipe:  "..item.Name.."\n");
						if logg == true then
							logInfo("LearnRecipe", "" ..player.Name.. ": Learning recipe:  " ..item.Name.. "." , true);
						end
						item:use();
						yrest(5000);
					else
						if drop == true and item.Quality < rarity then
							printf("Deleting Recipe:  "..item.Name.."\n");
							if logg == true then
								logInfo("LearnRecipe", "" ..player.Name.. ": Deleting recipe:  " ..item.Name.. "." , true);
							end
							item:delete();
						end
					end
				elseif item:isType("Monster Cards") then
					if not haveCard(item.Id) then
						printf("Using card:  "..item.Name.."\n");
						if logg == true then
							logInfo("UseCard", "" ..player.Name.. ": Using card:  " ..item.Name.. "." , true);
						end
						item:use();
						yrest(5000);
					end
				elseif item:isType("Potions") and item.RequiredLvl < player.Level - 10 then
					if not string.find(item.Name, "Phirius") then
						item:delete();
					end
				elseif item:isType("Runes") or item:isType("Production Runes") then
					item:delete();
				end
			end -- keep and delete
		end -- item slot
	end -- for inventory
end -- function end

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Cleanbag userfunction 2.5

#77 Post by kenzu38 » Sun Jan 06, 2013 2:10 pm

Lol my bad, it actually works, I put the new file in the RC3 folder but I may have tested it with RC2.

But yeah, it works well now. Thanks for this! I still think you should add auto-using transmutor charges to this function though. :) But oh well, it's easy enough for me to add that by myself so I'll just customize this code.

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.5

#78 Post by botje » Sun Jan 06, 2013 4:55 pm

woot xd

User avatar
botje
Posts: 656
Joined: Wed Oct 27, 2010 7:17 am

Re: Cleanbag userfunction 2.5

#79 Post by botje » Mon Jan 07, 2013 12:54 pm

Code: Select all

if inventory:itemTotalCount("Arcane Transmutor Charge") > 0 then
     repeat
          inventory:useItem("Arcane Transmutor Charge")
     until inventory:itemTotalCount("Arcane Transmutor Charge") == 0
end
here, for your charges xd

kuripot
Posts: 493
Joined: Mon Nov 07, 2011 9:14 pm

Re: Cleanbag userfunction 2.5

#80 Post by kuripot » Mon Jan 14, 2013 7:25 am

how can i add the item in forced keep?

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests