Author Topic: Save and Load maxhealth  (Read 3044 times)

Can someone make a way to save and load your max health.

I tried to do it with the save variables mod, but it doesn't work. So if there was a way to make it work with the save and load variables mod that would be greatly appreciated.

Thanks in advance.

There's no way to do this in general because there's no one way to set max health individually per player.

Max health is a datablock field, the only way to adjust it individually per player is to package the damage functions to reduce incoming damage by a percent calculated by a "max health" variable, and this could be named anything.

But, if you give a link to the add-on you want it to work with, adding health saving is just adding one line of code (and executing script_player_persistence)

The best way is making a maxHealth mod that works like the datablocks, except you can mod your max health. Then you can make a variable that would be something like %player.health.

Here's a health detection mod I've made long ago for an existing health mod:
Code: (Support_HealthDetection.cs) [Select]
function Player::getHealth(%this)
{
if(!isObject(%this))
return -1;
if(%this.maxHealth > 0) //Does the player have custom health?
return %this.health;
return %this.getDatablock().maxDamage - %this.getDamageLevel(); //I guess not.
}

function Player::getMaxHealth(%this)
{
if(!isObject(%this))
return -1;
if(%this.maxHealth > 0)
return %this.maxHealth;
return %this.getDatablock().maxDamage;
}

This is useful for add-ons that currently use the %player.getDatablock().maxDamage which can break stuff if you use a health mod (which is why this code can work if you replace it)

There's no way to do this in general because there's no one way to set max health individually per player.

Max health is a datablock field, the only way to adjust it individually per player is to package the damage functions to reduce incoming damage by a percent calculated by a "max health" variable, and this could be named anything.

But, if you give a link to the add-on you want it to work with, adding health saving is just adding one line of code (and executing script_player_persistence)
wrong
you can simulate modifying max health by dividing/multiplying damage received to give the appearance of having that much health

obviously implementation to load save variables mod would be a pain and it would be better to be it's own addon however
« Last Edit: March 27, 2015, 11:20:16 PM by Swollow »

wrong
you can simulate modifying max health by dividing/multiplying damage received to give the appearance of having that much health
What are you talking about
That's exactly what I said
package the damage functions to reduce incoming damage by a percent
« Last Edit: March 27, 2015, 05:48:56 PM by Headcrab Zombie »

my bad i tend to not read enough, very sorry

There's no way to do this in general because there's no one way to set max health individually per player.

Max health is a datablock field, the only way to adjust it individually per player is to package the damage functions to reduce incoming damage by a percent calculated by a "max health" variable, and this could be named anything.

But, if you give a link to the add-on you want it to work with, adding health saving is just adding one line of code (and executing script_player_persistence)
Well i use this mod for setting max health, so if its as easy as you say would anyone mind doing it please?

The best way is making a maxHealth mod that works like the datablocks, except you can mod your max health. Then you can make a variable that would be something like %player.health.

Here's a health detection mod I've made long ago for an existing health mod:
Code: (Support_HealthDetection.cs) [Select]
function Player::getHealth(%this)
{
if(!isObject(%this))
return -1;
if(%this.maxHealth > 0) //Does the player have custom health?
return %this.health;
return %this.getDatablock().maxDamage - %this.getDamageLevel(); //I guess not.
}

function Player::getMaxHealth(%this)
{
if(!isObject(%this))
return -1;
if(%this.maxHealth > 0)
return %this.maxHealth;
return %this.getDatablock().maxDamage;
}

This is useful for add-ons that currently use the %player.getDatablock().maxDamage which can break stuff if you use a health mod (which is why this code can work if you replace it)

And I kinda understand what your saying, like I get what your saying about the max health mod and creating a variable from that mod, but i'm not sure how your Health Detection mod helps i'm confused on that.

It was just an example.

If you want a health mod I've made one long ago that has this file inside. If I remember it also modifies VCE stuff.
https://www.dropbox.com/s/mnctkr1p2uc8o0z/Zzerver_NewHealth.zip?dl=1
Note that this mod is pretty old to me and it might break some stuff.

It was just an example.

If you want a health mod I've made one long ago that has this file inside. If I remember it also modifies VCE stuff.
https://www.dropbox.com/s/mnctkr1p2uc8o0z/Zzerver_NewHealth.zip?dl=1
Note that this mod is pretty old to me and it might break some stuff.


Well i wouldn't want it to break stuff, what about the suggestion that headcrab made?

what about the suggestion that headcrab made?
You are able to create a health variable when the person becomes damaged (using Armor::Damage).
%player.getDatablock().maxDamage - %player.getDamageLevel() - Should automatically give you how much health they have left out of their max datablock health.

Well i use this mod for setting max health, so if its as easy as you say would anyone mind doing it please?
I just looked at the persistence script and I'm not sure how registerpersistencevar handles players
I don't know if you'd do RegisterPersistenceVar("maxHealth", false, ""); or RegisterPersistenceVar("player.maxHealth", false, ""); or what


It was just an example.

If you want a health mod I've made one long ago that has this file inside. If I remember it also modifies VCE stuff.
https://www.dropbox.com/s/mnctkr1p2uc8o0z/Zzerver_NewHealth.zip?dl=1
Note that this mod is pretty old to me and it might break some stuff.

Just an fyi
This addon is about three or so times as large as it needs to be
Player, AIPlayer, Vehicle, and WheeledVehicle all inherit from ShapeBase. So you only need to define the methods for ShapeBase. I see you did that for many methods, but you defined addhealth and sethealth (looks like exaclty the same code) individually for each class

You are able to create a health variable when the person becomes damaged (using Armor::Damage).
%player.getDatablock().maxDamage - %player.getDamageLevel() - Should automatically give you how much health they have left out of their max datablock health.

I'm sorry, but i'm so confused, like i'm not sure how I would use those codes, the Armor::Damage, or the %player.getDatablock() like i don't understand that.

I was just looking for a way to load a health varaible if they die or leave the game and come back. For example i have it setup where your checkpoints are saved and when you spawn at a checkpoint there is a zone for when players enter that zone, they load things such as..

onPlayerEnterZone - client - loadVariable - Client - Gold(Or whatever)

Now i was wondering if there was a way to do

onPlayerEnterZone - client - loadVariable - Player - maxHealth(Also save the variable as well.)

When I try it, it doesn't work.

It is possible as said if you make a vce variable for it.

Just an fyi
This addon is about three or so times as large as it needs to be
Player, AIPlayer, Vehicle, and WheeledVehicle all inherit from ShapeBase. So you only need to define the methods for ShapeBase. I see you did that for many methods, but you defined addhealth and sethealth (looks like exaclty the same code) individually for each class
The reason was because the health functions were broken somehow because the ShapeBase stuff didin't work with the mod.

It is possible as said if you make a vce variable for it.

Oh okay, well its not the default *maxHealth* variable because I tried that one and it doesn't work. Does that mean I have to create my own variable for the health? If so how would I do that?

My bad, I meant a player variable for vce that represents health, since you can't save the maxhealth or the health variable (well, you can but you can't load it)