Problems force equipping items on player in MenuMode

Post » Sat May 28, 2011 9:29 am

Sandman and I are working on a comprehensive sheathing mod for all stock equipment and this problem has come to light a couple of times. He's done hundreds (and hundreds) of awesome meshes; I'm responsible for making them 'do suff'' as intuitivley as possible. I want to check this with you guys to see if a more experienced scripter might have encountered/fixed/worked around similar problems.

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.
User avatar
Trent Theriot
 
Posts: 3395
Joined: Sat Oct 13, 2007 3:37 am

Post » Fri May 27, 2011 11:27 pm

I think you can do very little involving player animation in menu mode, better wait to exit from menu mode.
User avatar
Ricky Rayner
 
Posts: 3339
Joined: Fri Jul 13, 2007 2:13 am

Post » Fri May 27, 2011 8:10 pm

Thanks abot, that answers my question. Now I have an answer for the testing phase:

Playtester: My equipment doesn't update until I leave the menu.
Me: I know, it's not really possible to do otherwise.
Playtester: Really?
Me: Yup, the dude who made guars ridable said so.
Playtester: Uh, OK.

:biggrin:
User avatar
Sandeep Khatkar
 
Posts: 3364
Joined: Wed Jul 18, 2007 11:02 am

Post » Fri May 27, 2011 11:05 pm

I just wanted to add that I found the problem I was having here. I did some testing and basically if an equipped item is removed from the player by a script using RemoveItem some kind of ghost off the item remains, and this would create various weird errors. It seems that the engine's trigger to clean this up is when you leave MenuMode. If are not in menu mode when the item is removed you have to enter and then leave before normal behaviour of that equipment slot returns. I've worked around this using two different methods:

If swapping something out:
1. Add and equip the replacement item first, and then immediately remove the now unequipped item.

If removing something without a replacement item:
2. If nothing is being added 'cleanse' the equipment slot by adding, equipping, then removing a dummy item and then remove the object. eg.:
Player->AddItem, "Dummy_LPauldron", 1Player->Equip, "Dummy_LPauldron"Player->RemoveItem, "Dummy_LPauldron", 1;Now the original equipped object is safe to remove.

User avatar
stacy hamilton
 
Posts: 3354
Joined: Fri Aug 25, 2006 10:03 am


Return to III - Morrowind