weapon swing stamina costs

Post » Thu Dec 18, 2014 6:52 am

Hello, I'm making a mod which uses 3 scripts to spice up combat a bit. This one is the last one I need to get working (one is finished and the other being polished).

Essentially, I want the player to have some stamina cost when he swings a melee weapon. I want the cost to be the weight of the weapon itself + five to account for the weight of hand to hand swings. I am using the SKSE query "GetWeight" in order to do this.

On the surface level, I unequip and reequip the sword, but when I swing it, nothing happens. So I used the console command "SQV" to see what was going on, and all of the variables were zero. This leads me to believe it is the event for equipping and unequipping that is messing up, but I am unsure. So that is why I'm asking. I wanted to know if anyone had any ideas while I fiddle with things.

Here is the script I have created. It compiles just fine at the moment.

Spoiler
Scriptname _Storm_Blood_StaminaCosts extends Quest  {Stamina Costs}Float RightWeightFloat RightCostFloat LeftWeightFloat LeftCostActor Property PlayerRef AutoEvent OnInit()	RegisterForAnimationEvent(PlayerRef, "attackStart_MC1HMLeft" )	RegisterForAnimationEvent(PlayerRef, "attackStartSprintLeftHand")	RegisterForAnimationEvent(PlayerRef, "attackStartH2HLeft")	RegisterForAnimationEvent(PlayerRef, "attackStartLeftHand")	RegisterForAnimationEvent(PlayerRef, "attackStart_MC1HMRight")	RegisterForAnimationEvent(PlayerRef, "attackStartSprintRightHand")	RegisterForAnimationEvent(PlayerRef, "attackStartH2HRight")	RegisterForAnimationEvent(PlayerRef, "attackStartRightHand")	RegisterForAnimationEvent(PlayerRef, "attackStartDualWield")endEvent;-----------------------------------------------------------------Event OnObjectEquipped (Form akBaseObject, ObjectReference akReference)	if akBaseObject as Weapon		RightWeight = (PlayerRef.GetEquippedWeapon(False).GetWeight()) ;acquire right weapon lbs		LeftWeight = (PlayerRef.GetEquippedWeapon(True).GetWeight()) ;acquire left weapon lbs		RightCost = (RightWeight+5) ;add to weight for unarmed		LeftCost = (LeftWeight+5) ;add to weight for unarmed	endifEndEvent;-----------------------------------------------------------------Event OnObjectUnequipped (Form akBaseObject, ObjectReference akReference)	if akBaseObject as Weapon		RightWeight = (PlayerRef.GetEquippedWeapon(False).GetWeight()) ;remove right weapon lbs		LeftWeight = (PlayerRef.GetEquippedWeapon(True).GetWeight()) ;remove left weapon lbs		RightCost = (RightWeight+5) ;add to weight for unarmed		LeftCost = (LeftWeight+5) ;add to weight for unarmed	endifEndEvent;-----------------------------------------------------------------Event OnAnimationEvent(ObjectReference akSource, String asEventName)	If (akSource == PlayerRef) && (asEventName == "attackStart_MC1HMLeft")		PlayerRef.DamageAV("Stamina", LeftCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartSprintLeftHand")   		 PlayerRef.DamageAV("Stamina", LeftCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartH2HLeft") ;hand to hand left attack		PlayerRef.DamageAV ("Stamina", LeftCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartLeftHand") ;left attack		PlayerRef.DamageAV ("Stamina", LeftCost);------------------------------------------------------------------	ElseIf (akSource == PlayerRef) && (asEventName == "attackStart_MC1HMRight") ;mounted right attack		PlayerRef.DamageAV ("Stamina", RightCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartSprintRightHand") ;sprinting right attack		PlayerRef.DamageAV ("Stamina", RightCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartH2HRight") ;hand to hand right attack		PlayerRef.DamageAV ("Stamina", RightCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartRightHand") ;right attack		PlayerRef.DamageAV ("Stamina", RightCost);-----------------------------------------------------------	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartDualWield") ;dual Attack		PlayerRef.DamageAV ("Stamina", RightCost + LeftCost)	EndifEndEvent 

