How to get NPCs to not spam one spell

Post » Wed Jun 20, 2012 4:35 pm

I've made these NPCs (based off of pokemon) and finally have them all finished up. The only problem remaining is that while I can give them new spells and take some away, the NPCs will always have strong preferences towards one particular spell, which they will spam until the only have enough mana for a lesser spell, which they will then spam until they are entirely out of mana. I was hoping there might be some way to influence the NPC to spells somewhat more randomly.

Anyone know?
User avatar
james reed
 
Posts: 3371
Joined: Tue Sep 18, 2007 12:18 am

Post » Wed Jun 20, 2012 10:51 am

You could add a Cooldown timer to the spells, and have a script remove them for the duration of the cooldown and return them when the cooldown is done.
User avatar
Cedric Pearson
 
Posts: 3487
Joined: Fri Sep 28, 2007 9:39 pm

Post » Wed Jun 20, 2012 6:13 am

I had thought about that, it just seems so...inelegant. Especially when theoretically spell effects have a cooldown already. They just don't seem to actually do anything.

EDIT: Yes, this works fantastically actually. If anyone wants it, here's how you do it:


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


Just put that as one of your effect scripts, and blammo you're done.
User avatar
willow
 
Posts: 3414
Joined: Wed Jul 26, 2006 9:43 pm

Post » Wed Jun 20, 2012 12:56 pm

Well You could Only give them the low power abilities, and use states to "build up" to the high power attacks

Int BuildUpLevel = 0Function AdToBuildup(int Powerlevel)EndFunctionAuto State OutOfCombat    event OnStateBegin()        BuildUpLevel = 0        ; Code to disable all but "Starter" abilities here.    EndEvent    Function AddToBuildUp(int PowerLevel) ; Needs to be defined in all states.    EndFunction    Event OnCombatStateChanged(Actor Who, Int What)       BuildUpLevel = 3 - What ; Gets +2 if entering combat, but only +1 if "searching"       GoToState("CombatStart")    EndEventEndStateState CombatStart    Function AddToBuildUp(int PowerLevel) ; Call this from each of the High (3) low (1) and mid(2) level effects.       BuildUpState += PowerLevel       If BuildUpState >= 5   	   GoToState("CombatLevel5")       EndIf    EndFunctionEndStateState CombatLevel5    event OnStateBegin()       ; Code to enable mid level abilities here.    EndEvent    Function AddToBuildUp(int PowerLevel)       BuildUpState += PowerLevel       If BuildUpState >= 15   	   GoToState("CombatLevel15")       EndIf    EndFunctionEndStateState CombatLevel15    event OnStateBegin()       ; Code to enable High level abilities here.    EndEvent    Function AddToBuildUp(int PowerLevel)       BuildUpState += PowerLevel       If BuildUpState >= 20   	   GoToState("CombatStart")       EndIf    EndFunctionEndState
User avatar
pinar
 
Posts: 3453
Joined: Thu Apr 19, 2007 1:35 pm

Post » Wed Jun 20, 2012 10:59 am

The cooldown thing worked fine, even if it is a little inelegant.
User avatar
Adam Baumgartner
 
Posts: 3344
Joined: Wed May 30, 2007 12:12 pm

Post » Wed Jun 20, 2012 1:14 pm

I have this exact same problem, and it's very frustrating. This seems like the perfect solution, but I can't get it to work.

I copy and pasted your script into the "magic effect" script section of the effect linked to the spell I'm trying to stop him from spamming, but it doesn't seem to do anything...
Am I doing this right?
User avatar
Dark Mogul
 
Posts: 3438
Joined: Tue Feb 20, 2007 11:51 am

Post » Wed Jun 20, 2012 8:07 am

Are you using my script or Redwood's? Use mine, and make sure to set your properties. It should work fine.
User avatar
Ian White
 
Posts: 3476
Joined: Thu Jul 19, 2007 8:08 pm

Post » Wed Jun 20, 2012 9:33 am

Yeah, I'm using your script.

I'm not really sure what the problem is. I gave the spell to the player to test it and it worked perfectly (removed the spell and gave it back after the time limit), but for some reason when the NPC is using the same spell it just doesn't remove it. It's really frustrating, because I feel like I'm so close, but I'm clueless when it comes to scripting right now.

Any ideas?
User avatar
Ronald
 
