I've found that adding an item and equipping it while the player is in MenuMode causes problems with inventory items. For example, I have a quiver script does a regular scan to see if any stock arrows are equipped and fills the quiver accordingly. I'm not going to post the whole thing as it also tracks the pauldron type and sheaths stock bows, the main script runs in at over 400 lines with additional run once scripts as well as reading and reacting to globals set by other scripts.
If the player removes all their arrows this will cause the script to 'empty' the quiver by swapping the filled quiver with an empty one. If this happened in menumode I got the following problems:
1. The newly added item did not equip.
2. The item(s) currently on pointer also appeared in the inventory box, effectively doubling it. Leaving and entering the menu may or may not correct the count.
After elimination, this is what caused the problem:
if ( Player->GetItemCount,== 0 ) Player->AddItem, , 1endifPlayer->Equip,
By adding a condition that menumode must be 0 before the appropriate add quiver script is started corrected the problem immediately. But of course if the quiver needs to be changed, now the quiver disappears until the player leaves menumode again:
if ( AddQuiver ) Set QTest to EA_Gl_QEID if ( MenuMode == 0 ) ;Select and start an appropriate 'run once' script to do the add/equip ; (EA_Gl_QEID is 0'ed by one of the child scripts) Set AddQuiver to 0 endifendif
I also observed the problem in a script that allows the player to double matching pieces of left/right armour (used to create free equipment slots) which removes the left/right items and replaces it with a dual item (that uses the right slot). This all happens in menumode:
Player->RemoveItem,, 1Player->RemoveItem, , 1Player->AddItem, , 1;Player->Equip, ; Add, but don't auto equip - strange behavior in inventory
At first I thought it might be GetItemCount forcing the engine to do an inventory refresh, however adding a GetItemCount check to this force unequip of a left pauldron, (used when the player equips a dual pauldron that takes the right slot) and it still works fine:
if (Player->GetItemCount, "EA_LPauldron_Dummy" == 0 ) Player->AddItem, "EA_LPauldron_Dummy", 1endifPlayer->Equip, "EA_LPauldron_Dummy"Player->RemoveItem, "EA_LPauldron_Dummy", 1
This leaves me to conclude I should only add and equip an item in menumode if I am immediately removing it again (force un-equipping something), otherwise I should wait until the player leaves menu mode and then add the appropriate sheath/slung shield/quiver. I'm new at this, so I could be getting it wrong, I'm seeking experience - am I completely off here, does anyone know any better?
Edit: Couple of typos removed.