EquipItem in loot menu

Post » Tue Nov 20, 2012 8:32 am

I'm pretty new to scripting so I'm hoping someone with more experience can help with a simple piece of code. Basically, I want to equip a piece of clothing to a corpse as soon as another clothing or armor is looted from it. I have the code set up to do this, but it doesn't run until the loot menu is closed, meaning the item isn't equipped until after you're done looting. What I need is a way to keep the code running while the player is in the loot menu.

I have a feeling that's it's not possible, but if it is, hopefully someone can offer some advice.

Another way I can possibly do this is to equip the item when the actor is alive but make it invisible while another piece of clothing or armor is equipped. I tried messing with the priority setting in the ARMA record, but had no luck.
User avatar
Portions
 
Posts: 3499
Joined: Thu Jun 14, 2007 1:47 am

Post » Tue Nov 20, 2012 12:29 am

Hello. I did something similar a couple of months ago.

This can be done through a perk on the player that reacts to activation (open the perk window and searches for it, I do not remember the details). Your papyrus fragment will be fired instead of the regular activation process. So you will have to use a command (do not remember which one) to perform the default activation once you're done swapping the items. I also advise you to put a token or something that will prevent your perk to be fired again on this target.
User avatar
Mark
 
Posts: 3341
Joined: Wed May 23, 2007 11:59 am

Post » Mon Nov 19, 2012 9:08 pm

Perhaps use http://www.creationkit.com/OnContainerChanged_-_ObjectReference
OnContainerChanged detect if moved to player inventory, you also get an reference to the corpse you looted.
However not sure how well equipitem works on dead actors.
User avatar
sarah simon-rogaume
 
Posts: 3383
Joined: Thu Mar 15, 2007 4:41 am

Post » Mon Nov 19, 2012 5:47 pm

However not sure how well equipitem works on dead actors.
It does work on dead actors. And afaik dead actors cannot suddenly choose to re-requip another item, as opposed to alive actors.
User avatar
David Chambers
 
Posts: 3333
Joined: Fri May 18, 2007 4:30 am

Post » Mon Nov 19, 2012 9:11 pm

This can be done through a perk on the player that reacts to activation (open the perk window and searches for it, I do not remember the details). Your papyrus fragment will be fired instead of the regular activation process. So you will have to use a command (do not remember which one) to perform the default activation once you're done swapping the items.
So, just to be clear, add a perk to the actor that checks if the actor is activated, then fire a script which equips the required item. The problem with my current script is that the EquipItem function doesn't fire until after the loot menu is closed, so using an OnActivate would solve this I assume (Makes sense to me).

Perhaps use http://www.creationkit.com/OnContainerChanged_-_ObjectReference OnContainerChanged detect if moved to player inventory, you also get an reference to the corpse you looted. However not sure how well equipitem works on dead actors.
I don't think this would work because the item I'm trying to equip is already in the actor's inventory. It only equips if the actor isn't wearing anything with the keywords ArmorCuirass and ClothingBody. I could probably find a way to use this, but I think OnActive is a simpler solution.

Thanks for the replies, I'll test your suggestions when I get home and post the results.
User avatar
His Bella
 
Posts: 3428
Joined: Wed Apr 25, 2007 5:57 am

Post » Tue Nov 20, 2012 4:22 am

So, just to be clear, add a perk to the actor that checks if the actor is activated
No, add a perk to the player that replaces the standard action when the player activates something. ;)
* EntryPoint: Activate/Add Activate Choice (do not worry, no choice will be displayed)
* Checks Run Immediately and ReplaceDefault

The problem with my current script is that the EquipItem function doesn't fire until after the loot menu is closed, so using an OnActivate would solve this I assume (Makes sense to me).
If I remember well, the OnActivate papyrus event is only fired after the menu is closed.
On the contrary, the trick with the perk I presented is that it is obviously ran before the loot menu is opened since it is made to allow modders to display a menu (for the cannibal perk for example).
User avatar
Sammie LM
 
Posts: 3424
Joined: Thu Nov 30, 2006 1:59 pm

Post » Tue Nov 20, 2012 4:29 am

