Jump to content

[LE] Reflect spell damage or spell


Recommended Posts

Task 1. Want to create an enchantment, that would reflect [%] of spell damage of certain type (lightning for example) back to caster.

Task 2. Want to create enchantment, that would reflect certain spell type (fear for example) entirely at caster

 

However, I am struggling at understanding, how spells in Skyrim work. reading theory on creationkit com website and attempts to reverse-engineer that spell reflection ward and spellbreaker mod yielded me nought, so I come here for assistance.

 

First of all, could this be done without scripting at all? Secondly, is magic effect with [Reflect Damage] or [Reflect Arrows] as [Associated item 1] applicable to achieve this. If yes, then I do not understand how exactly can I make them differentiate the exact damage type (lightning for example).

Link to comment
Share on other sites

Reflect Damage is tricky. I have messed with it myself and have a spell that kinda works for it, but even if I set the effect magnitude at 100, it still doesnt appear to be reflecting the full damage to the attacker, only part of it.

 

I was messing around with Colorful Magic, which has tons of interesting magics, even a reflect damage spell, you should check it.

Havent had the time to properly investigate everything about it since mine kinda works as I want for now.

The Colorful Magic one, for some reason, uses the same reflect damage effect 3 times, I have no idea why. Maybe each one reflecs 33%?

 

Dunno. Anyway, I think Reflect Damage only works on melee attacks, but not entirely sure.

 

I can tell you about another thing that works though, which is a script with an OnHit event

Setting the conditions for the hit to apply, can be messy, but it seems to work.

Mechanic is simple, wearer of the effect gets hit, event happens, you can make something happen after that to the attacker registered on the hit event.

My experiment on it is simpler though, it only casts a spell. But you want it to return damage, so you might be better off with functions to register how much damage was done, and re-apply it to the attacker with a simple DamageAV("Health") function

Link to comment
Share on other sites

Well, will try to look at examples and reverse-engineer them.

 

But meanwhile, could anyone explain to me, how exactly "Magical Effect" category works. I have read the description of parameters on construction kit website, what I would like to know is, how exactly they could be used. If anyone could give me examples with description what is set up in that particular way and why, I would be greatful.

Link to comment
Share on other sites

I cannot explain how does "Magical Effect" category works. But maybe next could be a step in the right direction. This is not for enchanted armor, its a cloak ability for actors.

 

xyzSpellReflectScript

 

Scriptname xyzSpellReflectScript extends ActiveMagicEffect
{ReDragon 2018}    ; spell with cloak ability for the player

; https://forums.nexusmods.com/index.php?/topic/7137121-reflect-spell-damage-or-spell/

; MAKE your CHOICE:
; Take the incomming Effect or Spell to reflect parts of damage back to the aggressor.

; see also script source "DLC1_ReflectShieldSCRIPT.psc" for more complexity

  Float fHealth
  Actor target


; -- EVENTs --

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
    Debug.MessageBox("OnEffectStart..")
    Debug.Trace("OnEffectStart() - target = " +akTarget+ ", caster = " +akCaster)

    target  = akTarget
    fHealth = akTarget.GetActorValue("Health")                ; init variable when cloak ability has started
ENDEVENT


EVENT OnEffectFinish(Actor akTarget, Actor akCaster)
    Debug.MessageBox("OnEffectFinish..")
    Debug.Trace("OnEffectFinish() - has been reached.. " +self)
ENDEVENT


EVENT OnMagicEffectApply(ObjectReference akCaster, MagicEffect akEffect)
; received when a magic affect is being applied to this object

IF (akCaster as Actor).IsHostileToActor(target)                        ; target == self.GetTargetActor()
; https://www.creationkit.com/index.php?title=IsHostileToActor-_Actor
ELSE
    RETURN    ; - STOP -    probably friendly effect do nothing
ENDIF
;---------------------
    gotoState("Busy")                ; ### STATE ###
    myF_ActionByEffect(akEffect, akCaster as Actor)
    gotoState("")                    ; ### STATE ###
ENDEVENT


EVENT OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, Bool abBashAttack, Bool abHitBlocked)
; received when this object is hit by a source (weapon, spell, explosion) or projectile attack

IF ( abHitBlocked )
    RETURN    ; - STOP -    no damage, current hit was blocked
ENDIF
;---------------------
IF (akSource as Spell)
ELSE
    fHealth = target.GetActorValue("Health")            ; update value only
    RETURN    ; - STOP -    was hit by others like weapon
ENDIF
;---------------------
IF (akSource as Spell).IsHostile()
; https://www.creationkit.com/index.php?title=IsHostile_-_Spell
ELSE
    RETURN    ; - STOP -    friendly spell, do nothing
ENDIF
;---------------------
    gotoState("Busy")                ; ### STATE ###
    myF_ActionBySpell(akSource as Spell, akAggressor as Actor)
    gotoState("")                    ; ### STATE ###
ENDEVENT


;========================
state Busy
;=========
endState


; -- FUNCTIONs --

;----------------------------------------------------------
FUNCTION myF_ActionBySpell(Spell akSpell, Actor hostileRef)
;----------------------------------------------------------
    Debug.Trace("hit by " +hostileRef+ " with " +akSpell)

    float f = target.GetActorValue("Health")

IF (f >= fHealth)
    fHealth = f
    RETURN    ; - STOP -    safety net here
ENDIF
;---------------------
    float fDiff = fHealth - f                                            ; hit points lost

    target.RestoreActorValue("Health", f + fDiff)                        ; healing current damage
; https://www.creationkit.com/index.php?title=RestoreActorValue_-_Actor

    hostileRef.ModActorValue("Health", fDiff * 0.2)                      ; reflect with 20% of current hit damage
; https://www.creationkit.com/index.php?title=ModActorValue_-_Actor

    fHealth = target.GetActorValue("Health")
ENDFUNCTION


;------------------------------------------------------------------
FUNCTION myF_ActionByEffect(MagicEffect akEffect, Actor hostileRef)
;------------------------------------------------------------------
    Debug.Trace("applied by " +hostileRef+ " with " +akEffect)

; similar like content above
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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