Jump to content

Activemagiceffect script with conditions


Recommended Posts

I have made an ability whose effect has a condition, the condition works because I get debug messages from both OnEffectStart and OnEffectFinish.

However I have a variable in the OnInit event that gets set but of course that is firing every time the condition goes true, without using a property of another script or globalvariable  is there a way to have a int/float variable on the effect script that is persistent and can be altered by either the OnEffectStart and OnEffectFinish events?

 

diziet

Link to comment
Share on other sites

ActiveMagicEffect is very self-contained in the way you are mentioning. When it starts, its fresh, and when it ends, it efficiently sanitizes loose ends. What you are wanting, requires an outside monitor like a globalvariable to be able to get/set values, or you can instead check the properties of another script

Int TrackingID = (WhateverScript as ScriptNameOfIt).TrackID

Try to utilize in-game conditions in the creation kit. That is lighter under-the-hood for the game engine and also very encompassing for most needs. If however you really want script-based usage, go with globalvariable IMO unless you are very comfortable casting to and from other scripts

Link to comment
Share on other sites

What Sphered said. A few more thoughts though. 

If you are wanting the ability to be used by multiple NPC's you could consider using the mod PapyrusUtil which has StorageUtil.psc. This would allow you to store int variables on the actors the magic effect is running on. 

As an example, this will add 1 to the stored int every time the magic effect starts. 

 

Event OnEffectStart(Actor akTarget, Actor akCaster) 
    int magEffectInt = StorageUtil.GetIntValue(akTarget, "MyModName_magEffectInt")
    magEffectInt += 1 
    StorageUtil.SetIntValue(akTarget, "MyModName_magEffectInt", magEffectInt)
EndEvent

 

Link to comment
Share on other sites

It's a player only ability whose effect in the spell has a condition on a pc misc stat. so I already have that covered in the CK.  I suspected that a magic effect might need to store things outside it if it starts and finishes a lot, thought I'd ask anyway!  Thanks:)

 

diziet

Link to comment
Share on other sites

Gotcha, in that case this is how I'd do it. Attach 2 scripts to your magic effect. The one you already have that extends ActiveMagicEffect and another that extends MagicEffect (the base object). You can store your int property in the MagicEffect script. 

So first script: 

scriptname TM_MagicEffectScript extends MagicEffect 

Int Property MyInt Auto

 

then in your second script that extends ActiveMagicEffect you can do: 

Event OnEffectStart(Actor akTarget, Actor akCaster) 
    TM_MagicEffectScript MagicEffectScript = GetBaseObject() as TM_MagicEffectScript
    MagicEffectScript.MyInt += 1 
    Debug.Notification(MagicEffectScript.MyInt)
EndEvent

 

Of course change the script name to something more unique to your mod.

Link to comment
Share on other sites

It's the equivalent. You don't need to use Self when using a function like that. You only need to use Self if passing the form your script is attached to to another function or using it in some other way.

As an example, if your script is attached to a weapon, you can do Game.GetPlayer().AddItem(self) to add the weapon to the player

Link to comment
Share on other sites

Equivalent.  Nothing special.

Well, it is different from the more common GetBaseObject for ObjectReferences, but still conceptually equivalent, though "special" to ActiveMagicEffect.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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