Posts: 3319
Joined: Sun Aug 05, 2007 12:16 am

Post » Wed Jun 20, 2012 2:03 pm

Ah! I remember this now! I forgot to update my script on here, sorry about that. You also have to unequip the spell, or the NPC thinks it still has a non-existent spell equipped and gets confused.
User avatar
Nina Mccormick
 
Posts: 3507
Joined: Mon Sep 18, 2006 5:38 pm

Post » Wed Jun 20, 2012 12:14 pm

That makes sense.

I tried this:

Scriptname SpellCoolDown01 extends activemagiceffect

Int Property time Auto

SPELL Property Move Auto

event OnEffectStart(Actor akTarget, Actor akCaster)
akCaster.removespell(Move)
akCaster.unequipspell(Move,0)
akCaster.unequipspell(Move,1)
Utility.Wait(time)
akCaster.addspell(Move)
endEvent

And again it worked for the player, but not the NPC. I'm still confused...

I also tried putting the "removespell" after the "unequipspell" lines, but it made no difference.
User avatar
Tyrel
 
Posts: 3304
Joined: Tue Oct 30, 2007 4:52 am

Post » Wed Jun 20, 2012 5:45 pm

This is my exact script and it works...
Scriptname SpellCoolDown extends ActiveMagicEffect Int Property time  Auto SPELL Property Move  Auto event OnEffectStart(Actor akTarget, Actor akCaster)   akCaster.removespell(Move)   akCaster.UnequipSpell(Move, 1)   akCaster.UnequipSpell(Move, 0)   Utility.Wait(time)   akCaster.addspell(Move)endEvent

The only thing I can think of is that you somehow have the wrong spell set as the property or something. I dunno.
User avatar
Skrapp Stephens
 
Posts: 3350
Joined: Mon Aug 06, 2007 5:04 am

Post » Wed Jun 20, 2012 10:13 am

No, I checked that. Funny thing is that it works as far as unequipping the spell, but instead of being removed he just equips it again immediately. So I am totally stumped...

Anyway, thank you for your help. I will try to make my own topic since this is my issue, not yours. But if you think of anything let me know
User avatar
Nina Mccormick
 
Posts: 3507
Joined: Mon Sep 18, 2006 5:38 pm

Post » Wed Jun 20, 2012 10:22 am

Well, it probably shouldn't take three long days of research and trial and error to do something so simple, but it did. Thanks Bethesda.

So first I downloaded your pokemon mod to see if I could find any differences between the way yours was set up and mine. I noticed right away that the spells on your NPCs were not in their spell list but instead added through a script.
I guess if the spells are in the spell list they are impossible to remove through a script. That's why it was working for the player, because I was giving it to the player through a spell tome.

So basically what you have to do is make a script and place it in your actor that gives him all the spells you want him to have. I made one that happens at the start of battle. I figured this would be the best way. I also took it further and added the cooldown script to the actor as well. That way you don't have to put a script on every spell you give him. However, if you want it to be spell-specific (different cooldown times, etc) you can still use the first part of my script below and put the cooldown script in the magic effect.

So here it is, finally. Hope this saves someone else from tearing their hair out like I did = /:

Scriptname GiveSpells extends ActorSpell Property Spell01 AutoSpell Property Spell02 AutoSpell Property Spell03 AutoSpell Property Spell04 AutoInt Property Time AutoEvent OnCombatStateChanged (Actor akTarget, int aeCombatState)	if (aeCombatState == 1)	  Self.AddSpell (Spell01)	  Self.AddSpell (Spell02)	  Self.AddSpell (Spell03)	  Self.AddSpell (Spell04)	endIfendEventEvent OnSpellCast (Form akSpell)   Self.RemoveSpell (akSpell as Spell)   Utility.Wait (Time)   Self.AddSpell (akSpell as Spell)endEvent

For more spells of course just add more "Spell Property XXXX Auto".
User avatar
Amanda Furtado
 
Posts: 3454
Joined: Fri Dec 15, 2006 4:22 pm

Post » Wed Jun 20, 2012 3:41 am

You should play around with the Pokemon. I don't talk about it on here any more, but I put a LOT of work into them, and I personally think they are among the msot interesting modded companions out there.
User avatar
Scotties Hottie
 
Posts: 3406
Joined: Thu Jun 08, 2006 1:40 am


Return to V - Skyrim