Mimicing 'Fortify Health'

Post » Tue May 03, 2011 4:26 am

Hello!

I've just got into modding for Oblivion, and I'm working on an idea I've had floating around for a while. I've got most of it working correctly; unfortunately, the main part of it isn't.

I dug around around the construction set wiki to no avail. Here's my issue: I want to make what is pretty much the 'Fortify Health' spell, slightly modified so it can stack without making multiple copies of the effect. I've tried player.ModActorValue to try to raise the maximum health without touching the current health, but it does the opposite of what I want; it raises the current health instead and sets it above the maximum health. I also had an idea of how to get the current health and maximum health in separate variables, but the calculations for maximum health looked too crazy to work with what I had in mind.

In short, is there some function to modify the player's maximum health without changing their current health? I am also using OBSE 19, if there are any useful functions in there. Any help is appreciated.

Thanks,
Lazlow
User avatar
michael danso
 
Posts: 3492
Joined: Wed Jun 13, 2007 9:21 am

Post » Tue May 03, 2011 12:18 am

In short, is there some function to modify the player's maximum health without changing their current health? I am also using OBSE 19, if there are any useful functions in there. Any help is appreciated.

ModActorValue has http://cs.elderscrolls.com/constwiki/index.php/ModActorValue. Simply put, it changes a special modifier reserved for scripts, rather than the normal 'Max' modifier affected by fortify/drain. If you want to mimic a Fortify Health, you will need to use the newer ModAVMod function:
ModAVMod Health Max [amount]

Due to the way that stats are calculated in Oblivion, this will also affect the current health value. If you want the current health to remain the same, you will need to apply an equal but opposite amount of health damage:
ModAVMod Health Damage [-amount]

There is a caveat, though. The changes you make to the Damage modifier are permanent (as in they get saved in the savegame; the player will still be able to heal the damage away as usual). However, the changes to the Max modifier will be erased once the player saves and reloads the game. If you decide to take this scripted approach you will have to reapply the bonus after every game load.

Given that, I would recommend finding another way to accomplish what you want. For example, you might have a fortify health Ability that gets added and removed by your scripts as necessary. That would give you control over when and how the health is fortified, and with a minimum of drawbacks.
User avatar
Lauren Dale
 
Posts: 3491
Joined: Tue Jul 04, 2006 8:57 am

Post » Tue May 03, 2011 3:34 am

ModActorValue has http://cs.elderscrolls.com/constwiki/index.php/ModActorValue. Simply put, it changes a special modifier reserved for scripts, rather than the normal 'Max' modifier affected by fortify/drain. If you want to mimic a Fortify Health, you will need to use the newer ModAVMod function:
ModAVMod Health Max [amount]

Due to the way that stats are calculated in Oblivion, this will also affect the current health value. If you want the current health to remain the same, you will need to apply an equal but opposite amount of health damage:
ModAVMod Health Damage [-amount]

There is a caveat, though. The changes you make to the Damage modifier are permanent (as in they get saved in the savegame; the player will still be able to heal the damage away as usual). However, the changes to the Max modifier will be erased once the player saves and reloads the game. If you decide to take this scripted approach you will have to reapply the bonus after every game load.

Given that, I would recommend finding another way to accomplish what you want. For example, you might have a fortify health Ability that gets added and removed by your scripts as necessary. That would give you control over when and how the health is fortified, and with a minimum of drawbacks.


ModAVMod was exactly what I needed; thank you. I've got most of the issues addressed, like re-applying the fortify on game load, so I think it is smooth sailing from here.

Again, appreciated.
User avatar
Tina Tupou
 
Posts: 3487
Joined: Fri Mar 09, 2007 4:37 pm

Post » Tue May 03, 2011 7:27 am

Unsurprisingly, because I said that everything would be fine, it all came crashing down and I can't see what the problem is. I scrapped the mechanic for keeping the health as it is, since it was making things unnecessarily difficult. Here is my script:

