Jump to content

Need object for health tracking system


Seren4XX

Recommended Posts

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.

Link to comment
Share on other sites

Mm..

 

Just wondering, did you check how the perk "Avoid Death" works?

As I do believe it might contain necessary info on how to make something like that work.

 

If not, SkyRe - Races, Dunmer has some new abilities, mostly spells, that take effect once HP is low enough.

(With spells I mean REAL spells, so those scripts should at least cover what you are trying to achieve)

 

Sorry that I can't help you directly, but I hope I was able to point you at right direction :thumbsup:

Link to comment
Share on other sites

All that seems overly complicated.

 

Why not just add an ability to the race in the ck.

Set up your custom ability with a condition (on the spell not the magic effect) "GetActorValuePercent". That way the Magic Effect is only active when you want it to be.

If you want it to be more like a power (only usable once/day) you could do that as well with some scripting.

Link to comment
Share on other sites

Mm..

 

Just wondering, did you check how the perk "Avoid Death" works?

As I do believe it might contain necessary info on how to make something like that work.

 

If not, SkyRe - Races, Dunmer has some new abilities, mostly spells, that take effect once HP is low enough.

(With spells I mean REAL spells, so those scripts should at least cover what you are trying to achieve)

 

Sorry that I can't help you directly, but I hope I was able to point you at right direction :thumbsup:

 

Avoid Death is a perk and I really don't want to add a perk due to possible conflicts with overhauls and all that stuff.

Thanks, I will check out SkyRe. :)

 

 

All that seems overly complicated.

 

Why not just add an ability to the race in the ck.

Set up your custom ability with a condition (on the spell not the magic effect) "GetActorValuePercent". That way the Magic Effect is only active when you want it to be.

If you want it to be more like a power (only usable once/day) you could do that as well with some scripting.

 

Yes, Bethesda makes things overly complicated. How would I go about setting a condition on an ability? I can only add them to magic effects, even in the Spell window.

Link to comment
Share on other sites

In the spell edit window, when you add a magic effect you can add conditions to each individual effect.

 

When you add conditions on the magic effect screen that magic effect will be "resisted" when the conditions are not met and the spell won't be applied at all. But if you add them on the spell screen (like in the pic) the spell will be applied and the effects work as a toggle. The effect will be applied when the conditions are met, and go away when they aren't (but the spell is still there so you can toggle back and forth for as long as the duration you set in the spell lasts).

 

EDIT: as far as that particular condition goes - in the pic I set it to 0.25 but you might need to set it to 25. I'm not sure if it returns a decimal or an actual percent.

 

Now if you want it to work like a power (one use per day/hour/whatever) you will need a bit of scripting, but less than what you've got up there probably.

Edited by cscottydont
Link to comment
Share on other sites

Heres what I tested.

 

It worked for me. When the player got below 25% he turned all ghosty and firey and when he got back above 25% the effect stopped and was no longer present on the spell menu.

 

EDIT: I'm not sure what exactly you're trying to accomplish though. Hit me with some more details and we'll see if we can get something working.

 

Just to be clear, this is for an ability. You can add castable spells with this method also, without using scripting.

Edited by cscottydont
Link to comment
Share on other sites

Okay, well maybe my CK was bugged when I first tried that or something, but I need something more complex than just being able to use it @ 25% and lower, anyway.

 

1) Player health reaches 25%

2) Power gets added + equipped.

3) Even if player health goes above 25% again, it should stay on if activated (that's scriptable), but what is much more important is that I want a timer on it so you can still use for like 10 seconds after your health had dropped below 25%. That is to avoid the player possibly being too late to activate it and simply because there are enough times where you could still need it even after you've healed some.

4) I need this script to work, because I am developing a system where you get notified you can obtain a new power at certain levels. An NPC will make the powers available to the player, but first I want it to work through an automated script before I add a vendor.

Link to comment
Share on other sites

If you're wanting to add a castable spell/power you'll need:

 

1.The spell you wish to add to the player.

2. An ability with an effect set up like we did above.

3.Magic Effect on the ability that adds a perk (through the "Perk to Apply" list)

4.Perk that adds your spell.

5.Perks can have Quest Stages, Abilities, or Entry Points - you want to choose Ability and then find your spell in the drop down list.

 

Now to add the once/day or whatever other functionality you'll need a small script.

This may seem more complicated than your original script idea, but I try to avoid lengthy constantly updating scripts whenever possible.

Link to comment
Share on other sites

I had actually decided to avoid perks, because I don't want to expand the original perk tree. The 'hidden' button on perk doesn't hide the perk, so I'm wondering whether the perk would show up in the perk tree. I want the system for the race to be invisible to the player. Also a constantly updating script isn't as bad as you think. The entire spell works on monitoring the player's health so whether it gets added through a perk or something else, it would need to update constantly anyway. It's not like it requires a huge amount of RAM and the script is very light.

 

I really believe it should be possible to implement my idea using only a hidden quest and a script (which is much less lengthy than with abilities, spells and perks), but I will try what is basically the "Avoid Death" perk idea as I'm starting to run short on time.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...