magic effect spell fires even though global is set

Post » Tue Sep 22, 2015 9:08 am

Hi,

I have a spell that my Dath Knight is spamming like crazy so I created a global variable to force him to stop using it. the global value becomes '3' after he uses the spell, that part works fine. But he stil is able to use the spell even with the condition as shown below. Like it is being ignored. I tried using Subject and Target as the target, though I do not know if that matters since a global value is being looked at... What am I missing?

http://imagizer.imageshack.us/v2/800x600q90/538/tuiONb.jpg

User avatar
lolli
 
Posts: 3485
Joined: Mon Jan 01, 2007 10:42 am

Post » Tue Sep 22, 2015 3:50 pm

That won't stop him from casting it, it will only stop the spell from doing any damage. Making an NPC stop casting a spell is more difficult.

I have seen it successfully done with Packages before, but that is kind of complicated.

You could also try removing the spell entirely with RemoveSpell and then also unequipping the spell after you remove it with UnequipItem.

Another idea that comes to mind (I haven't tested this, but I think it would work...) is to try setting the spell magnitude/duration to zero using the SKSE function SetNthEffectMagnitude. Usually NPCs will use whatever their strongest spell is, so if you set it to have zero power/magnitude they NPC might stop trying to use it and use something else instead.

User avatar
Nice one
 
Posts: 3473
Joined: Thu Jun 21, 2007 5:30 am

Post » Tue Sep 22, 2015 6:10 pm

Thank you for posting, much appreciated. After considering the suggestions and experimenting the following workaround works though I hate scripting it.

When I want the fool toon to use his melee weapons I use a script that extends Actor ont he toon to remove all his spells. When i want him to use spells i add them back. One thing I learned: the toon CANNOT start life with the spell already assigned. If he does, he will cast the spell EVEN IF REMOVED. So it must be added during the fight.

Do you know what is a pain though?? I am using the On Hit event on the toon to add or remove spells. So when he gets hit he loses his spells. When he gets hit again he gains them back. See the problem? In a melee fight he will be gaining them and losing them every second. Not good.

So I had to write a script. See below. When the fool is hit, he will be given the spell. a random time is picked , and when expired and hit again, he will lose the spell. a random time is picked again, and after that time if hit he will regain the spell. The logic being that if he is still getting hit he needs to try something else. But he will not just toggle back on forth on every hit.

But this script can be further enhanced with other events, such as IsUnconscious, IsAlarmed, IsAlerted, IsBleedingOut, IsInCombat, IsSprinting, IsRunning, IsSwimming. And then different spells or weapons given or taken depending on what the status are. On Hit will also let me check any attribute so if fool is half low on health I can select a different spell to use, or weapon, or scripted summon. See/ But more work that I was counting on.

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, \	Bool abBashAttack, Bool abHitBlocked)					If cool == 1		If Self.HasSpell(DKDeathCoilSpellUnholy07)  			Self.RemoveSpell(DKDeathCoilSpellUnholy07)			Debug.Notification("Removed!")			cool = 5			RegisterForSingleUpdate(Utility.RandomInt(30, 90))		EndIf	EndIf		If cool == 0		If !Self.HasSpell(DKDeathCoilSpellUnholy07)			Self.AddSpell(DKDeathCoilSpellUnholy07)  			Debug.Notification("Added!")  			cool = 6			RegisterForSingleUpdate(Utility.RandomInt(30, 90))		EndIf	EndIf			EndEventEvent OnUpdate()		If cool == 5		;self.addspell(DKDeathCoilSpellUnholy07)		Debug.Notification("Added!")  		cool = 0	EndIf		If cool == 6		;self.removespell(DKDeathCoilSpellUnholy07)		Debug.Notification("Removed!")  		cool = 1	EndIf		EndEvent
User avatar
Russell Davies
 
Posts: 3429
Joined: Wed Nov 07, 2007 5:01 am

Post » Tue Sep 22, 2015 8:29 am

You can also use States to simplify your code

Spoiler
Auto State ActiveState    Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, \        Bool abBashAttack, Bool abHitBlocked)        GoToState("InactiveState")        If Self.HasSpell(DKDeathCoilSpellUnholy07)              Self.RemoveSpell(DKDeathCoilSpellUnholy07)        Else            Self.AddSpell(DKDeathCoilSpellUnholy07)        EndIf        Utility.Wait(Utility.RandomInt(30, 90))        GoToState("ActiveState")    EndEventEndStateState InactiveState    Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, \        Bool abBashAttack, Bool abHitBlocked)        ;OnHit event will be ignored while we are in the InactiveState    EndEventEndState 
User avatar
Sian Ennis
 
Posts: 3362
Joined: Wed Nov 08, 2006 11:46 am

Post » Tue Sep 22, 2015 6:39 pm

Very elegant, any drawbacks to pausing the script for such a long time? Can I still use other events such as If InBleedout? If the player leaves the area and the toon is unloaded? I am trying to avoid NONE conditions to minimize ctds and log spam.

Could I use the inactive state to check for further scenarios? Such as spawning helper toons if the toons health is below 20?

User avatar
Adam
 
Posts: 3446
Joined: Sat Jun 02, 2007 2:56 pm

Post » Tue Sep 22, 2015 1:15 pm

Wait is a latent function which means other events and functions in your script will run just fine while OnHit is in the inactive state. It will only disable OnHit in the script, everything else runs as normal. And there won't be any NONE conditions or log errors introduced by waiting and then changing states.

Yes, you can use the inactive state for other things - though I'm not sure exactly what you're asking. You can put secondary versions of other functions/events inside the Inactive state if you want to also have a second version of them running during that state. You can also put OnBeginState or OnEndState events inside of a state to do certain things when the state is first entered or when the script leaves that state (like spawning other actors).

User avatar
Hope Greenhaw
 
Posts: 3368
Joined: Fri Aug 17, 2007 8:44 pm


Return to V - Skyrim