What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

WoWItem.StackCount !!

BPAlpha

New Member
Joined
Jan 15, 2010
Messages
594
Reaction score
41
im having trouble with the WOWItem.stackcount.. it seems to always be returning with stacksize of 20 when its not.. any ideas
 
im having trouble with the WOWItem.stackcount.. it seems to always be returning with stacksize of 20 when its not.. any ideas
Code:
        public uint GetItemCount(string ItemName)
        {
            foreach (WoWItem Item in Me.BagItems)
            {
                if (ItemName == Item.Name)
                {
                    return Item.StackCount;
                }
            }
            return 0;
        }
thats the method i use when dealing with items in my CC and plugins such as Mr.ItemRemover. so give it a try, if this fails then it might be a bug with the item.
 
Hope you will manage to sort it out, I use Allrounder everyday :)
 
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);
}
 
I seriously doubt it's wrong. Are you sure you don't have any stacks of 20 in yours bags?

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);
}
What specifically have you had problems with?
 
yes main but when i tell HB to interact with item it uses the item with less than required amount in ie herbs need to be in stacks of 5 for milling and trying to use < 5 items..
but plugin is set to check if stackcount is >5 cant understand it
 
Try
Code:
Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
And tell me if that works.
 
how is your plugin setup? are you locking the thread? if so chances are the object manager isnt updating after every transaction. so your stack count and items would never change because HB never gets the chance to update them on the next pulse. try tossing in "ObjectManager.Update();" to force the object manager to update all the objects. add this BEFORE the stack count check. and try adding some logging to see if its returning properly.
"Logging.Write("Stack Count of {0} is {1}", Item.Name, Item.StackCount.ToString());"
like i said before ive never had a problem with it. it just might be the way your program utilities the thread, thats causing the issue.
 
Also please consider than the HB API is not threadsafe. Using it simultaneously from other thread while HB runs is bound to cause issues.
 
Also please consider than the HB API is not threadsafe. Using it simultaneously from other thread while HB runs is bound to cause issues.
its cool, i like to live dangerously *Sticks hand in alligators mouth*
 
[CO
What specifically have you had problems with?

I'll make an example:
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 piece of code is part of an automated crafting plugin..
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 :p): 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>
 
Last edited:
go take a look at the code for Mr.ItemRemover. since C# starts at 0, and wow starts 1, you have to do some werid +1 to each value. just take a look at mr.itemremover and youll see what i mean, its commented.
 
[CO

I'll make an example:
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 piece of code is part of an automated crafting plugin..
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 :p): 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&lt;WoWItem&gt; 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.
 
This is because GetObjectsOfType&lt;WoWItem&gt; 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.

I'll try it asap and i'll let you know. Ty :)
 
Main in all seriously i want to marry you lol.. worked a treat m8 thanks very much
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 :)

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.
 
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.
-1 is invalid. just weed it out.
 
-1 is invalid. just weed it out.
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).
 
That's because you're taking over the entire thread and not giving HB a chance to update anything (something that is VERY bad to do).
You need to call ObjectManager.Update() before you use the object API (note that HB does this automatically every pulse, but as you are taking over the thread it doesn't get a chance to do it).
 
Back
Top