OnMagicEffectStart trouble

Post » Wed Jun 20, 2012 1:09 pm

I have this script attached to all of my spells I made for my NPC followers. Basically what it does is induce a cooldown period for any spell, which is handy as otherwise NPCs tend to just spam one spell over and over. Here is the script:
Scriptname SpellCoolDown extends ActiveMagicEffect  Int Property time  Auto  SPELL Property Move  Auto  event OnEffectStart(Actor akTarget, Actor akCaster)   akCaster.removespell(Move)   Utility.Wait(time)   akCaster.addspell(Move)endEvent
The problem seems to be that when the akCaster.removeSpell(Move) works properly and removes the spell from the NPC. Unfortunately, when the addspell function is called, for whatever reason it applies to the player instead of the NPC follower, so the NPC is stuck without any spells while the player has a bunch of weird spells they didn't need.

Help?
User avatar
Johanna Van Drunick
 
Posts: 3437
Joined: Tue Jun 20, 2006 11:40 am

Post » Wed Jun 20, 2012 8:38 am

Have you tried some debug message boxes to see whether the akCaster variable somehow changes (though I cannot say how that would happen).
Maybe Actor.Addspell is bugged and does not work for NPCs?
User avatar
Spencey!
 
Posts: 3221
Joined: Thu Aug 17, 2006 12:18 am

Post » Wed Jun 20, 2012 9:15 am

There are two approaches that I used for my autocast racial mod.
1.
I created a "dummy effect" which did nothing and didnt display in teh UI anywhere.
Then on my custom spells, I called that effect with a duration as long as I wanted the cooldown to be (as well as the heal/fire/wahetevr effect of the spell).
In a script I performed a check to see if the effect was still on the casting actor. If it was prewsent, then no cast, if it was absent, then cast away.

I had issues with this on *some* NPC spells but not all which is why I had to resort to...

2. Entirely scripting a system using states and game updates on spell effect. It used onupdates and registerforupdate() to change the scripts state: I also had to put in checks for sleeping/ quick travelling which broke the register for updates.

2 is more robust but much more complex. 1 is pretty simple but may be buggy with some NPCS/Spells.

it also means you arent fiddling aroudn with adding then removing spells from an npc, jsut when tehy can cast it :)
User avatar
adam holden
 
Posts: 3339
Joined: Tue Jun 19, 2007 9:34 pm

Post » Wed Jun 20, 2012 2:06 am

I don't know the reason why it's not working correctly. I would try what Cronos988 suggested. I don't think what thesniperdevil suggested would work for you, because his mod was dealing with abilities, and casting spells from the abilities' scripts. What you're doing is letting your NPCs cast spells on their own, not through using the http://www.creationkit.com/Cast_-_Spell function.

If you can't figure it out, you could try to change the way you create cooldowns Instead of having the spells be scripted with the cooldown, script the NPCs instead.

Scriptname TestActorScript extends ActorFormList property AllPossibleMoves autoArray[] AllPossibleMovesCooldownint Function GetIndexOfElementInFormlist(Form tempForm, FormList tempFormList)    int index = tempFormList.GetSize()    while (index > 0)        index -= 1        if (tempForm == tempFormList.GetAt(index)            Return index        endif    endwhileEndFunctionEvent OnSpellCast(Form akSpell)    if (AllPossibleMoves.HasForm(akSpell))        int index = GetIndexOfElementInFormList(akSpell, AllPossibleMoves)        int cooldown = AllPossibleMovesCooldown[index]        RemoveSpell(akSpell as Spell)        Utility.Wait(cooldown)        AddSpell(akSpell as Spell)    endifEndEvent
User avatar
Tarka
 
Posts: 3430
Joined: Sun Jun 10, 2007 9:22 pm

Post » Wed Jun 20, 2012 4:22 pm

I don't get an error report in my logs, which is making me think that maybe the cooldown is working properly, but the NPC doesn't know to switch spells when it gets what its using abruptly taken away like that. I'm going to try to see if there's some way of equipping another spell at random.
User avatar
Naomi Lastname
 
Posts: 3390
Joined: Mon Sep 25, 2006 9:21 am

Post » Wed Jun 20, 2012 10:47 am

Interesting thought, you can verify by calling http://www.creationkit.com/EvaluatePackage_-_Actor on your NPC's, if they change behavior, you got it.

And what thesniperdevil suggested can work as well, it needs two separate magic effects, though.
One is the controller, enforcing the cooldown via papyrus and needs to be a ability/constant effect.
The other effect is whatever you want to add/remove.
User avatar
Philip Lyon
 
Posts: 3297
Joined: Tue Aug 14, 2007 6:08 am

Post » Wed Jun 20, 2012 11:59 am

The problem was that she still had a spell equipped that she no longer had learned, which bugs the AI pretty hard. All you have to do is after they forget the spell:
akCaster.UnEquipSpell(Move, 1)
akCaster.UnEquipSpell(Move, 0)

and it works fantastically.
User avatar
teeny
 
Posts: 3423
Joined: Sun Feb 25, 2007 1:51 am

Post » Wed Jun 20, 2012 6:35 pm

So that fixes the problem of the player getting all the spells instead of the NPC too?
User avatar
Natasha Callaghan
 
Posts: 3523
Joined: Sat Dec 09, 2006 7:44 pm

Post » Wed Jun 20, 2012 7:37 am

So that fixes the problem of the player getting all the spells instead of the NPC too?

That was only happening with one spell, and I'm still not sure why. I haven't seen it happen since though.
User avatar
laila hassan
 
Posts: 3476
Joined: Mon Oct 09, 2006 2:53 pm


Return to V - Skyrim