Understanding why this script fails

Post » Tue Jun 19, 2012 6:25 pm

Spoiler
Scriptname DivineHealthExquisiteScript extends activemagiceffect  Actor Property player Auto hiddenSpell Property RestoreHealth Auto ; restores 1000 healthSpell Property RestoreMagicka Auto ; restores the cost of Divine HealthFloat Property HealthThreshold Auto ; Defined as 0.4 ie 40% of healthFloat CurrentHealth;FUNCTIONS-----------------------------------------------------------------------------------------	; function to cast the spell Divine Health, defined as RestoreHealthFUNCTION Healing(Actor akTarget)	RestoreHealth.cast(player, player)	ENDFUNCTION	; function to cast the spell Divine Health NoCast , defined as RestoreMagickaFUNCTION Magicka(Actor akTarget)	RestoreMagicka.cast(player, player)	ENDFUNCTION	;EVENTS--------------------------------------------------------------------------------------------Event OnEffectStart (Actor akTarget, Actor akCaster)	player = akTarget		CurrentHealth = player.GetActorValuePercentage("Health")		Debug.Trace (CurrentHealth)	; Refunds the cost of Divine Health if the player is above the threshold		If (CurrentHealth >= HealthThreshold)				Debug.Notification (CurrentHealth +":- Health above threshold")					Magicka(player)	; If the player's health is below the defined maximum health, heals the player fully			Elseif (CurrentHealth < HealthThreshold)			Debug.Notification (CurrentHealth +":- Divine Healing Cast")				;player.RestoreAv("Health", 1000) This line causes the script to work perfectly				Healing(Player) ; Casts Divine Health Heal This line causes both spells to be cast					Endif	endEvent

Im new to scripting, this is only my second script. I have encountered an issue which i do not understand why it occurs

This is still a work in progress but the idea behind the script is to create an instant heal which restores health fully but only when the players health is below 40%. I intend to add a cooldwon effect to it but have yet to add it to the script
If the spell is cast when health is above 40%, the cost of the spell is refunded.
However below 40% the spell cost applies and the player is healed fully.

The issue that i am encountering is in this part of the script

; If the player's health is below the defined maximum health, heals the player fully
Elseif (CurrentHealth < HealthThreshold)
Debug.Notification (CurrentHealth +":- Divine Healing Cast")
;player.RestoreAv("Health", 1000)
Healing(Player)


If i use this line:
Healing(Player) - Casts a spell to heal 1000 health
The heal spell triggers and then is followed by the restore magicka spell which shouldn't happen. This is born out by the two Debug Notifications which are displayed


However if i use this line instead
player.RestoreAv("Health", 1000)
the script works as intended.

If anyone can explain why this occurs as far as i can see both lines should have the same effect, but what i dont understand is why it does this.

Can anyone explain why it is occurring?
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm

Post » Wed Jun 20, 2012 6:19 am

Maybe a dumb question, but did you by any chance attach this script to the spell effect for "RestoreHealth"?
User avatar
Tyrone Haywood
 
Posts: 3472
Joined: Sun Apr 29, 2007 7:10 am

Post » Tue Jun 19, 2012 3:49 pm

I was going to respond saying no, i have attached it to the dummy effect spell that the player uses to call the script, however after your comment double checked all magic effects. I feel so stupid, i had left the script attached to the restorehealth effect when i had duplicated the magic effect spell.

In essence the script fired off as it should have with the dummy spell, and then fired again on the restore health spell which was triggered by the script.
Many thanks RandomNoob, i just could not see why it was doing this. It is so obvious now. It also explains why i was getting 2 debug notifications
User avatar
Nancy RIP
 
Posts: 3519
Joined: Mon Jan 29, 2007 5:42 am


Return to V - Skyrim