Problems getting my script to force-equip a specific weapon

Post » Sun Jun 24, 2012 3:42 pm

I'm trying to implement a proper Unarmed skill. I decided to throw all the light armors into the Heavy Armor skill and use Light Armor as my Unarmed skill. My idea for advancing the skill was to give the palyer a perk that would apply a scripted spell that advances Light Armor experience each time an unarmed attack is used, but it turns out that empty hand doesn't count as a weapon for the purpose of perk entry points (I tried to use the "apply combat hit spell" entry point with the condition that the weapon doesn't have any of the keywords for bow, dagger, sword, etc.).

So as a workaround I've created a left hand and right hand unarmed weapon and now I'm trying to make a scripted magic effect for an ability that would equip said weapons whenever the player's hand is empty. But it doesn't work. Here is the full script:

Spoiler
Scriptname dsrUnarmedEquipScript extends activemagiceffect  ObjectReference Property UnarmedRightRef Auto ; references to the right hand unarmed weaponObjectReference Property UnarmedLeftRef Auto ; references to the left hand unarmed weaponActor PlayerRef ;reference to the playerEvent OnEffectStart(Actor Target, Actor Caster)	RegisterForSingleUpdate(1) ; Give us a single update in one secondendEventEvent OnUpdate()	PlayerRef = Game.GetPlayer() ; this is the player		; if the player doesn't have any unarmed weapons, give him some		if (PlayerRef.GetItemCount(UnarmedRightRef) == 0)		PlayerRef.AddItem(UnarmedRightRef, 1, true) ; the item to add is the right hand weapon, give only one, don't display a message	endif	if (PlayerRef.GetItemCount(UnarmedLeftRef) == 0)		PlayerRef.AddItem(UnarmedLeftRef, 1, true)	endif		; now that we made sure the player has the unarmed weapons in their inventory, we check if the script should equip said weapons		if (PlayerRef.GetEquippedItemType(1) == 0) ; if the player' right hand is unarmed		if (PlayerRef.IsEquipped(UnarmedRightRef) == 0); and the player doesn't have the right hand weapon equiped			PlayerRef.EquipItem(UnarmedRightRef) ; then the player has an actually empty right hand and we can equip the right hand unarmed weapon		endif	endIf		if (PlayerRef.GetEquippedItemType(0) == 0) ; if the player' left hand is unarmed		if (PlayerRef.IsEquipped(UnarmedLeftRef) == 0); and the player doesn't have the left hand weapon equiped			PlayerRef.EquipItem(UnarmedLeftRef) ; then the player has an actually empty left hand and we can equip the left hand unarmed weapon		endif	endIf	RegisterForSingleUpdate(1) ; Now that this has all been done we can do it again.endEvent

During testing I've found that the unarmed weapons are added to my inventory as they should be and if I store them in a container they get moved back into my inventory. So far so good, but the script fails to equip them so I must've messed up something in this part:

	if (PlayerRef.GetEquippedItemType(1) == 0) ; if the player' right hand is unarmed		if (PlayerRef.IsEquipped(UnarmedRightRef) == 0) ; and the player doesn't have the right hand weapon equiped			PlayerRef.EquipItem(UnarmedRightRef) ; then the player has an actually empty right hand and we can equip the right hand unarmed weapon		endif	endIf

Any ideas what I'm doing wrong?
User avatar
brandon frier
 
Posts: 3422
Joined: Wed Oct 17, 2007 8:47 pm

Post » Sun Jun 24, 2012 7:02 pm

After (PlayerRef.GetEquippedItemType(1) == 0), throw up a debug notification. Does that fire?
User avatar
Chloe Botham
 
Posts: 3537
Joined: Wed Aug 30, 2006 12:11 am

Post » Sun Jun 24, 2012 4:17 am

Just tried a variant:
Scriptname dsrUnarmedEquipScript extEnds ActiveMagicEffect  ObjectReference Property UnarmedRightRef AutoObjectReference Property UnarmedLeftRef AutoActor Property PlayerRef AutoEvent OnEffectStart(Actor Target, Actor Caster)	If !PlayerRef.GetItemCount(UnarmedRightRef)		PlayerRef.AddItem(UnarmedRightRef, 1, True)	EndIf	If !PlayerRef.GetItemCount(UnarmedLeftRef)		PlayerRef.AddItem(UnarmedLeftRef, 1, True)	EndIf	If PlayerRef.GetEquippedItemType(1)	ElseIf !PlayerRef.IsEquipped(UnarmedRightRef.GetBaseObject())		PlayerRef.EquipItem(UnarmedRightRef.GetBaseObject())	EndIf	If PlayerRef.GetEquippedItemType(0)	ElseIf !PlayerRef.IsEquipped(UnarmedLeftRef.GetBaseObject())		PlayerRef.EquipItem(UnarmedLeftRef.GetBaseObject())	EndIfEndEvent
And it worked. The player has to have that ObjectReference(s) to ensure it/they are the one equipped as EquipItem will otherwise give the player *whatever is passed as EquipItem's akItem. Also, the ObjectReference mustn't be disabled.

*including actors
User avatar
Skivs
 
Posts: 3550
Joined: Sat Dec 01, 2007 10:06 pm


Return to V - Skyrim