Awhile back an issue was addressed on my shard where Vendors were removing gold from Alpha's Gold Ledger AND a Player's bankbox (duplicate withdrawals). Thinking the problem had been solved, I haven't given it much thought. However, a player recently reported that vendors would not sell items at all. A message was appearing stating that XX gold was withdrawn from your (backpack/ledger/bankbox), but it wasn't actually happening. So I took a look at the script for BaseVendor and this was the fix that was put into place:
Now onto the "fun" part. What I have discovered is that if a player HAS a Gold Ledger, but it has no gold in it, vendors will not sell the player anything, but the player will still get the message the gold has been withdrawn from (backpack/ledger/bankbox). I'm assuming at this point I'm going to have to add an additional Else If statement to cover a Gold Ledger that has no gold...correct?
EDIT:
I've added another Else If statement to withdraw the gold from the player's bankbox and it does work (but it has to be loose gold, checks are ignored) and if the player has NO loose gold in their bankbox, the purchase list stays on their screen and they get no message that they are lacking the funds. So it seems that no matter what, I'm getting hung up in this loop. Here is the code with the new section:
Adding an additional Else didn't help as far as if all of the above wouldn't work. *throws hands in the air*
Code:
if (buyer.Backpack != null)
{
Item item = buyer.Backpack.FindItemByType(typeof(GoldLedger));
GoldLedger ledger = item as GoldLedger;
Item[] item2 = buyer.Backpack.FindItemsByType(typeof(Gold));
int goldint = 0;
foreach (Item item3 in item2)
goldint += item3.Amount;
if (buyer.Backpack.ConsumeTotal(typeof(Gold), totalCost))
{
if (Core.Debug) buyer.SendMessage(2125, "{0} gold has been withdrawn from your backpack.", totalCost.ToString("#,0"));
bought = true;
}
else if (ledger != null)
{
if (goldint > 0 && (goldint + ledger.Gold) >= totalCost)
{
buyer.Backpack.ConsumeTotal(typeof(Gold), goldint);
if (Core.Debug) buyer.SendMessage(2125, "{0} gold was taken from your backpack.", goldint.ToString("#,0"));
ledger.Gold -= (totalCost - goldint);
if (Core.Debug) buyer.SendMessage(2125, "The balance of {0} gold was withdrawn from your gold ledger.", (totalCost - goldint).ToString("#,0"));
bought = true;
fromLedger = true;
}
else if (ledger.Gold >= totalCost)
{
ledger.Gold -= totalCost;
if (Core.Debug) buyer.SendMessage(2125, "{0} gold has been withdrawn from your gold ledger.", totalCost.ToString("#,0"));
bought = true;
fromLedger = true;
}
}
}
Now onto the "fun" part. What I have discovered is that if a player HAS a Gold Ledger, but it has no gold in it, vendors will not sell the player anything, but the player will still get the message the gold has been withdrawn from (backpack/ledger/bankbox). I'm assuming at this point I'm going to have to add an additional Else If statement to cover a Gold Ledger that has no gold...correct?
EDIT:
I've added another Else If statement to withdraw the gold from the player's bankbox and it does work (but it has to be loose gold, checks are ignored) and if the player has NO loose gold in their bankbox, the purchase list stays on their screen and they get no message that they are lacking the funds. So it seems that no matter what, I'm getting hung up in this loop. Here is the code with the new section:
Code:
if (buyer.Backpack != null)
{
Item item = buyer.Backpack.FindItemByType(typeof(GoldLedger));
GoldLedger ledger = item as GoldLedger;
Item[] item2 = buyer.Backpack.FindItemsByType(typeof(Gold));
int goldint = 0;
foreach (Item item3 in item2)
goldint += item3.Amount;
if (buyer.Backpack.ConsumeTotal(typeof(Gold), totalCost))
{
if (Core.Debug) buyer.SendMessage(2125, "{0} gold has been withdrawn from your backpack.", totalCost.ToString("#,0"));
bought = true;
}
else if (ledger != null && ledger.Gold != 0)
{
if (goldint > 0 && (goldint + ledger.Gold) >= totalCost)
{
buyer.Backpack.ConsumeTotal(typeof(Gold), goldint);
if (Core.Debug) buyer.SendMessage(2125, "{0} gold was taken from your backpack.", goldint.ToString("#,0"));
ledger.Gold -= (totalCost - goldint);
if (Core.Debug) buyer.SendMessage(2125, "The balance of {0} gold was withdrawn from your gold ledger.", (totalCost - goldint).ToString("#,0"));
bought = true;
fromLedger = true;
}
else if (ledger.Gold >= totalCost)
{
ledger.Gold -= totalCost;
if (Core.Debug) buyer.SendMessage(2125, "{0} gold has been withdrawn from your gold ledger.", totalCost.ToString("#,0"));
bought = true;
fromLedger = true;
}
}
else if (buyer.BankBox.ConsumeTotal(typeof(Gold), totalCost))
{
if (Core.Debug) buyer.SendMessage(2125, "{0} gold has been withdrawn from your bank.", totalCost.ToString("#,0"));
bought = true;
fromLedger = false;
}
}
Adding an additional Else didn't help as far as if all of the above wouldn't work. *throws hands in the air*
Last edited: