Jump to content

[LE] Problem with scripted spell


Serya

Recommended Posts

Hi,

 

i wrote a script, that changes the strength of a spell depending of the light around the caster. If i attach it to a spell that is casted on the player itself (for example a healspell) it works as it should. But if i attach it to a spell that is fired away (like a fireball) the strength doesn´t change although the script is executed (the messageboxes are appearing).

 

This is the script:

Scriptname sunheal Extends ActiveMagicEffect

import Debug
import Math


Spell Property healspell Auto


Event OnEffectStart(Actor akTarget, Actor akCaster)
    MessageBox("Start")
    float lLevel = akCaster.GetLightLevel()
    MessageBox(lLevel)
    float magnitude = (lLevel / 5) * sqrt(lLevel)
    MessageBox(magnitude)
    healspell.SetNthEffectMagnitude(0, magnitude)
EndEvent

I´m still a noob in scripting so maybe this is a stupid question but can someone please help me with this?

Link to comment
Share on other sites

maybe SKSE issue, spell or magiceffect has extra conditions, spell has more than one effect

 

sunheal

 

Scriptname sunheal extends ActiveMagicEffect
; https://forums.nexusmods.com/index.php?/topic/8719298-problem-with-scripted-spell/

   Spell PROPERTY healspell auto    ; Healing [SPEL:00012FCC]


; -- EVENTs -- 2

EVENT OnEffectStart(Actor akTarget, Actor akCaster)

    Debug.Notification("Start sunheal..")
    Debug.Trace(self+" OnEffectStart() - target = " +akTarget+ ", caster = " +akCaster)        ; debugging only, see "papyrus.0.log"

    float f = akCaster.GetLightLevel()        ; lightlevel from 0.0 up to 150.0
    float m = (f / 5.0) * Math.Sqrt(f)        ; calculate magnitude

IF (SKSE.GetVersion() > 0) && (healspell)
    int iMax = healspell.GetNumEffects()      ; SKSE required !!
    int i = 0
    WHILE (i < iMax)
        Debug.Trace("Index: " +i+ " has " + healspell.GetNthEffectMagicEffect(i))            ; debugging only, see "papyrus.0.log"
        i = i + 1
    ENDWHILE
ENDIF

; https://www.creationkit.com/index.php?title=SetNthEffectMagnitude_-_Spell
    ; index = 0: The index of the Magic Effect to change.
    ; value = m: The Magnitude to set the Magic Effect to.

    IF (SKSE.GetVersion() > 0)
        healspell.SetNthEffectMagnitude(0, m)        ; SKSE required !!
        Debug.Trace("LightLevel = " +f+ ", magnitude = " +m)                                ; debugging only, see "papyrus.0.log"
    ELSE
        Debug.Notification("SKSE is missing!")
    ENDIF
ENDEVENT

EVENT OnEffectFinish(Actor akTarget, Actor akCaster)
    Debug.Trace(self+" OnEffectFinish() - target = " +akTarget+ ", caster = " +akCaster)        ; debugging only, see "papyrus.0.log"
ENDEVENT

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

Hi,

 

sorry for the late answer. I made it work in a much more easier way (why take the easy way, if you can also take the hardest?).

 

This is the script now:

Scriptname sunheal Extends ActiveMagicEffect

import Debug
import Math

bool Property IsDamageSpell Auto
bool Property SwitchCasterAndTarget Auto


Event OnEffectStart(Actor akTarget, Actor akCaster)
    Debug.Trace("Start - TargetHP: " + akTarget.GetAV("health"))
    float lLevel = akCaster.GetLightLevel()
    Debug.Trace(lLevel)
    float magnitude = (lLevel / 5) * sqrt(lLevel)
    Debug.Trace(magnitude)
    
    If IsDamageSpell
        akTarget.DamageAV("health", magnitude)
    Else
        if SwitchCasterAndTarget    ;heal other person
            akTarget.RestoreAV("health", magnitude)
        Else
            akCaster.RestoreAV("health", magnitude)
        EndIf
    EndIf
    
    Debug.Trace("End - TargetHP: " + akTarget.GetAV("health"))
    Debug.Trace(""); seperating calls in debugfile
EndEvent

Instead of falling into despair with the "SetNthEffectMagnitude" I just use now "DamageAV" and "RestoreAV" (I didn´t knew those functions exists before sorry). All i have to do now is playing around with the numbers and formulas. Thanks to you both for your answers.

I just have one last question (I hope :laugh: ) : I think the Trace-commands aren´t that good for the performance (even if it shouldn´t be a problem with this "huge and complex" script), so are they still executed even if logging is disabled (in this case they would do nothing right?) or do I have to delete/comment them?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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