How HasMagicEffect() is supposed to work?

Post » Wed Jun 20, 2012 11:42 pm

I have made a ability that attaches to the player a magiceffect through some conditions

Spoiler

Scriptname testAbility extends activemagiceffect

Event OnEffectStart (Actor akTarget, Actor akCaster)
debug.notification("ON")
EndEvent

Event OnEffectFinish (Actor akTarget, Actor akCaster)
debug.notification("OFF")
EndEvent

the game handles everything correcly: the ability shows/hides in UI as expected, and the debug notification is correct.

But when I check if the magic effect is on the player with
game.getplayer().hasmagiceffect(myTestAbility)
, the game always return true.

what I am missing here...? The effect is still on the player even if it has finished? If yes, what is the correct method to check if it is active?
User avatar
Chris Jones
 
Posts: 3435
Joined: Wed May 09, 2007 3:11 am

Post » Wed Jun 20, 2012 8:13 pm

Erm, I think it's amazing you managed to get that to work in the activemagiceffect script.. I could only get the thing to work in the actor script.

But one way to check is do this:

if game.getplayer().hasmagiceffect(myTestAbility);do stuffendif
User avatar
vicki kitterman
 
Posts: 3494
Joined: Mon Aug 07, 2006 11:58 am

Post » Wed Jun 20, 2012 8:20 am

the property is already in, and correctly set in esp too. (otherwise that would return false anyway)
User avatar
Stephanie Valentine
 
Posts: 3281
Joined: Wed Jun 28, 2006 2:09 pm

Post » Wed Jun 20, 2012 12:34 pm

if game.getplayer().hasmagiceffect(myTestAbility);do stuffendif
this is exactly what I am doing, but what I am saying if that game.getplayer().hasmagiceffect(myTestAbility) always returns true.

(edit, crap, I added a post instead of editing the previous one, sorry)
User avatar
Kayla Oatney
 
Posts: 3472
Joined: Sat Jan 20, 2007 9:02 pm

Post » Wed Jun 20, 2012 10:10 am

Pretty sure that is not supposed to happen. I am mostly using hasmagiceffectwithkeyword, and that works as it should.

What are the parameters of your magic effect (Fire&Forget, Self etc.)?
Is it a custom made effect or did you use one that is already in place?
Does the spell applying the Effect have any other effects attached? Are any of those still running?
User avatar
OnlyDumazzapplyhere
 
Posts: 3445
Joined: Wed Jan 24, 2007 12:43 am

Post » Wed Jun 20, 2012 9:20 pm

He's using a magic effect attached to an ability. There was a topic by kuertee describing how to use this to check for conditions not available through scripting commands (the example used was GetPC1stPerson).

My guess is that the script only triggers the OnEffectStart when the magic effect becomes active and triggers OnEffectFinish when it becomes inactive. Probably HasMagicEffect doesn't care whether or not the effect is currently active, just whether or not you have it at all.
User avatar
Beast Attire
 
Posts: 3456
Joined: Tue Oct 09, 2007 5:33 am

Post » Wed Jun 20, 2012 5:34 pm

He's using a magic effect attached to an ability. There was a topic by kuertee describing how to use this to check for conditions not available through scripting commands (the example used was GetPC1stPerson).
yes this is the same idea
My guess is that the script only triggers the OnEffectStart when the magic effect becomes active and triggers OnEffectFinish when it becomes inactive. Probably HasMagicEffect doesn't care whether or not the effect is currently active, just whether or not you have it at all.
this is exactly what I am thinking...:
there is no way to simply check directly if the effect is active or not in that case...
I've finally solved the problem with a quest Script that handle the magiceffect response.
User avatar
Lucie H
 
Posts: 3276
Joined: Tue Mar 13, 2007 11:46 pm

Post » Wed Jun 20, 2012 5:01 pm

I have made a ability that attaches to the player a magiceffect through some conditions

Spoiler

Scriptname testAbility extends activemagiceffect

Event OnEffectStart (Actor akTarget, Actor akCaster)
debug.notification("ON")
EndEvent

Event OnEffectFinish (Actor akTarget, Actor akCaster)
debug.notification("OFF")
EndEvent

the game handles everything correcly: the ability shows/hides in UI as expected, and the debug notification is correct.

