Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

NPC Healing Script


Rastafariel
 Share

Recommended Posts

Ok, I don't know about you guys, but vanilla oblivion npc healing AI seems to suxxors.

So, I'm writing a script for actor healing (I'm sure there are many out there but I didn't see any =/)

This is it so far, for discussion (and apparantly the function getcurrenthealth does not actually work... so I'm looking for a workaround)

scn RasOperatingScript


ref me

short TH

short timer

short doonce


Begin GameMode


;identify Ras

set me to getself


;get total health when spawned

Set TH to me.getcurrenthealth


;if activator for healing when loosing health


;doonce loop

if doonce == 0

	if me.GetCurrentHealth != TH

		me.cast LL0RestoreHealthMajorLvl100 me

		set timer to timer + getsecondspast

		set doonce to 1

	endif

endif


if doonce == 1

	if timer == 10

		set doonce to 0

	endif

endif


End

Edited by InsanitySorrow
Placed code inside a code box :)
Link to comment
Share on other sites

TH is always going to be equal to current health. Might want to set that, and use a condition of some sort, so you are not resetting it every frame.

Oooooooh. Duh. =/

(Might be a moot point since getcurrenthealth doesnt seem to be a valid function even when Im modding with OBSE functions & CS.)

Link to comment
Share on other sites

Would a begin onload work like this?

scn RasOperatingScript


ref me

short TH ;Total Health

short timer

short doonce


Begin OnLoad


;identify Ras

set me to getself


;get total health when spawned

Set TH to me.getcurrenthealth


End


Begin GameMode

;if activator for healing when loosing health


;doonce loop

if doonce == 0

	if me.GetCurrentHealth != TH

		me.cast LL0RestoreHealthMajorLvl100 me

		set timer to timer + getsecondspast

		set doonce to 1

	endif

endif


if doonce == 1

	if timer == 10

		set doonce to 0

	endif

endif


End

P.S. .... Why oh why are my tabs not showing in this post so hard to read script...

OOH, code box - had no idea - TY IS =-)

Edited by Rastafariel
Link to comment
Share on other sites

Ok so the final iteration looks like this:

scn RasOperatingScript


ref me

short TH

float timer

short doonce

float health


Begin OnLoad


;identify Ras

set me to getself


;get total health when spawned

Set TH to me.getcurrenthealth


End


Begin GameMode

;if activator for healing when loosing health


;doonce loop

if doonce == 0

	if me.GetCurrentHealth != TH

		me.cast LL0RestoreHealthMajorLvl100 me

		set timer to timer + getsecondspassed

		set doonce to 1

	endif

endif


if doonce == 1

	if timer == 10

		set doonce to 0

	endif

endif


End

Edited by Rastafariel
Link to comment
Share on other sites

How is the script run? is it actually on the NPC's? Quest script? AoE spell?

on the NPC.

I just realized that even if this script works correctly, if the NPC is already spawned and wounded, it will not correct to max health because it will think its current health is max health. TES must have a getmaxhealth type of function... how could they not when maxhealth is derived from levels and endurance but you cant get it by endx2 cause end can change over level..... *pulls out hair*

____________

EDIT:

ooh ooh... I think I can use GetBaseActorValue health to solve this problem, but I still don't have a working script yet.

Edited by Rastafariel
Link to comment
Share on other sites

Could also try:

set TH to me.GetBaseActorValue Health

Gets the base value. I am only guessing that it gets the max value. Something to experiment with. Keep in mind, this does not take into account fortify effects, or, probably the opposite of those...... might want to check for those types of effects as well, or, you may find an npc stuck in an infinite loop.

Could also run the TH update on getcellchanged..... incase you pick up one of your companions a time after loading.

Link to comment
Share on other sites

this is the current version of the script I'm working on, but it's not activating when the NPC takes damage.

scn RasOperatingScript


ref me

short TH

float timer

short doonce

float health


Begin OnLoad


;identify Ras

set me to getself


;get total health when spawned

Set TH to me.GetBaseActorValue Health


End


Begin GameMode

;if activator for healing when loosing health


;doonce loop

if doonce == 0

	if me.GetCurrentHealth != TH

		me.cast DNBGRegenerate me

		set timer to timer + getSecondsPassed

		set doonce to 1

	endif

endif


if doonce == 1

	if timer >= 10

		set doonce to 0

		set timer to 0

	endif

endif


End

Edited by Rastafariel
Link to comment
Share on other sites

Could also try:

set TH to me.GetBaseActorValue Health

Gets the base value. I am only guessing that it gets the max value. Something to experiment with. Keep in mind, this does not take into account fortify effects, or, probably the opposite of those...... might want to check for those types of effects as well, or, you may find an npc stuck in an infinite loop.

Could also run the TH update on getcellchanged..... incase you pick up one of your companions a time after loading.

Thanks for the continued help HY!

Now that we have two seperate functions for health, I dont think we need the qualifyer anymore. I can just take the base and gethealthhcanged in one script... I think.... (I'm going to modify it below and try it out)

Link to comment
Share on other sites

Revised Script:


scn RasOperatingScript


ref me

short TH

float timer

short doonce

float health


Begin GameMode


;identify Ras

set me to getself


;get max health for comparison

Set TH to me.GetBaseActorValue Health


;set level to PC level -3

;some function to do that later



;if activator for healing when loosing health

;doonce loop

if doonce == 0

	if me.Getav health != TH

		me.cast DNBGRegenerate me

		set timer to timer + getSecondsPassed

		set doonce to 1

	endif

endif


if doonce == 1

	if timer >= 10

		set doonce to 0

		set timer to 0

	endif

endif


End

NOTES:

I'm now concerned that Toaster's Companion Script may be interfearing with this NPC script Im trying to run.... SO... I think I will disable Toaster's Mod for a bit to test this...

Well, I think this is a wash because getbaseav health returns the base health at L1, not the base max health of the actor

also getav health is the same as getcurrenthealth (except getav health works in the console so I think I'll use that in script)

Edited by Rastafariel
Link to comment
Share on other sites

Ok, how about a bit of a 'cheat' then?

Resethealth restores health to its maximum value. (according to the wiki) It would require a bit of dancing but.......

do an oncellchanged block that would

a. get current health, and store it as a variable

b. resethealth

c. set TH to current health.

d. set health back to original value (if it was different)

the rest of the script could then process.

Link to comment
Share on other sites

Ok, how about a bit of a 'cheat' then?

Resethealth restores health to its maximum value. (according to the wiki) It would require a bit of dancing but.......

do an oncellchanged block that would

a. get current health, and store it as a variable

b. resethealth

c. set TH to current health.

d. set health back to original value (if it was different)

the rest of the script could then process.

Interesting, I was thinking of trying EXACTLY that for my own Heal Companions spell, which seems to be having trouble remembering what people's max is, ...and was about to suggest Leo try it when i saw your post.

Link to comment
Share on other sites

Interesting, I was thinking of trying EXACTLY that for my own Heal Companions spell, which seems to be having trouble remembering what people's max is, ...and was about to suggest Leo try it when i saw your post.

Also, to add to the mix, Montana did one for Astrianna II that seems to work... awesomely.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...