Page 4 of 6
Re: Cleanbag userfunction 2.4
Posted: Sat Jan 05, 2013 7:06 pm
by lisa
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 =)
Re: Cleanbag userfunction 2.4
Posted: Sat Jan 05, 2013 7:24 pm
by botje
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
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
Re: Cleanbag userfunction 2.4
Posted: Sat Jan 05, 2013 8:03 pm
by lisa
*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
Re: Cleanbag userfunction 2.4
Posted: Sat Jan 05, 2013 8:16 pm
by botje
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
Re: Cleanbag userfunction 2.4
Posted: Sat Jan 05, 2013 8:44 pm
by lisa
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 =)
Re: Cleanbag userfunction 2.4
Posted: Sun Jan 06, 2013 9:20 am
by botje
ok, updated to 2.5, very much credit to lisa, that helped me optimize and fix my mess
Re: Cleanbag userfunction 2.4
Posted: Sun Jan 06, 2013 9:53 am
by lisa
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
they both do exactly the same thing but I just think the second looks nicer and less typing
Re: Cleanbag userfunction 2.4
Posted: Sun Jan 06, 2013 9:54 am
by botje
nice, ill fix that ^^
Re: Cleanbag userfunction 2.4
Posted: Sun Jan 06, 2013 10:16 am
by lisa
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.
Re: Cleanbag userfunction 2.4
Posted: Sun Jan 06, 2013 10:26 am
by botje
lol, it is yours
i just included it so there wont be any, "errors" due to people missing it
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?
im open for suggestions ^^
Re: Cleanbag userfunction 2.4
Posted: Sun Jan 06, 2013 11:23 am
by kenzu38
And I'll wait for the most optimized version. Not gonna download yet.
Re: Cleanbag userfunction 2.4
Posted: Sun Jan 06, 2013 11:48 am
by botje
think you should download it anyway mate, its much better allready , those things dont make a huge difference
also, things work now
Re: Cleanbag userfunction 2.5
Posted: Sun Jan 06, 2013 12:20 pm
by kenzu38
Lol yep, already downloaded it. Might I suggest, though, that you also make the function check for transmutor charges and use all of them.
Re: Cleanbag userfunction 2.5
Posted: Sun Jan 06, 2013 12:45 pm
by botje
but those are in itemshop bag, thats not the thing im trying to clean
Re: Cleanbag userfunction 2.5
Posted: Sun Jan 06, 2013 1:29 pm
by kenzu38
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.
Re: Cleanbag userfunction 2.5
Posted: Sun Jan 06, 2013 1:48 pm
by botje
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
Re: Cleanbag userfunction 2.5
Posted: Sun Jan 06, 2013 2:10 pm
by kenzu38
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.
Re: Cleanbag userfunction 2.5
Posted: Sun Jan 06, 2013 4:55 pm
by botje
woot xd
Re: Cleanbag userfunction 2.5
Posted: Mon Jan 07, 2013 12:54 pm
by botje
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
Re: Cleanbag userfunction 2.5
Posted: Mon Jan 14, 2013 7:25 am
by kuripot
how can i add the item in forced keep?