Use
DelayCommand on the
CreateItemOnObject call within the while loop (0.1 duration ought to do it). That should solve your issue I think. But when you do, all the
GetGoldInContainer functions will start exhibiting inaccuracies because the gold won't go in until after the script ends. What you really need is to keep track in a counter of how much gold is put in the chest within the loop instead of actually creating it there. Then you can make one call to create it all after the loop ends and before the
GetGoldInContainer's go off. Or just use your counter directly instead of calling those functions (assuming there was no gold in the chest to begin with, if so just initialize the counter using -
GetGoldInContainer before the loop). Something like Monk posted.
Also,
oItems must be invalid after the loop, or else it would not have ended. Thus the
DestroyObject( oItems ) call in the first if-stmt following the loop is having no effect. So whatever it was you were thinking needed to get destroyed there isn't getting whacked. Might as well delete that line if you don't need it.
Another thing, gold heaps in inventory have a maximum stack limit. As long as you are working with small stack sized donations, which it looks like you're doing, then you'll be ok. But there will come a point where
10 *nNumberM1 will necessarily exceed that limit. The result will be that you will only get one heap of maximum size in the chest and lose all the excess.
If you wanted to handle that possibility, you could make a function that wraps the create call so it will loop and create multiple heaps in the chest until the full amount has been deposited there. Something like:
void CreateGoldInChest( object oChest, int nGold )
{ while( nGold > 0 )
nGold -= GetItemStackSize( CreateItemOnObject( "NW_IT_GOLD001", oChest, nGold ));
}
Then
DelayCommand( 0.1, CreateGoldInChest( oContainer, 10 *nNumberM1 )) in your loop.
But it looks like you probably need not worry about it.
Modifié par Axe_Murderer, 17 juillet 2013 - 10:07 .