Hello, currently I am working on a new custom race for which I want to make a system that tracks the player's health and adds a certain spell when the player is at 25%. The script for this is done and should work, but it simply doesn't get executed. I have put a debug message in the onInit event and it never gets displayed. I assume the script simply doesn't get executed. I have tried attaching the script to a magic effect w/ constant effect on self and I tried binding it to a quest that is always running (run once is off) also to no avail. Here is the script:
Scriptname NingheimDivineInterventionScript extends Actor ;or Quest hidden or ActiveMagicEffect? I believe this is right. I tried all three anyway.
;Quest Property aaaNingheimHealthTrackingQuest Auto ;Only use if Quest is necessary to function <-Never used this
Spell Property NingheimDivineIntervention Auto ; A shield + shock cloak spell
Spell Property abDI Auto ; The ability I use to see if the script executes
Float Property healthThreshold = 0.25 Auto
Sound Property activationBlast Auto ; Just sound
Sound Property deactivationNotice Auto ; Just sound
String playerRace
Float playerHealthPercent ; Will store current player health in percentages
Actor player
;Event OnEffectStart(Actor Target, Actor Caster) <-Left-over code from when I used it in a MagicEffect
Event OnInit()
;Debug.Notification("Initialized DIabScript")
player = Game.GetPlayer()
;Currently there is an ability spell I have so I can see if the script actually starts by letting it get deleted. It doesn't get deleted however
If player.HasSpell(abDI)
player.RemoveSpell(abDI)
Debug.MessageBox("DI Ability removed.")
endIf
RegisterForSingleUpdate(1.0) ; Check current player status per second
endEvent
; Event that should occur after init through the RegisterForSingleUpdate(1.0)
Event OnUpdate()
playerHealthPercent = player.GetAVPercentage("Health") ;Should give a value between 0.0 and 1.0
playerRace = player.GetRace()
; Check whether health is below set threshold, check if the race is correct and check whether combat is actually initialized
If(playerHealthPercent <= healthThreshold && (playerRace == "NingheimRace" || playerRace == "NingheimRaceVampire") && player.IsInCombat())
If player.HasSpell(NingheimDivineIntervention) == 0
player.AddSpell(NingheimDivineIntervention)
player.EquipSpell(NingheimDivineIntervention, 2) ; I give the player a choice whether to let the power activate as it only works once a day
activationBlast.Play(player)
Debug.Notification("Divine Intervention has come " + playerRace) ; Just a test thing
endIf
; This is simply the reverse conditional statement from the above in case the player restores health. The power would get removed again. Will probably use a utility.wait() here so it doesn't get removed right when you wanted to use it.
ElseIf(playerHealthPercent > healthThreshold && (playerRace == "NingheimRace" || playerRace == "NingheimRaceVampire") && !player.IsInCombat() && player.HasSpell(NingheimDivineIntervention))
player.RemoveSpell(NingheimDivineIntervention)
deactivationNotice.Play(player)
Debug.Notification("Divine Intervention has passed" + playerRace)
endIf
RegisterForSingleUpdate(1.0) ; Causes the script to loop another time
;Debug.Trace("Going for another update-pass. Conditions checked.")
endEvent
It compiles correctly and I believe my issue isn't with the scripting. The issue is that I need to know how to get it to run. Also, if you're wondering why I use "RegisterForSingleUpdate(1.0)" instead of "RegisterForUpdate(1.0)" is because a RegisterForUpdate will keep running even after the script/plug-in isn't active anymore (it sticks to the save) while with the current set-up using two RegisterForSingleUpdate functions ensures me it will stop running once the plugin is deactivated. Essential for potential patches and correct mod removal. Thanks a lot for viewing and if you can't help directly, but you happen to know a mod that has a health checker for the player, let me know. I could learn how it should be done from it.