Jump to content
⚠ Known Issue: Media on User Profiles ×

More CK Scripting Fun: Placing Outfit Items In Inventory


bluemarvin

Recommended Posts

Thanks for any assistance on this.

 

I'm trying to create an effect similar to UFO mod, where a follower's invisible outfit items get placed in the follower's inventory, so you can more easily change their outfits. I want this to happen when the follower enters a trigger.

 

Here's the code as it currently stands:

	Actor akactionRef = triggerRef as Actor

	If akActionRef != Game.GetPlayer()
		Outfit OrigOutfit = akActionRef.GetActorBase().GetOutfit()
		Int NumPart =OrigOutfit.GetNumParts()
		while NumPart
			Numpart -= 1
			Form MyClothing = OrigOutfit.GetNthPart(NumPart)
			akActionRef.AddItem (MyClothing,1,True)
		EndWhile

		akActionRef.SetOutfit (NewOutfit)

	EndIf

The outfit gets changed as planned, but the original outfit items don't seem to make it into the follower's inventory. Anyone see any problems here? I tried casting the Form as Armor, even as ObjectReference for a hoot, the script compiles but no satisfaction. :(

Link to comment
Share on other sites

The plot thickens. If I change the destination for each item to a chest instead of the actor, the items show up in the chest. But, I can't get them to show up in the follower's inventory now matter what. And I know the actor ref is set right, because the actor's outfit changes fine via the SetOutfit call, so the akActionRef is indeed pointing at my target.

 

Sigh... two to three hours wasted on this alone. :(

Link to comment
Share on other sites

An alternative I can think of is first storing the equipped items and sending them to an array. Basically making your own get outfit function but allowing you to pull the pieces out when ready. See where i m going with this?
Link to comment
Share on other sites

Well, I haven't tried the array... but I did try using the RemoveAllItems (akActionRef) approack to try and move everything from the chest back to the follower... and the items disappear out of the chest, but don't end up with the follower. :(

 

Adding to the Scooby Doo mystery... if I create a Armor Property and set it to say a robe, then use AddItem() to place that robe directly in the actor's inventory, it shows up. AARRGGH!!! Why then, why not the others?!

 

So I tried to set the MyClothing variable from the above code as a property and... of course, no luck.

 

The Creation Kit is really inconsistent, can drive you crazy.

Link to comment
Share on other sites

Just when I was about to give up for the night (and I hate not solving a coding problem before sleep) I came up with something that works.

 

This is a solution to auto-stripping NPCs (and the player) when they enter a trigger area (such as a swimming pool) so they aren't swimming with their armor on. There was a tutorial posted on this site about one way to do this, and I used that approach for the magic spell and it's effect referenced in the below script. But that solution wasn't enough because NPCs sometimes use outfits that can't be unequipped, so in those cases the linked tutorial won't work (for example on Lydia). So this script addresses that problem, and it does it in a way where there aren't problems if you have multiple NPCs enter the trigger area around the same time.

 

This script below is attached to a trigger over a swimming pool. When the player enters the trigger area, it simply un-equips all his items, so he's in his underwear. That's the easy part.

 

When an NPC enters, it's more problematic because they often use "outfits" that are hidden and can't just be unequipped. So with an NPC, the script first creates each piece of their outfit and places it it a chest hidden from sight. It then changes the NPC's outfit to one that contains nothing but a simple ring, which basically means they're in their underwear. It then moves everything from the chest back into the NPC's inventory and THEN hits the NPC with the unequip spell, so they don't just instantly re-equip all the armor that just got added back in.

 

When either the player or the NPC leave the trigger area, the spell is dispelled. Players can re-equip manually whenever they want, while NPCs will automatically equip their best armor.

 

Here's the final script, in case anyone else ever reads this thread and wants to do the same thing:

Scriptname ActorOutfitTriggerScript extends ObjectReference  

spell property MyUnequipActorSpell auto
Outfit Property NewOutfit Auto
Armor Property MyArmorRef Auto
ObjectReference Property HoldingChest Auto

Event OnTriggerEnter (ObjectReference triggerRef)

	Actor akactionRef = triggerRef as Actor

	If akActionRef != Game.GetPlayer()

		Outfit OrigOutfit = akActionRef.GetActorBase().GetOutfit()
		Int NumPart = OrigOutfit.GetNumParts()
		while NumPart
			Numpart -= 1
			MyArmorRef = OrigOutfit.GetNthPart(NumPart) as Armor
			HoldingChest.AddItem (MyArmorRef,1,True)
		EndWhile

		akActionRef.SetOutfit (NewOutfit)
		HoldingChest.RemoveAllItems (akactionref)

	EndIf

	MyUnequipActorSpell.cast(akactionref,akactionref)

endEvent


Event OnTriggerLeave (ObjectReference triggerRef)

	Actor akactionRef = triggerRef as Actor
	akActionRef.dispelspell(MyUnequipActorSpell)

endEvent 
Link to comment
Share on other sites

UFO, just uses

removeallitems() to strip the npc's items to a container.

then uses removeallitems() to move all the items from the container back to the npc.

Apart from that UFO uses crossfade (fade to black) before the removal and after the 2nd removal (fade from black).

 

UFO doesn't use Unequip or check actor slots at all.

Basically it's 4 ~ 5 small 1 line functions in a fragment.

No slot checks or loops for UFO "You could dress better" option.

 

Funny as UFO "Train some, you are weak" option actually uses the same code as "You could dress better" option.

 

The only reason the follower NPC will put your clothes you give them is because UFO always leaves the 2nd Teammate parameter as True, even when the follower is dismissed.

Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

Hmm, my first attempt was to use the "unequipall()" approach documented in the tutorial that I linked. That worked for NPCs not using outfits, but not for NPCs with outfits like Lydia.

 

I did not try the "removeallitems()" approach you mention here, didn't know it would get at hidden outfit items, but if it works it would be simpler with less that could go wrong than what I did, so maybe I'll play around with that too just to see if I can get it to work. Would simplify my script for sure.

 

Thanks for the comments.

Link to comment
Share on other sites

OK so tested this... and a few things:

 

1) Using RemoveAllItems() to move everything from an NPC over into a chest, and then back to the NPC, DOES work quite nicely, and it's easier than what I did.

 

2) However, this will not cause the same behavior as UFO for me.

 

With UFO, if I tell the follower that he/she can dress better, their armor that was hidden is suddenly placed in their inventory. I can now take the armor by trading items with them, and give them anything else to wear. With the RemoveAllItems() method combined with the strip spell from the tutorial, it does in fact cause the NPC to strip down to their undies. But while in that state if you initiate a trade with the NPC follower you won't see their outfit items in their inventory, as you do with UFO.

 

The longer script that I posted above WILL cause their inventory items to show up in their inventory so you can take them if you want, just like in UFO.

 

Thanks again for the idea. For my purposes, it works better than my own longer solution.

Edited by bluemarvin
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...