But when I check if the magic effect is on the player with
game.getplayer().hasmagiceffect(myTestAbility)
, the game always return true.

what I am missing here...? The effect is still on the player even if it has finished? If yes, what is the correct method to check if it is active?

is "myTestAbility" a magic effect or an ability? If it is an ability, it will always return true because the ability will always be present on the player until you manually remove it. The magic effect attached to the ability is what switches on and off with your conditions.
So
game.getplayer().hasmagiceffect(myMagicEffect)
should be what you're after. (where "myMagicEffect" is the effect attached to the ability)
User avatar
Cedric Pearson
 
Posts: 3487
Joined: Fri Sep 28, 2007 9:39 pm

Post » Wed Jun 20, 2012 7:10 pm

myTestAbility is only the name I gave to the property, but it's linked to the magicEffect (It's not possible to link a magicEffect property to a spell anyway.)
User avatar
x_JeNnY_x
 
Posts: 3493
Joined: Wed Jul 05, 2006 3:52 pm

Post » Wed Jun 20, 2012 6:38 pm

I think you have a rogue effect on your player that's perhaps not in the UI. Have you checked your uses on the MGEF and see if there's more than one spell that might be using it? This .... appears ... to work for me. Although come to think of it, I apply some of my MGEFs in a very unique way when I have to use abilities. Since you have a workaround, I won't go into it, but if you want to know PM me and I'll respond here.

-MM
User avatar
Rebecca Clare Smith
 
Posts: 3508
Joined: Fri Aug 04, 2006 4:13 pm

Post » Wed Jun 20, 2012 11:56 pm

@mofomojo
Yes, I was thinking about this but I am pretty sure I have only one spell using the MGEF. And I am also completly sure the "spell-ability" is applied once to the player (and not in a onUpdate or onInit event). This is really wierd.
User avatar
Suzie Dalziel
 
Posts: 3443
Joined: Thu Jun 15, 2006 8:19 pm

Post » Wed Jun 20, 2012 10:09 am

So I ran across this problem with magic effect archetypes being "thought" to be applied by the game when I was implementing sun damage for my vampirism mod. I had an ability that applied health damage. The spell conditions only applied the effect if the player was outside and the lightlevel was greater than a certain value, but in the game, even when I wasn't taking damage the engine *thought* I was and wouldn't let me fast travel, sleep, or wait. To work around the problem I implemented the following workaround....so...it is possible if you have an ability that only applies effects under certain conditions, the game will always think the player has the effect even if the conditions are not TRUE and the effect isn't actually applied. Stupid I know.

1) Create a spell with necessary conditions for effect
2) Create an effect for the spell which adds a perk
3) Have the perk apply another spell
4) Have the spell use an actual MGEF that applies whatever effect you need to test for your conditions

That should work to dynamically add/remove the proper effect you need to test for. Stinks that it has to be so complicated. Alternatively...I can't recall if I ever tested having the required conditions on BOTH the SPELL and the EFFECT and getting by with one spell. The thought hadn't actually crossed my mind until I read your post since I haven't thought about this problem for 3-4 months (I started my mod with SkyEdit).

-MM
User avatar
Dustin Brown
 
Posts: 3307
Joined: Sun Sep 30, 2007 6:55 am

Post » Wed Jun 20, 2012 11:30 am

@mofomojo
Thank for the tips. My method is a bit different a works quite good ad far as I know:

1) Create a spell with necessary conditions for effect
2) Create 2 effect for the spell. One with a condition and one for the opposite condition (condition == 1) and (condition != 1)
3) attach a script to each effect that set a variable to true or false (depending of the conditions logic) in their onEffect Start event (I dont trust the onEffectStop, this is why I use 2 effects)

Then you just have to check the variable value.
In my case I stored the variable in a Quest script (where I also put some functions that I use as a small personnal api)
but that would also probably work with adding/removing perk, or with a globalvariable.
User avatar
RObert loVes MOmmy
 
Posts: 3432
Joined: Fri Dec 08, 2006 10:12 am

Post » Wed Jun 20, 2012 7:04 pm

Very good! There's always more than one way, and we learn when we see about new tecgniques.
User avatar
Jennifer Rose
 
Posts: 3432
Joined: Wed Jan 17, 2007 2:54 pm


Return to V - Skyrim