Ah I see, but I don't want to swap the items immediately on activation, only if the player chooses to remove a certain piece of clothing. So if the player doesn't remove the required item, my script shouldn't run. The script works perfectly on actors who are alive, even in the trade menu, but not on dead actors(because, as you said, dead actors cannot suddenly choose to re-equip items).
User avatar
Jeneene Hunte
 
Posts: 3478
Joined: Mon Sep 11, 2006 3:18 pm

Post » Tue Nov 20, 2012 6:48 am

Oh, my apologies. Then what you need to use is OnItemAdded (on a magiceffect on the player) or OnItemRemoved (on a magic effect on the corpse). The magic effects should be added through abilities. The player version is of course easier to implement, while the target version would still require the use of a perk similar to what I described. Both events provide the source/target container reference and the transfered item reference.
User avatar
D LOpez
 
Posts: 3434
Joined: Sat Aug 25, 2007 12:30 pm

Post » Mon Nov 19, 2012 7:07 pm

Would the script run while in the loot menu? My script is basically doing this already, but instead of OnItemRemoved, I'm using WornHasKeyword for the keywords ArmorCuirass and ClothingBody. As soon as these return false, it equips the item, though it only checks outside the loot menu.
User avatar
Zach Hunter
 
Posts: 3444
Joined: Wed Aug 08, 2007 3:26 pm

Post » Tue Nov 20, 2012 5:19 am

Would the script run while in the loot menu? My script is basically doing this already, but instead of OnItemRemoved, I'm using WornHasKeyword for the keywords ArmorCuirass and ClothingBody. As soon as these return false, it equips the item, though it only checks outside the loot menu.
The question is when do you fire this check? I guess you do so through OnUpdate and the wiki explicitly states that this one is not fired in menu mode. Other events are still fired afaik, but I never tested it.
User avatar
David John Hunter
 
Posts: 3376
Joined: Sun May 13, 2007 8:24 am

Post » Tue Nov 20, 2012 7:12 am

I'll post the code for you when I get home, but what I'm doing is applying a magic effect that runs my script using the OnEffectStart event. After I add the required items and tokens, I check for the two keywords and if they are not there, I equip the items. I'm pretty sure the problem is that OnEffectStart doesn't run in the loot menu.
User avatar
Jessica Phoenix
 
Posts: 3420
Joined: Sat Jun 24, 2006 8:49 am

Post » Tue Nov 20, 2012 1:19 am

Here's the code. I'm trying to add underwear that only equips when the actor's body is naked. It works fine except if the actor is dead, in which case you can see the naked body while in the loot menu.
Spoiler

Scriptname UnderwearScript extends ActiveMagicEffectArmor Property UnderwearBra AutoArmor Property UnderwearPanties AutoMiscObject Property UnderwearToken AutoKeyword Property ArmorCuirass AutoKeyword Property ClothingBody AutoEvent OnEffectStart(Actor Target, Actor Caster)if Target.GetItemCount(UnderwearBra) == 0.0 && Target.GetItemCount(UnderwearToken) == 0.0 && Target.GetItemCount(UnderwearPanties) == 0.0  Target.AddItem(UnderwearToken)  Target.AddItem(UnderwearBra)  Target.AddItem(UnderwearPanties)Endifif Target.WornHasKeyword(ArmorCuirass) ==  1.0 || Target.WornHasKeyword(ClothingBody) == 1.0  Target.UnEquipItem(UnderwearBra)  Target.UnEquipItem(UnderwearPanties)Endifif Target.IsDead() == 1.0 && Target.WornHasKeyword(ArmorCuirass) ==  0.0 && Target.WornHasKeyword(ClothingBody) == 0.0  if Target.GetItemCount(UnderwearBra) == 1.0   Target.EquipItem(UnderwearBra)  Endif  if Target.GetItemCount(UnderwearPanties) == 1.0   Target.EquipItem(UnderwearPanties)  EndifEndifEndEvent
I tried my hand at the perk script fragment but I don't know how it works. I can't seem to compile anything useful, Got it to work but I can only use functions from the Form script.
User avatar
Tanika O'Connell
 
Posts: 3412
Joined: Fri Jan 26, 2007 1:34 am

