Help with this healing script

Post » Sat Nov 17, 2012 9:10 pm

I have made a script attached to a follower (vilma) what allowing to auto-heal the player if its health is less than 50%.


Scriptname AP_Health extends ActorActor vilmaGlobalVariable Property b_VilmaAutoHealth Auto ; boolean, If "1", auto-healSpell Property HealOther  Auto  Float Property SeekRange = 1000.0 AutoFloat Property PulseRate = 1.0 Auto ; How often do we shoot?Event OnInit()	RegisterForSingleUpdate(PulseRate)EndEventEvent OnUpdate()	bool auto_health= b_VilmaAutoHealth.Getvalue()	if auto_health== 1 ; if global variable= 1		if vilma.GetDistance(Game.GetPlayer()) < SeekRange ; if close to the player			float PercentHealth = Game.GetPlayer().GetActorValuePercentage("health")			If (PercentHealth < 0.5)				;if (vilma.HasSpell(HealOther))					  Debug.Notification("6")				   HealOther.Cast(vilma, Game.GetPlayer())  ; cast the spell  				;endif			endif		endif	  RegisterForSingleUpdate(PulseRate)	else		UnregisterForUpdate();	endifendEvent

It works till the line "If (PercentHealth < 0.5)" that never achieves the condition.
Why?
Please help...
User avatar
Kortniie Dumont
 
Posts: 3428
Joined: Wed Jan 10, 2007 7:50 pm

Post » Sun Nov 18, 2012 3:17 am

Try:
Spoiler
ScriptName AP_Health Extends ActorActor Property PlayerREF AutoActor Property Vilma AutoFloat Property SeekRange = 1000.0 AutoFloat Property PulseRate = 1.0 Auto ; How often do we shoot?GlobalVariable Property b_VilmaAutoHealth Auto ; boolean, If "1", auto-healSpell Property HealOther Auto  Event OnInit()	RegisterForSingleUpdate(PulseRate)EndEventEvent OnUpdate()	If b_VilmaAutoHealth.GetValue()		If PlayerREF.GetActorValuePercentage("Health") < 0.5			If GetDistance(PlayerREF) < SeekRange				HealOther.Cast(Vilma, PlayerREF)				Debug.Notification("Gatorade me, beotch!")			EndIf		EndIf		RegisterForSingleUpdate(PulseRate)	EndIfEndEvent
It'll be 'cheaper' for a few reasons, but I've never used GetActorValuePercentage. If it still won't fire, try 'PlayerREF.GetActorValue("Health") < 25' or something similar.
User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Sun Nov 18, 2012 5:12 am

I've changed the script to:
Scriptname AP_Health extends ActorActor Property vilma AutoFloat Property SeekRange = 1000.0 AutoFloat Property PulseRate = 1.0 Auto ; How often do we shoot?GlobalVariable Property b_VilmaAutoHealth Auto ; boolean, If "1", auto-healSpell Property HealOther AutoFunction CheckHealthPlayer()	b_VilmaAutoHealth.SetValue(1)	RegisterForUpdate(PulseRate)endFunctionFunction NoHealthPlayer()	b_VilmaAutoHealth.SetValue(0)	UnregisterForUpdate()endFunctionEvent OnUpdate()		If (b_VilmaAutoHealth.GetValue()==1)	   	 Debug.Notification("1")	   	 int playersHealth = Game.GetPlayer().GetActorValue("health") as int				If  (playersHealth  < 25)		   	  Debug.Notification("2")						If vilma.GetDistance(Game.GetPlayer()) < SeekRange								HealOther.Cast(self, game.getPlayer())								Debug.Notification("Gatorade me, beotch!")						EndIf				EndIf		EndIfEndEvent
It works, but the NPC heals the player continuously. The condition of the Player's Health always keeps TRUE. The healing never stops.
User avatar
Ross Zombie
 
Posts: 3328
Joined: Wed Jul 11, 2007 5:40 pm

Post » Sun Nov 18, 2012 3:21 am

I've changed the script to:
Scriptname AP_Health extends ActorActor Property vilma AutoFloat Property SeekRange = 1000.0 AutoFloat Property PulseRate = 1.0 Auto ; How often do we shoot?GlobalVariable Property b_VilmaAutoHealth Auto ; boolean, If "1", auto-healSpell Property HealOther AutoFunction CheckHealthPlayer()	b_VilmaAutoHealth.SetValue(1)	RegisterForUpdate(PulseRate)endFunctionFunction NoHealthPlayer()	b_VilmaAutoHealth.SetValue(0)	UnregisterForUpdate()endFunctionEvent OnUpdate()		If (b_VilmaAutoHealth.GetValue()==1)	   	 Debug.Notification("1")	   	 int playersHealth = Game.GetPlayer().GetActorValue("health") as int				If  (playersHealth  < 25)		   	  Debug.Notification("2")						If vilma.GetDistance(Game.GetPlayer()) < SeekRange								HealOther.Cast(self, game.getPlayer())								Debug.Notification("Gatorade me, beotch!")						EndIf				EndIf		EndIfEndEvent
It works, but the NPC heals the player continuously. The condition of the Player's Health always keeps TRUE. The healing never stops.

Take out all but one of the endif, and change all but the first if to Elseif. Try that mate.
User avatar
Jack Moves
 
Posts: 3367
Joined: Wed Jun 27, 2007 7:51 am

Post » Sun Nov 18, 2012 1:18 am

The condition of the Player's Health always keeps TRUE.

Maybe it is because of this:


Function CheckHealthPlayer()		b_VilmaAutoHealth.SetValue(1)		RegisterForUpdate(PulseRate)endFunction

?
User avatar
xx_Jess_xx
 
Posts: 3371
Joined: Thu Nov 30, 2006 12:01 pm

Post » Sat Nov 17, 2012 5:02 pm

Thanks you all for your support and very profitable help. Finally I have made the mod: http://skyrim.nexusmods.com/mods/23747/. The source of the script is also included.
User avatar
Hairul Hafis
 
Posts: 3516
Joined: Mon Oct 29, 2007 12:22 am


Return to V - Skyrim