Jump to content

CK How to check whether the player has a specific active effect or not?


Recommended Posts

Hi, I'm trying to make a spell using scripts. What it does is that it'll equip the player with a suit of armor for a duration, during that duration, it'll also buff the player. I need some help with a way to check whether the player's already had this effect running and do different things accordingly.

 

This is what I've come up with so far:

 

 

 

Scriptname SprigganArmor extends ActiveMagicEffect  
{Matron of the Woods magic effect}

Armor property Spriggancuir Auto
{Points to the spriggan top}
Armor property Sprigganfeet Auto
{Points to the spriggan shoes}
Armor property Spriggangunt Auto
{Points to the spriggan arms}
Armor property Sprigganmask Auto
{Points to the spriggan mask}

Keyword property Sprigganized Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
;===============================================================================
;Check if the player has this effect running
if (!akTarget.HasEffectKeyword(Sprigganized))
Debug.Notification("You're already tapping into the power of the Woods")
return
endif
;================================================================================
;Random Notification for Immersion
int rng = Utility.RandomInt(1,4)
if rng == 1
Debug.Notification("The power of the Woods overwhelms you")
elseif rng == 2
Debug.Notification("You feel a youthful energy flowing through your body")
elseif rng == 3
Debug.Notification("The Woods got you")
else
Debug.Notification("The Woods lend you great power")
endif
;================================================================================
;Equips armor on the player
Actor player = akCaster
player.additem(Spriggancuir,1, true)
player.additem(Sprigganfeet,1, true)
player.additem(Spriggangunt,1, true)
player.additem(Sprigganmask,1, true)

player.equipitem(Spriggancuir, true, true)
player.equipitem(Sprigganfeet, true, true)
player.equipitem(Spriggangunt, true, true)
player.equipitem(Sprigganmask, true, true)
endEvent
;=================================================================================
;Remove the armor once the effect wears out
Event OnEffectFinish(Actor akTarget, Actor akCaster)
Actor player = akCaster
player.removeitem(Spriggancuir,1, true)
player.removeitem(Sprigganfeet,1, true)
player.removeitem(Spriggangunt,1, true)
player.removeitem(Sprigganmask,1, true)
endEvent

 

 

In my script the checking part doesn't seem to work, the player can just keep spamming the spell but get no notification that they already have the effect.

Edited by nofawkingasianservers
Link to comment
Share on other sites

I think my problem lies elsewhere. It always return TRUE even if I don't have that active spell effect (I don't see it in the Effects menu in-game). Could it be that something's wrong with the keyword hooking part? Can you help me with this? I think I messed up somewhere. Here's how it currently looks like

 

https://imgur.com/a/ZrMbNDH

 

 

Link to comment
Share on other sites

Hmmm, actually reading here: https://www.creationkit.com/index.php?title=HasMagicEffect_-_Actor it seems that the condition will return true if the actor has the effect, regardless of whether the CK conditions are true or not for the effect. So, as a work around, you'll have to do something else to determine if the actor has the effect. You could maybe add the actor to a faction, then remove from faction with OnEffectFinish. Something like this:

 

Faction Property SprigganizedFaction Auto
Bool Active

Event OnEffectStart(Actor akTarget, Actor akCaster)
    If akTarget.IsInFaction(SprigganizedFaction) ;effect is already active on target
        Active = false 
    Else 
        akTarget.AddToFaction(SprigganizedFaction) 
        Active = true 
    Endif 
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster) 
    If Active == True 
        akTarget.RemoveFromFaction(SprigganizedFaction)
    Endif 
EndEvent
Link to comment
Share on other sites

 

Hmmm, actually reading here: https://www.creationkit.com/index.php?title=HasMagicEffect_-_Actor it seems that the condition will return true if the actor has the effect, regardless of whether the CK conditions are true or not for the effect. So, as a work around, you'll have to do something else to determine if the actor has the effect. You could maybe add the actor to a faction, then remove from faction with OnEffectFinish. Something like this:

 

Faction Property SprigganizedFaction Auto
Bool Active

Event OnEffectStart(Actor akTarget, Actor akCaster)
    If akTarget.IsInFaction(SprigganizedFaction) ;effect is already active on target
        Active = false 
    Else 
        akTarget.AddToFaction(SprigganizedFaction) 
        Active = true 
    Endif 
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster) 
    If Active == True 
        akTarget.RemoveFromFaction(SprigganizedFaction)
    Endif 
EndEvent

 

Does that mean while having this effect, the PC is also friend with the spriggans? If that's the case, it's quite nice. However, I don't wanna mess with factions as I want to expand the features of this spell further. I also have a mod that modifies the relationship of the PC with the wild life so I think messing with faction rank is not ideal.

Edited by nofawkingasianservers
Link to comment
Share on other sites

The simplest way if using a script is to set a global variable to 1 when the effect starts, then set it to 0 when it finished.

 

You can then check for the global variable elsewhere either from a script or as a condition function.

From what I've read on the Creation Kit website, I have to use one of the pre defined global variable? If that's the case, which one should I use to avoid that global variable from being changed by other mods? Or is it the same case in C, where I can define my own global variable?

 

Edit: Further fiddling with the creation kit reveals that I can make my own global var, stupid me :>

 

Edit edit: I'm trying the global variable way. For some reason, the script can't modify the value of the global variable.

Scriptname SprigganArmor extends ActiveMagicEffect  
{Matron of the Woods magic effect}

Armor property Spriggancuir Auto
{Points to the spriggan top}
Armor property Sprigganfeet Auto
{Points to the spriggan shoes}
Armor property Spriggangunt Auto
{Points to the spriggan arms}
Armor property Sprigganmask Auto
{Points to the spriggan mask}

Globalvariable property Sprigged Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
float st = Sprigged.GetValue()
if st == 1.0
Debug.Notification("You're already tapping into the power of the Woods")
return
endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Sprigged.SetValue(1.0)       <= The script doesnt execute  further from here
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
int rng = Utility.RandomInt(1,4)
if rng == 1
Debug.Notification("The power of the Woods overwhelms you")
elseif rng == 2
 
Edited by nofawkingasianservers
Link to comment
Share on other sites

Did you fill the property for the global variable on the script?

Yes I have, I currently have 'em set up like this: https://imgur.com/uSSPo0G

 

I think I hook it up properly because if I open the console ingame and type : set sprigganstate to 1 then cast the spell, the condition of the first IF statement is met and it'll push out a notification "You're already tapping into the power of the Woods" in the top left corner. It's just the SetValue() function that refuses to do its job; I haven't figured out why yet.

Edited by nofawkingasianservers
Link to comment
Share on other sites

  • Recently Browsing   0 members

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