Jump to content

Help with script that adds health on level up(gains smaller than 1)


Recommended Posts

Edit: As per GamerRick's comment I managed to get things working.

 

 

So I am trying to write a script that changes how the game calculates health gain on level up and I got it mostly working. But I have run into some trouble regarding the handling of (leftover) health gains smaller than 1.
For reference this is my script

scn HealthPerLevel

Short HealthUpdate
int EnduranceHealthMod


begin menumode 1027

Set HealthUpdate to 1

end

begin gamemode

if HealthUpdate == 1 && player.getlevel <= 31

let EnduranceHealthMod := (player.getpermanentactorvalue Endurance * 0.5)

player.modav health EnduranceHealthMod
player.modav Health 2

if player.getpermanentactorvalue Endurance == 1 || 3 || 5 || 7 || 9 && player.getlevel == 1 || 3 || 5 || 7 || 9 || 11 || 13 || 15 || 17 || 19 || 21 || 23 || 25 || 27 || 29 || 31

player.modav Health 1



endif
endif


Set HealthUpdate to 0

end

Additional notes on the above. I have set fAVDHealthLevelMult to 0 under the settings tab to disable vanilla health gains, instead using my mod.

 

The game will round down any result, this means that if you have say 5 Endurance you will gain 4 Health a level rather than 4.5 per level or 9 over the course of 2 levels. However I would like to have the player actually gain that 9 health over the course of 2 levels in a 4+5 fashion as a work around to engine limitations.
To this end I have added a section that aims to address it through a level + endurance check however it does not seem to work right in game instead adding 1 extra hit point every level regardless of endurance and/or level. Removing this section will make my script work completely as intended, barring the engine limitation with odd numbered endurance stats.

 

I guess I am trying to check against too many variables which confuses the game and results in it deciding to always add that 1 extra health regardless of whether it passes the checks or not. But I am not sure if that's the problem or if I am doing something else wrong. So I would appreciate any help in figuring this out.

Edited by mysteriousman121
Link to comment
Share on other sites

Your problem is how you defined your variable as to "type".

 

An "integer" variable type cannot store a decimal value (fraction). Round numbers only (values after the decimal point are ignored/dropped).

 

You need to define it as a "float".

 

But your problem doesn't stop there. The "Health" value is one of the more complicated "ActorValues" with "pools" for "temporary", "permanent" and "damage" effects. Once you have determined which pool is supposed to get your result, you then have the problem that the "SetActorValue" function only works with "integers". You probably want to use the "DamageActorValue" function which will accept a "float" value but the result may not be precisely what you expect. And it only applies to the "temporary pool". For a "permanent" change you need to use "ModActorValue" which also only accepts "ints".

 

You have to live within the limits of the available functions. Not to say you can't get there from here, but it may take a more round-about route.

 

-Dubious-

Link to comment
Share on other sites

Your problem is how you defined your variable as to "type".

 

An "integer" variable type cannot store a decimal value (fraction). Round numbers only (values after the decimal point are ignored/dropped).

 

You need to define it as a "float".

 

But your problem doesn't stop there. The "Health" value is one of the more complicated "ActorValues" with "pools" for "temporary", "permanent" and "damage" effects. Once you have determined which pool is supposed to get your result, you then have the problem that the "SetActorValue" function only works with "integers". You probably want to use the "DamageActorValue" function which will accept a "float" value but the result may not be precisely what you expect. And it only applies to the "temporary pool". For a "permanent" change you need to use "ModActorValue" which also only accepts "ints".

 

You have to live within the limits of the available functions. Not to say you can't get there from here, but it may take a more round-about route.

 

-Dubious-

 

Thanks for the suggestion, but the use of a int rather than float isn't really that relevant here. Since as you explained yourself when I use modav(which I ultimately have to) I will need an int anyway.

The problem is that the engine doesn't seem to handle repeated OR(written as ||) conditions particularly well. As my testing reveals that if I greatly simplify the needed conditions to apply the 1 extra health, it will work as it should according to the script. But then it no longer does what I am intending to do here obviously.

 

To make myself clear what I mean here is an example script:

scn HealthPerLevel

Short HealthUpdate
int EnduranceHealthMod

begin menumode 1027

Set HealthUpdate to 1

end

begin gamemode

if HealthUpdate == 1 && player.getlevel <= 31

let EnduranceHealthMod := (player.getpermanentactorvalue Endurance * 0.5)

player.modav health EnduranceHealthMod
player.modav Health 2

if player.getpermanentactorvalue Endurance == 5 

player.modav Health 1

endif
endif

Set HealthUpdate to 0

end

This script will result in the following (rounded down) health increase on level up:

Health increase = ( Endurance * 50%) + 2

 

However if you were to have 5 Endurance it would be:

Health increase = (Endurance * 50%) + 2 + 1

 

The only change between this and my original script is that I outright removed the level requirement and removed the OR statement's from the endurance requirement for the additional + 1 health to be applied. Yet it works properly now when my original script didn't. Also just removing the level requirement wasn't enough to get it to work properly so it's not like that was the (only) problem either.

So my original problem still stands as even with a rewrite, as far as I can see I still am going to need to do some kind of check against odd numbered endurance values at some point and need it to execute properly.

Link to comment
Share on other sites

 

If you want to see if a number is odd:

if player.getpermanentactorvalue Endurance % 2 == 1

I feel like an idiot right now, but thank you very much by applying that to both Endurance and player level it actually works now.

I suppose that's 1 more lesson learned about scripting (for new vegas) something I am pretty clueless at I'l be honest.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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