Hoamaii Posted April 11, 2014 Share Posted April 11, 2014 Hi guys, I'm trying to get Followers to unequip weapons, shield and torches when entering a trigger box - basically the idea is to sheathe all weapons and get their hands free. But obviously, I've got it wrong by using the "UnequipItemSlot" function which only seems to work for armor slots. Can one of you perhaps help me get this right? Here's what I've been trying: Event OnTriggerEnter(ObjectReference akActionRef) actor who = akActionRef as actor if who != Game.GetPlayer() && who.IsInFaction(CurrentFollowerFaction) If (who.IsOnMount() || who.IsInCombat() || who.IsRunning() || who.IsSprinting() || who.IsSneaking() || who.IsUnconscious() || who.IsDead()) ; if actor is riding, in combat, running, sprinting, sneaking, unconscious or dead, forget it Else If (who.GetEquippedItemType(0) == 10) ; actor is equipped with shield in left hand who.UnEquipItemSlot(10) ElseIf (who.GetEquippedItemType(0) == 11) ; actor is equipped with Torch in left hand who.UnEquipItemSlot(11) ElseIf (who.GetEquippedItemType(0) == 9) ; actor is equipped with spell in left hand, who.UnEquipItemSlot(9) EndIf If (who.GetEquippedItemType(1) == 9) ; actor is equipped with spell in right hand who.UnEquipItemSlot(9) EndIf EndIf EndIf EndEvent I'm trying to avoid having to list all types of shields and weapons in that script and find a more generic manner to get weapons out of my actor's hands (and I just realized I forgot the 2-handed weapons in this...). I'd be very grateful for any help or advice :smile:. Many thanks in advance! Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 11, 2014 Share Posted April 11, 2014 Try using GetEquippedObject. It returns the form of the equipped object rather than the type. However, the NPC can have a weapon equipped but not drawn which means that their hands are free. So comparing that object against IsWeaponDrawn before unequipping might be a good idea. Link to comment Share on other sites More sharing options...
Hoamaii Posted April 11, 2014 Author Share Posted April 11, 2014 Thanks a lot, IsharaMeradin, I had not tried that yet while checking my actor isWeaponDrawn too. From what I see in the CK wiki, I can also check if the equipped object is a weapon or a spell which seem to be keywords. Would you know if that could also work for shields? Torches are a lot easier, there's only one equipable base object... Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 11, 2014 Share Posted April 11, 2014 If you are referring to this example from the CK wiki Actor PlayerRef = Game.GetPlayer() Form EquippedItem = PlayerRef.GetEquippedObject(0) ; Check Left Hand If !EquippedItem Debug.Trace("Player did not have any item in their left hand.") ElseIf (EquippedItem as Weapon) Debug.Trace("Player has a Weapon in their left hand") ElseIf (EquippedItem as Spell) Debug.Trace("Player has a spell in their left hand") Else Debug.Trace("Player was wielding an object in their left hand.") EndIf The "as Weapon" and "as Spell" are not keywords. It is a method of casting a variable of one type into a parent or child type. If you note, the EquippedItem variable is declared as a form because that is what the GetEquippedObject returns. However, in the example different things were being done when the EquippedItem form was also valid as the child types Weapon and Spell The following is quoted from here <ObjectType> is the type of game object we want this property to point to, and valid types for this setting can be seen by scrolling through the Object Window in the Creation Kit. So, things like Globals, Weapons, Sounds, Imagespace Modifiers, all of them can be referred to in your script by setting your property to use their Object type. So, a property of the Object type Weapon, for example, would tell Papyrus that you are referring to a Weapon object from the gameSo if shields have their own specific category just as weapons and spells do, then you can perform "as Shield" in a similar manner. Hopefully, this is helpful. Link to comment Share on other sites More sharing options...
Hoamaii Posted April 12, 2014 Author Share Posted April 12, 2014 Thanks again, IsharaMeradin :).I just realized SKSE also has a straightforward function with "SheatheWeapon()" - then dug a little further and read a thread warning us about forcibly sheathing weapons before calling an idle animation when an actor is in the "alert" state - apparently the risk is that he stays forever in the alert state afterwards (sorry for the awkward English - not my language). Since I was trying to unequip actors to get them to play an animation, I think it safer to forget the weapon sheathing, let him ignore the trigger box if he is weapon sheathed and simply get him to unequip shield and torch if any. Many thanks also for clarifying to me the use of ObjectType - yes apparently Shields have their own specific category, like Weapons and Spells. For the moment since I've decided to limit myself to torch and shield, I kept to the "UnequipItemSlot" function for shields which are slot 39 and "unEquipItem(Torch01)" for the torch. I still have to test it in game though. Thanks again, it's not the first time you've helped me here, and I really do appreciate your coming back to the topic and checking that we got things right :). You've always been of great help. I have not forgotten that I offered send you a custom satchel I've been working on which I plan to use with your "wearable satchel" scripts - the thing is I'm finishing a house mod I've been working on for quite a while before I move to anything else, so I did not want to bother you with any "WIP" files, I'll contact you when it is finished and working. Cheers :). Link to comment Share on other sites More sharing options...
Hoamaii Posted April 15, 2014 Author Share Posted April 15, 2014 In case anybody has the same problem, I thought I'd post a solution I found in the animation section of the CK, unexpectedly. There is a root Idle which is called "DefaultSheathe" which, when played, makes actor sheathe all weapons whatever they are. It also works for the player. I suppose something similar is used by the game engine to get player to sheathe weapons before using crafting benches. The setback of using this however is if the player starts performing another animation before DefaultSheathe has finished playing, the weapons get stuck in his hand and the "drawWeapon" function gets stuck. He will, for instance, play the Drink anim with his weapon still in hand and I found no way to revert this - the game thinks weapons are sheathed. A safe way to avoid this is to give it time to perform "DefaultSheathe" by adding a "Utility.Wait(1.5)" afterwards (or 1.7 to be extra safe), then using SAE "IdleForceDefaultState" before performing any other animation. If we want extra precaution (the "Wait" time is not always accurate) in case the player spams his keys like mad, it is even safer to DisablePlayerControls and SetPlayerAIDriven before making him perform the DefaultSheathe, and reenable controls and AI immediately after he returns to DefaultState. Or alternately use a "Busy" state in between. It seems to work with custom weapons too, provided they are flagged as weapons of course. And in order to to mess up with the "alert" or "alarmed", should only be used when NOT in combat. Link to comment Share on other sites More sharing options...
Recommended Posts