Post » Mon Nov 19, 2012 5:37 pm

The problem with your script is likely related to how you apply this effect. Through a cloak? Since a cloak rely on a timer, it would be logical if it were not ran when the loot menu is opened. I guess you won't have this problem with the solution I suggested.
Now, I do not understand why you're trying to add a perk fragment since you do not need those with the latest solution I am talking about.
User avatar
Vincent Joe
 
Posts: 3370
Joined: Wed Sep 26, 2007 1:13 pm

Post » Tue Nov 20, 2012 4:16 am

I thought your latest solution was to add perk fragments lol. Do you mean apply an ability on the actor which contains the script? In that case I'll use the cloak to add a new spell to the actor which contains the script(unless there's a better way of dynamically adding scripts to actors?)

I doubt it'll work, anyways. I've come to the conclusion that there's no way to get a script to run while in the loot menu without changing the code for the menu itself. My script works fine in the regular trade menu, when it tells the game to equip the underwear, it does it right away - during the trade, while the game is paused. There's no time where the actor is naked. When I try the same thing in the loot menu, it waits until the game unpauses to equip the underwear.

Either this is happening because the menus operate differently or because of the fact the actor is dead. I'll try your latest solution and let you know how it goes tomorrow.
User avatar
Project
 
Posts: 3490
Joined: Fri May 04, 2007 7:58 am

Post » Mon Nov 19, 2012 9:42 pm

I thought your latest solution was to add perk fragments lol. Do you mean apply an ability on the actor which contains the script?
I mean to apply an ability on the player himself and only on the player, with a script that hooks OnItemAdded. No need for a cloak. :smile:
Now maybe you are right and no script can be ran when the loot menu is opened but nothing from what you did so far allows you to reach that conclusion (again my suspicion was that your effect was not applied while yours is that the script attached to it was not fired). Besides I would be very surprised if OnItemAdded was not fired.
User avatar
neen
 
Posts: 3517
Joined: Sun Nov 26, 2006 1:19 pm

Post » Tue Nov 20, 2012 3:56 am

Alright, I'll give it a try. Hopefully you're right, but what I don't understand why it works in the trade menu and not in the loot menu :brokencomputer:.
User avatar
Julia Schwalbe
 
Posts: 3557
Joined: Wed Apr 11, 2007 3:02 pm

Post » Tue Nov 20, 2012 7:59 am

It worked!....Well, kind of. The script fired in the loot menu but there's a second where the actor is naked before the item is equipped. And when it equips, it doesn't load the model until the menu is closed so the body becomes invisible. I had to use OnItemRemoved because OnItemAdded wouldn't let me use EquipItem. It's not perfect but It's a start. Now I need to find a way to reduce the time it takes for the corpse to equip the item.
Spoiler

Scriptname UnderwearDeathEquip extends ActiveMagicEffectArmor Property UnderwearBra AutoArmor Property UnderwearPanties AutoKeyword Property ArmorCuirass AutoKeyword Property ClothingBody AutoEvent OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)Actor Target = GetCasterActor()if Target.WornHasKeyword(ArmorCuirass) ==  0.0 && Target.WornHasKeyword(ClothingBody) == 0.0  if Target.GetItemCount(UnderwearBra) == 1.0   Target.EquipItem(UnderwearBra)  Endif  if Target.GetItemCount(UnderwearPanties) == 1.0   Target.EquipItem(UnderwearPanties)  EndifEndifEndEvent
User avatar
lucile
 
Posts: 3371
Joined: Thu Mar 22, 2007 4:37 pm

Post » Tue Nov 20, 2012 4:52 am

Well, good news. :)
I suggest you try to add the item replacement in the inventory before the menu is opened, through the perk-activate trick I described earlier. Then, when the original item is looted, it will only have to equip it, maybe this will be faster?
User avatar
kevin ball
 
Posts: 3399
Joined: Fri Jun 08, 2007 10:02 pm

Post » Tue Nov 20, 2012 1:20 am

The replacement is already in the inventory. It's put there as soon as the cell loads with the cloak spell.
User avatar
[ becca ]
 
Posts: 3514
Joined: Wed Jun 21, 2006 12:59 pm


Return to V - Skyrim