arael53 Posted September 27, 2019 Share Posted September 27, 2019 Hello, I'm trying to understand scripting to modify a mod (for my personal use). I'd like to add a stamina drain effect relative to the weapon used. I'm looking at the stamina drain effect from wildcat, and I'd like to modify it to add what I want, but as I said, I've never use script before, so i'm a bit lost. That's the part of the script from wildcat. function OnAnimationEvent(objectreference akSource, String asEventName) if asEventName == "weaponSwing" || asEventName == "weaponLeftSwing" self.GetTargetActor().DamageActorValue("Stamina", SFL_SwingCostsStamina_Global.GetValue()) endIf endFunctionI think I understand that it takes the magnitude from the value set by in the MCM. i'd like to make something simpler and add a static stamina drain for each weapon. I though about something like this : function OnAnimationEvent(objectreference akSource, float afDamage) if asEventName == "weaponSwing" || asEventName == "weaponLeftSwing" if self.GetTargetActor().WornHasKeyword(WeapTypeSword) self.GetTargetActor().DamageActorValue("Stamina", 5.0()) endIf endIf endFunctionAm I on the right track ? As I said, I'm really a noob about all this. I couldn't compile it to test (something about the fact that the script was already in a similar state, I suppose that's because i tried to add it to the existing script) is something like this possible in the same script for each weapon type ? Could someone help me a bit about this ? thanks for your help. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted September 27, 2019 Share Posted September 27, 2019 (edited) ; Register for the specified animation event from the specified object - returns true if it successfully registered;bool FUNCTION RegisterForAnimationEvent(ObjectReference akSender, string asEventName) native ; anywhere before, you'll see something like that RegisterForAnimationEvent(self, "weaponSwing") RegisterForAnimationEvent(self, "weaponLeftSwing")next is the event (native, hardcoded to papyrus) and at least one property (filled by Creation Kit) GlobalVariable PROPERTY SFL_SwingCostsStamina_Global auto EVENT OnAnimationEvent(Objectreference akSource, String asEventName) ; native see Form.psc, Alias.psc, ActiveMagicEffect.psc IF (asEventName == "weaponSwing") || (asEventName == "weaponLeftSwing") self.GetTargetActor().DamageActorValue("Stamina", SFL_SwingCostsStamina_Global.GetValue()) ENDIF ENDEVENTDo you want, "I'd like to add a stamina drain effect relative to the weapon used." GlobalVariable PROPERTY SFL_SwingCostsStamina_Global auto Keyword PROPERTY WeapTypeSword auto ;Keyword PROPERTY WeapTypeDagger auto ;Keyword PROPERTY .. EVENT OnAnimationEvent(Objectreference akSource, String asEventName) ; native see Form.psc, Alias.psc, ActiveMagicEffect.psc IF (asEventName == "weaponSwing") || (asEventName == "weaponLeftSwing") ELSE RETURN ; - STOP - ENDIF ;-------------------- actor aRef = self.GetTargetActor() float f IF ( aRef ) IF aRef.WornHasKeyword(WeapTypeSword) f = 5.0 ;ELSEIF aRef.WornHasKeyword(WeapTypeDagger) ; f = 2.5 ;ELSEIF aRef.WornHasKEyword() ; f = ELSE f = 0.0 ENDIF aRef.DamageActorValue("Stamina", f) ENDIF ENDEVENT Edited September 27, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
arael53 Posted September 28, 2019 Author Share Posted September 28, 2019 ; Register for the specified animation event from the specified object - returns true if it successfully registered;bool FUNCTION RegisterForAnimationEvent(ObjectReference akSender, string asEventName) native ; anywhere before, you'll see something like that RegisterForAnimationEvent(self, "weaponSwing") RegisterForAnimationEvent(self, "weaponLeftSwing")next is the event (native, hardcoded to papyrus) and at least one property (filled by Creation Kit) GlobalVariable PROPERTY SFL_SwingCostsStamina_Global auto EVENT OnAnimationEvent(Objectreference akSource, String asEventName) ; native see Form.psc, Alias.psc, ActiveMagicEffect.psc IF (asEventName == "weaponSwing") || (asEventName == "weaponLeftSwing") self.GetTargetActor().DamageActorValue("Stamina", SFL_SwingCostsStamina_Global.GetValue()) ENDIF ENDEVENTDo you want, "I'd like to add a stamina drain effect relative to the weapon used." GlobalVariable PROPERTY SFL_SwingCostsStamina_Global auto Keyword PROPERTY WeapTypeSword auto ;Keyword PROPERTY WeapTypeDagger auto ;Keyword PROPERTY .. EVENT OnAnimationEvent(Objectreference akSource, String asEventName) ; native see Form.psc, Alias.psc, ActiveMagicEffect.psc IF (asEventName == "weaponSwing") || (asEventName == "weaponLeftSwing") ELSE RETURN ; - STOP - ENDIF ;-------------------- actor aRef = self.GetTargetActor() float f IF ( aRef ) IF aRef.WornHasKeyword(WeapTypeSword) f = 5.0 ;ELSEIF aRef.WornHasKeyword(WeapTypeDagger) ; f = 2.5 ;ELSEIF aRef.WornHasKEyword() ; f = ELSE f = 0.0 ENDIF aRef.DamageActorValue("Stamina", f) ENDIF ENDEVENTWow thanks, I'll try this as soon as I'm able to. Thank you Link to comment Share on other sites More sharing options...
npdogg Posted October 3, 2019 Share Posted October 3, 2019 ScriptName SwingCostsStamina extends ActiveMagicEffect Actor TargetActor String WeaponSwingRightEvent = "weaponSwing" String WeaponSwingLeftEvent = "weaponSwingLeft" Float SwordStaminaCost = 5.0 Float DaggerStaminaCost = 2.5 Event OnEffectStart(Actor akCaster, Actor akTarget) If akTarget == Game.GetPlayer() TargetActor = akTarget RegisterForAnimationEvent(TargetActor, WeaponSwingRightEvent) RegisterForAnimationEvent(TargetActor, WeaponSwingLeftEvent) Else Dispel() EndIf EndEvent Event OnRaceSwitchComplete() RegisterForAnimationEvent(TargetActor, WeaponSwingRightEvent) RegisterForAnimationEvent(TargetActor, WeaponSwingLeftEvent) EndEvent Event OnAnimationEvent(ObjectReference akSource, String asEventName) If akSource == TargetActor Int EquippedItemType = 0 If asEventName == WeaponSwingRightEvent EquippedItemType = TargetActor.GetEquippedItemType(0) ElseIf asEventName == WeaponSwingLeftEvent EquippedItemType = TargetActor.GetEquippedItemType(1) EndIf If EquippedItemType == 1 TargetActor.DamageActorValue("Stamina", SwordStaminaCost) ElseIf EquippedItemType == 2 TargetActor.DamageActorValue("Stamina", DaggerStaminaCost) EndIf EndIf EndEvent Link to comment Share on other sites More sharing options...
arael53 Posted October 9, 2019 Author Share Posted October 9, 2019 ScriptName SwingCostsStamina extends ActiveMagicEffect Actor TargetActor String WeaponSwingRightEvent = "weaponSwing" String WeaponSwingLeftEvent = "weaponSwingLeft" Float SwordStaminaCost = 5.0 Float DaggerStaminaCost = 2.5 Event OnEffectStart(Actor akCaster, Actor akTarget) If akTarget == Game.GetPlayer() TargetActor = akTarget RegisterForAnimationEvent(TargetActor, WeaponSwingRightEvent) RegisterForAnimationEvent(TargetActor, WeaponSwingLeftEvent) Else Dispel() EndIf EndEvent Event OnRaceSwitchComplete() RegisterForAnimationEvent(TargetActor, WeaponSwingRightEvent) RegisterForAnimationEvent(TargetActor, WeaponSwingLeftEvent) EndEvent Event OnAnimationEvent(ObjectReference akSource, String asEventName) If akSource == TargetActor Int EquippedItemType = 0 If asEventName == WeaponSwingRightEvent EquippedItemType = TargetActor.GetEquippedItemType(0) ElseIf asEventName == WeaponSwingLeftEvent EquippedItemType = TargetActor.GetEquippedItemType(1) EndIf If EquippedItemType == 1 TargetActor.DamageActorValue("Stamina", SwordStaminaCost) ElseIf EquippedItemType == 2 TargetActor.DamageActorValue("Stamina", DaggerStaminaCost) EndIf EndIf EndEvent Thanks for the script !It compiles just fine. It seems I can't make it work in game though. I try to attach it to a magic effect, but in game it doesn't drain stamina. I think I'll need to understand these things a bit more. Link to comment Share on other sites More sharing options...
npdogg Posted October 9, 2019 Share Posted October 9, 2019 Thanks for the script !It compiles just fine. It seems I can't make it work in game though. I try to attach it to a magic effect, but in game it doesn't drain stamina. I think I'll need to understand these things a bit more. How are you attaching the magic effect to the player? Link to comment Share on other sites More sharing options...
npdogg Posted October 13, 2019 Share Posted October 13, 2019 Bleh. Just realized that I made a mistake in the function signature for OnEffectStart - akTarget should come before akCaster. That may be why it isn't working. Link to comment Share on other sites More sharing options...
Recommended Posts