I am a beginning scriptor (in that I learned how to do this a few days ago), so I apologize if this is an incredibly obvious mistake

User avatar
Frank Firefly
 
Posts: 3429
Joined: Sun Aug 19, 2007 9:34 am

Post » Thu Dec 18, 2014 9:15 pm

OK, don't ever put that much stuff in the OnInit. Oftentimes, it won't work. Instead do this:

Scriptname _Storm_Blood_StaminaCosts extends Quest  {Stamina Costs}Float RightWeightFloat RightCostFloat LeftWeightFloat LeftCostActor Property PlayerRef AutoEvent OnInit()     RegisterForSingleUpdate(0.1)EndEventEvent OnUpdate()	RegisterForAnimationEvent(PlayerRef, "attackStart_MC1HMLeft" )	RegisterForAnimationEvent(PlayerRef, "attackStartSprintLeftHand")	RegisterForAnimationEvent(PlayerRef, "attackStartH2HLeft")	RegisterForAnimationEvent(PlayerRef, "attackStartLeftHand")	RegisterForAnimationEvent(PlayerRef, "attackStart_MC1HMRight")	RegisterForAnimationEvent(PlayerRef, "attackStartSprintRightHand")	RegisterForAnimationEvent(PlayerRef, "attackStartH2HRight")	RegisterForAnimationEvent(PlayerRef, "attackStartRightHand")	RegisterForAnimationEvent(PlayerRef, "attackStartDualWield")endEvent;-----------------------------------------------------------------Event OnObjectEquipped (Form akBaseObject, ObjectReference akReference)	if akBaseObject as Weapon		RightWeight = (PlayerRef.GetEquippedWeapon(False).GetWeight()) ;acquire right weapon lbs		LeftWeight = (PlayerRef.GetEquippedWeapon(True).GetWeight()) ;acquire left weapon lbs		RightCost = (RightWeight+5) ;add to weight for unarmed		LeftCost = (LeftWeight+5) ;add to weight for unarmed	endifEndEvent;-----------------------------------------------------------------Event OnObjectUnequipped (Form akBaseObject, ObjectReference akReference)	if akBaseObject as Weapon		RightWeight = (PlayerRef.GetEquippedWeapon(False).GetWeight()) ;remove right weapon lbs		LeftWeight = (PlayerRef.GetEquippedWeapon(True).GetWeight()) ;remove left weapon lbs		RightCost = (RightWeight+5) ;add to weight for unarmed		LeftCost = (LeftWeight+5) ;add to weight for unarmed	endifEndEvent;-----------------------------------------------------------------Event OnAnimationEvent(ObjectReference akSource, String asEventName)	If (akSource == PlayerRef) && (asEventName == "attackStart_MC1HMLeft")		PlayerRef.DamageAV("Stamina", LeftCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartSprintLeftHand")   		 PlayerRef.DamageAV("Stamina", LeftCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartH2HLeft") ;hand to hand left attack		PlayerRef.DamageAV ("Stamina", LeftCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartLeftHand") ;left attack		PlayerRef.DamageAV ("Stamina", LeftCost);------------------------------------------------------------------	ElseIf (akSource == PlayerRef) && (asEventName == "attackStart_MC1HMRight") ;mounted right attack		PlayerRef.DamageAV ("Stamina", RightCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartSprintRightHand") ;sprinting right attack		PlayerRef.DamageAV ("Stamina", RightCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartH2HRight") ;hand to hand right attack		PlayerRef.DamageAV ("Stamina", RightCost)	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartRightHand") ;right attack		PlayerRef.DamageAV ("Stamina", RightCost);-----------------------------------------------------------	ElseIf (akSource == PlayerRef) && (asEventName == "attackStartDualWield") ;dual Attack		PlayerRef.DamageAV ("Stamina", RightCost + LeftCost)	EndifEndEvent
User avatar
Quick Draw
 
Posts: 3423
Joined: Sun Sep 30, 2007 4:56 am


Return to V - Skyrim