It looks like you don't really know what you're doing, and you've copy and pasted the code from somewhere and hacked at it hoping it will work.
If you're going to want the amount of items in your bag, maybe use something like this instead of lua:
Code:
static int NumOfItemsInBag(uint entry) {
int count = 0;
foreach(WoWItem item in StyxWoW.Me.BagItems.Where(i => i.Entry == entry))
{
count += (int)item.StackCount;
}
return count;
}
is
As for the MerchantList, that code will get every instance of a WoWUnit including players (cuz wowplayer is a derivative of wowunit). If you only want units and not derived classes (ie, players), do this:
Code:
List<wowunit> Merchantlist = ObjectManager.GetObjectsOfType<wowunit>(false);
If you only want vendors, do this:
Code:
List<wowunit> Merchantlist = ObjectManager.GetObjectsOfType<wowunit>(false).Where(unit => unit.IsVendor).ToList();
And then fuck off using a second list to hold vendors. I'd also recommend not using lua to buy items, rather use something like Styx.Logic.Inventory.Frames.Merchant.MerchantFrame.BuyItem(int index, int amount)
Other than that your code is pretty horrible in implementation and I wouldn't be surprised if it worked at all. It's a nice try, but I really would recommend learning a bit more about how HB works and c# in general.