scn CTLCharmHealth1Scriptshort CTLCharmHealth1Countbegin OnAdd Player	if ( CTLCharmHealth1Count == 0 )		PrintToConsole "Running script for first charm pick-up."		player.ModAVMod Health Max 5		player.AddSpell CTLCharmHealth1Ability		set CTLCharmHealth1Count to 1	else		PrintToConsole "Running script for non-first charm pick-up."		player.ModAVMod Health Max 5		set CTLCharmHealth1Count to (CTLCharmHealth1Count + 1)		PrintToConsole "%.0f charms." CTLCharmHealth1Count	endifendbegin OnDrop Player	if ( CTLCharmHealth1Count == 1 )		PrintToConsole "Running script for dropping the last charm."		player.ModAVMod Health Max -5		player.RemoveSpell CTLCharmHealth1Ability		set CTLCharmHealth1Count to 0	else		PrintToConsole "Running script for dropping non-last charm."		player.ModAVMod Health Max -5		set CTLCharmHealth1Count to (CTLCharmHealth1Count - 1)		PrintToConsole "%.0f charms." CTLCharmHealth1Count	endifend


When debugging ingame, I noticed that each time I picked up another of the item, it would print out "Running script for first charm pick-up" as if it was the first one in my inventory... it isn't. I can't tell what's wrong here; shouldn't the variable be updating and the next time the item is picked up, skip to the else portion of it?
User avatar
Kerri Lee
 
Posts: 3404
Joined: Sun Feb 25, 2007 9:37 pm

Post » Mon May 02, 2011 8:50 pm

I'm assuming that you attached that script to your token item, and that you add a new token item each time your fortify mechanic is activated. If that's the case, then each individual token in the player's inventory has it's own copy of the local script variables. If you want a "global" variable that gets shared by all of the tokens, you will need to create a http://cs.elderscrolls.com/constwiki/index.php/Quest_scripts to hold that variable. Alternatively, you might just use the number of tokens in the player's inventory using the GetItemCount function.
User avatar
Jenna Fields
 
Posts: 3396
Joined: Mon Dec 11, 2006 11:36 am

Post » Mon May 02, 2011 10:19 pm

I'm assuming that you attached that script to your token item, and that you add a new token item each time your fortify mechanic is activated. If that's the case, then each individual token in the player's inventory has it's own copy of the local script variables. If you want a "global" variable that gets shared by all of the tokens, you will need to create a http://cs.elderscrolls.com/constwiki/index.php/Quest_scripts to hold that variable. Alternatively, you might just use the number of tokens in the player's inventory using the GetItemCount function.


Fantastic; GetItemCount worked.

And I hope saying that won't mess something else up.

On another note, while everything else is working fine, something very... odd is happening. After picking up at least three of them, I seem to be unable to drop them. The oblivion icon appears in the top left as if it's about to tell me a message, but nothing appears. I can't drop most other items either, but some drop normally.

At first I thought this was an issue with the weight of the charms, but after I lowered the weight to 0.1, the problem still persisted.

I don't think this is a problem with the script, is it?

scn CTLCharmHealth1Scriptshort CharmCountbegin OnAdd Player	set CharmCount to ( player.GetItemCount CTLCharmHealth1Item )	if ( CharmCount == 1 )		player.ModAVMod Health Max 5		player.AddSpell CTLCharmHealth1Ability	else		player.ModAVMod Health Max 5	endifendbegin OnDrop Player	set CharmCount to ( player.GetItemCount CTLCharmHealth1Item )	if ( CharmCount == 0 )		if player.GetActorValue Health < 5			player.ForceActorValue Health 6			player.ModAVMod Health Max -5		else			player.ModAVMod Health Max -5		endif		player.RemoveSpell CTLCharmHealth1Ability		set CharmCount to 0	else		if player.GetActorValue Health < 5			player.ForceActorValue Health 6			player.ModAVMod Health Max -5		else			player.ModAVMod Health Max -5		endif	endifend

User avatar
Mrs shelly Sugarplum
 
Posts: 3440
Joined: Thu Jun 15, 2006 2:16 am

Post » Mon May 02, 2011 8:45 pm

Sorry for the bump, but I just want to report that I have the script working perfectly now.

I would like to proclaim my love for OBSE for making scripting so much easier.

(Also, that issue was resolved by starting the script over from scratch, strangely enough...)
User avatar
celebrity
 
Posts: 3522
Joined: Mon Jul 02, 2007 12:53 pm


Return to IV - Oblivion