im having trouble with the WOWItem.stackcount.. it seems to always be returning with stacksize of 20 when its not.. any ideas
public uint GetItemCount(string ItemName)
{
foreach (WoWItem Item in Me.BagItems)
{
if (ItemName == Item.Name)
{
return Item.StackCount;
}
}
return 0;
}
What specifically have you had problems with?I think he is having issues about counting the specific amount of items of a single stack. I had several problems with bags content handling APIs on HB, so I usually rely on WOW APIs...
Check this:
bagIndex=0;
bagSlot=1;
List<string> resultValues = Lua.GetReturnValues("return GetContainerItemInfo(" + bagIndex + ", " + bagSlot + ")", "asd.lua");
if (resultValues != null)
{
int stackCount = 0;
Int32.TryParse(resultValues[1].ToString(), out stackCount);
}
its cool, i like to live dangerously *Sticks hand in alligators mouth*Also please consider than the HB API is not threadsafe. Using it simultaneously from other thread while HB runs is bound to cause issues.
What specifically have you had problems with?
private Boolean prospectOres()
{
Logging.Write("Prospecting ores");
Boolean atLeastAprospectWasDone = false;
foreach (WoWItem item in ObjectManager.GetObjectsOfType<wowitem>())
{
if (minerals.Contains(item.GetItemName()))
{
//Logging.Write("contains: " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot);
if (NumOfItemsInBag(item.Entry) >= 5)
{
//Logging.Write("numitbags " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot + " stackcount: " + item.StackCount);
if (item.StackCount >= 5)
{
WoWMovement.MoveStop();
Thread.Sleep(250);
//Logging.Write("[provo]:Using " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot);
while (item.BagSlot != -1 && item.StackCount >= 5) //
{
SpellManager.Cast(31252);
Thread.Sleep(250);
//Logging.Write(item.StackCount.ToString());
//Logging.Write( "[Prospecting]:Using " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot);
item.UseContainerItem();
Thread.Sleep(4300);
atLeastAprospectWasDone = true;
}
}
}
}
}
return atLeastAprospectWasDone;
}
[CO
I'll make an example:
this piece of code is part of an automated crafting plugin..Code:private Boolean prospectOres() { Logging.Write("Prospecting ores"); Boolean atLeastAprospectWasDone = false; foreach (WoWItem item in ObjectManager.GetObjectsOfType<wowitem>()) { if (minerals.Contains(item.GetItemName())) { //Logging.Write("contains: " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot); if (NumOfItemsInBag(item.Entry) >= 5) { //Logging.Write("numitbags " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot + " stackcount: " + item.StackCount); if (item.StackCount >= 5) { WoWMovement.MoveStop(); Thread.Sleep(250); //Logging.Write("[provo]:Using " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot); while (item.BagSlot != -1 && item.StackCount >= 5) // { SpellManager.Cast(31252); Thread.Sleep(250); //Logging.Write(item.StackCount.ToString()); //Logging.Write( "[Prospecting]:Using " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot); item.UseContainerItem(); Thread.Sleep(4300); atLeastAprospectWasDone = true; } } } } } return atLeastAprospectWasDone; }
this plugin gets ores from my bank, prospects them and stores the gems back. If there are still ores to prospect inside my bank, it starts over.
The first "loop" goes just fine, it withdraws and prospects as intended, but starting from the second loop if fails to prospect. If i make it write the BagIndex and BagSlot coordinates i get that BagSlot is mostly -1, even if that specific slot is full!
So, to write it again (perhaps clearer): The first loop goest just fine, the second loop seems to be mostly unable to properly select a specific item. If i make it write the bag coordinates of every items he is going to prospest, that's what i get:
[Prospecting]:Using Elementium Ore bagID: 0 bagSlot: -1
"bagSlot -1"? why is like that?
So..even if HB properly selected a stack of Elementium Ore, i'm not able to "use" it.
Another issue I had is about counting the amount of free bag slots and the stackCount property of every every item, it seems that HB is not always accurate (but maybe due to lag).
I hope my english is not too crappy, i'm very tired
</wowitem>
This is because GetObjectsOfType<WoWItem> returns every item you have in the buy back frame, equipped and every item you have in the bank.
You probably want to go through each item by using ObjectManager.Me.BagItems. It contains only the items in the bag.
Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
I'll try it asap and i'll let you know. Ty![]()
private Boolean performActionOnItemsInBag(List itemsToClick, int spellNumber, int castDelay) //31252 is prospect, 4300 castDelay
{
Logging.Write("Performing spell N? " + spellNumber + " on some objects");
WoWMovement.MoveStop();
Thread.Sleep(250);
Boolean atLeastAspellWasCast = false;
foreach (WoWItem item in ObjectManager.Me.BagItems)
{
foreach (string nameOfTheItemToClick in itemsToClick) {
if (nameOfTheItemToClick.ToLower().Equals(item.GetItemName().ToLower()))
{
//Logging.Write("contains: " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot);
if (NumOfItemsInBag(item.Entry) >= 5)
{
//Logging.Write("numitbags " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot + " stackcount: " + item.StackCount);
//Logging.Write("[provo]:Using " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot);
while (item.BagSlot != -1 && item.StackCount >= 5) //
{
SpellManager.Cast(spellNumber);
//Logging.Write(item.StackCount.ToString());
//Logging.Write( "[Prospecting]:Using " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot);
item.UseContainerItem();
Thread.Sleep(castDelay);
atLeastAspellWasCast = true;
}
}
}
}
}
return atLeastAspellWasCast;
}
-1 is invalid. just weed it out.Tested it, it doesn't work as intended
My code is like this:
while (true) {
gotoguildbank();
withdraw();
prospect();
while (true) {
craftgems();
sellgems();
if (remainingrawgems == 0) break;
}
and this is the function I use to prospect:
Code:private Boolean performActionOnItemsInBag(List itemsToClick, int spellNumber, int castDelay) //31252 is prospect, 4300 castDelay { Logging.Write("Performing spell N? " + spellNumber + " on some objects"); WoWMovement.MoveStop(); Thread.Sleep(250); Boolean atLeastAspellWasCast = false; foreach (WoWItem item in ObjectManager.Me.BagItems) { foreach (string nameOfTheItemToClick in itemsToClick) { if (nameOfTheItemToClick.ToLower().Equals(item.GetItemName().ToLower())) { //Logging.Write("contains: " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot); if (NumOfItemsInBag(item.Entry) >= 5) { //Logging.Write("numitbags " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot + " stackcount: " + item.StackCount); //Logging.Write("[provo]:Using " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot); while (item.BagSlot != -1 && item.StackCount >= 5) // { SpellManager.Cast(spellNumber); //Logging.Write(item.StackCount.ToString()); //Logging.Write( "[Prospecting]:Using " + item.Name + " bagID:" + item.BagIndex + " bagSlot:" + item.BagSlot); item.UseContainerItem(); Thread.Sleep(castDelay); atLeastAspellWasCast = true; } } } } } return atLeastAspellWasCast; }
On the first loop it works as intended, but starting from the second loop it doesn't work properly anymore. If i make it print the item position it says that it is in "bagIndex xxx" (the right one) and "bagslot -1" for every single object in my bags.
I know it, but it's -1 for every object into the bags. It's like as if after the first loop HB cannot properly set the properties of the Items into the collection. (Just my guess, i'm not a very skilled coder).-1 is invalid. just weed it out.