Page 1 of 1
any code to detect if a card is owned?
Posted: Mon Nov 26, 2012 1:27 pm
by botje
as title, any snippets that help me detect if a monster card is owned or not?
thanx in advance
Re: any code to detect if a card is owned?
Posted: Mon Nov 26, 2012 5:53 pm
by grande
Hey howdy botje. There is an addon that will paint "learned" or unlearned in green/red on the card. Maybe something from the addon could be modded to meet your needs in a script but I'm not sure. Sorry couldn't help more.
Re: any code to detect if a card is owned?
Posted: Mon Nov 26, 2012 11:14 pm
by rock5
Ok made a little function. tag: havecard
Code: Select all
function haveCard(idorname)
if type(idorname) == "string" and type(tonumber(idorname)) ~= "number" then
idorname = "\""..idorname.."\""
end
return RoMScript("} for x=0,15 do "..
"local cc=LuaFunc_GetCardMaxCount(x) "..
"if cc~=nil and cc>0 then "..
"for y=1,cc do "..
"local i,f,n=LuaFunc_GetCardInfo(x,y-1) "..
"if i=="..idorname.." or n=="..idorname.." then "..
"a={f==1} "..
"end "..
"end "..
"end "..
"end z={")
end
It accepts names or ids. Note: it only accepts the creature name, not the full card name. So this
wont work.
But these will
Code: Select all
haveCard("Abyssal Shadow")
haveCard(771059)
haveCard("771059")
Of course you will still need to look for cards in your inventory. Let me know if you need help with that too.
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 3:04 am
by botje
nice rock
Code: Select all
function CleanBag(sellprize, rarity, drop)
inventory:update();
if sellprize == nil then sellprize = 750 end;
if rarity == nil then rarity = 1 end;
if drop == nil then drop = false end;
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
if (item:isType("Weapons") or item:isType("Armor")) and sellprize > item.Worth and item.Quality < rarity then
printf("Deleting Item: "..item.Name.."\n");
item:delete()
logInfo("CleanBag", "Deleted: " ..item.Name.. "." , true)
elseif item:isType("Recipes") then
if RoMScript("GetCraftItemInfo("..item.Id..")") == nil then -- Don't have it
printf("Learning recipe: "..item.Name.."\n");
logInfo("LearnRecipe", "Learning recipe: " ..item.Name.. "." , true)
item:use();
yrest(5000);
else
if drop == true then
printf("Deleting Recipe: "..item.Name.."\n");
item:delete()
end
end
elseif item:isType("Monster Cards") then
end
end
end
end
i would like to put that in my cleanbag function, but would i use item:id to pass it on to the function you made?
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 3:52 am
by rock5
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 4:21 am
by botje
and what exactly does it return? i cant seem to get that from your function, true/false, or 1/2 or???
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 4:52 am
by rock5
Sorry, true or false (or nil I guess if it doesn't make a match). So you would use it like this for example
Code: Select all
if haveCard(item.Id) then
item:delete()
else
item:use() yrest(3000)
end
If you're curious, it gets the true or false from "a={f==1}". When a RoMScript is written like that ie "} some code; a={somevalues} z={" then it returns the values in 'a'. 'f' is the flag of whether you have the card or not. If you do have the card then 'f' should be 1. f==1 is either true or false so the "a={f==1}" will return true or false. I hope that made some sense.
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 5:43 am
by lisa
I am just amazed you got it all into a single macro =)
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 6:14 am
by rock5
It was easy, still plenty of room. I still remember what I went through creating the code that gets all the item types from the game. The initial code took about 15 seconds I think or maybe longer, I don't remember exactly. Doing a RoMScript for each type probably meant it was doing well over 120 RoMScripts. Now I think it does it in about 15. Takes about 2.5s

.
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 6:25 am
by botje
now all i need is a way to use the recipe color to keep everything from that color upwards and my cleanbag is done
thanx rock ^^
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 6:31 am
by rock5
That should be easy. 'item' has a Quality value after all.
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 6:32 am
by botje
i could not find that on the recipe one O.o
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 6:42 am
by rock5
All inventory items have Quality even recipes.
Code: Select all
Command> print(inventory.BagSlot[61].Name)
Recipe - Tador's Brilliant Armor
Command> print(inventory.BagSlot[61].Quality)
3
Re: any code to detect if a card is owned?
Posted: Tue Nov 27, 2012 6:46 am
by botje
cool, then its indeed easy, thanx ^^