private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player" && aw) // checks if the auto-win conditions are met
{
if (!dropped) // a private variable to ensure no repeated activations
{
ORK.GlobalEvents.Get(0).Call(gameObject); // global event to 'kill' the enemy in the field
int cash = 0; int xp = 0; // initialise 'totals' to be added
List<IShortcut> list = new List<IShortcut>(); // list of items to be dropped
foreach (Combatant c in troop)
{
cash += c.Inventory.GetMoney(0); xp += c.Status[9].GetValue(); // track totals
// Fill 'list' with the currently iterating combatant's inventory
c.Inventory.GetAll(false, false, true, false, true, false, false, false, -1, true, ref list);
foreach (IShortcut item in list)
{
print(item.GetName()); // debugging: make sure the entire inventory is listed
c.Inventory.Drop(item, 1, false, false); // drop the item for the player to collect
}
}
foreach (Combatant pc in player_group)
{
// Grant each ally the total EXP gain only showing one batch of flying text
if (pc.ID == 0)
pc.Status[9].AddValue(xp, false, false, true, false, true, false, null);
else
pc.Status[9].AddValue(xp, false, false, true, false, false, false, null);
}
ORK.Game.ActiveGroup.Inventory.AddMoney(0, cash, true, false); // gain currency total
dropped = true; // prevent repeated activations
}
}
}
What usually happens is that when an enemy is 'auto-defeated', it SHOULD be dropping several items (as determined in the print call during tests) but only one item collecter is created (containing only one item), and occasionally - though usually after one has already been generated - won't drop anything at all.It looks like you're new here. If you want to get involved, click one of these buttons!
There's a Drop function in the inventory that takes the item list as parameter and drops them all - it's the same that's used by the Drop Items node and just calls the function you're using for each item.
I haven't tested your code, but I've just tested that event node, and that works fine.
Also, you can pass on -1 (instead of 1) to drop the actual quantity of the item, instead of just 1 :)
Edit: Are you using individual or group inventory? If you're using group inventory, going through the whole troop would be useless, as the first already dropped the whole inventory.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
The item prefabs are set up, I've only been testing with the one item for the moment so haven't even encountered a situation where it would have come up yet.
As I said in my original post, I have tried dropping the whole list at once. To be sure I've tested it again and still had the same issue - only one item prefab is dropped, containing a single item, and occasionally for no observable reason drop nothing at all.
I thought it might be an issue with calling the drop method multiple times in a single frame, so I tried putting the iteration through a coroutine that waited briefly after each drop (and after each list drop) but no change.
I have considered using an Event to drop the inventory, a Select Items node could store the combatants' inventories but I found the Drop Items node could only drop specific items rather than any saved data, is there a workaround for that I'm not seeing?
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Thank you very much!