Jump to content

Recommended Posts

Posted

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
endFunction

I 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
endFunction

Am 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.

Posted (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
ENDEVENT

Do 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 by ReDragon2013
Posted
  On 9/27/2019 at 7:34 PM, ReDragon2013 said:

 

; 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
ENDEVENT

Do 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

Wow thanks, I'll try this as soon as I'm able to.

 

Thank you

Posted

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
Posted
  On 10/3/2019 at 4:55 PM, npdogg said:
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.

Posted
  On 10/9/2019 at 6:25 AM, arael53 said:

 

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?

Posted

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.

  • Recently Browsing   0 members

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