Setting MaxHealth & MaxArmor for Custom Player Class?

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Setting MaxHealth & MaxArmor for Custom Player Class?

Post by ReX »

Right, here's what I want to do:
  • 1. Create a custom player <Done>
    2. Give the player a maximum health of 100, and do not allow the use of health via a script or custom health items if the player is at 100 health.
    3. Give the player a maximum armor of 100, and do not allow the use of armor via a script or custom armor items if the player is at 100 armor.
Here's what is happening:
  • 1. When the player is at 100 health and uses a script that delivers health, the device to continues to deliver the health but the player's health does not go up past 100. In other words, the health from the device is being "wasted".
    2. When the player is at 100 armor and uses a script that delivers armor, the device to continues to deliver armor, thereby increasing the armor past 100.
    3. When the player is at 100 armor and picks up an armor item (similar to an armor bonus), the extra armor is not delivered but the item has been used up (i.e., wasted). Here is the definition of the item:
    Spoiler:
Here's what I've found in my researches:
  • 1. It sounds as if player health could be increased past maxhealth using health delivered via a script or by a custom health item. Refer to the wiki, which reads:
    player.maxhealth value
    Default is 100.
    The maximum health reachable by using *normal* health items.
    2. It sounds as if it may not be possible to limit the maximum armor possible. Refer to this post:
    "The armor you can't change. Period."
I know that I can prevent the player from acquiring additional health or armor that are delivered through scripts by checking for the player's health/armor inventory. I'd still need to know how to do this for health/armor pickups. However, I'd rather accomplish my objectives via the player's DECORATE definition, if it is possible.
User avatar
Ryan Cordell
Posts: 4349
Joined: Sun Feb 06, 2005 6:39 am
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)
Location: Capital of Explodistan

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by Ryan Cordell »

If I understand you right, you pretty much want to go for the "If you already got <THIS> type of health/armor, do not pick lesser or go beyond", right? I think I already dabbled with the same problem as you have then. Take a look here.
However, I'm not sure how I'd apply this to a particular player class. :(
Spoiler:
And so on. Boy, did I hate this system before I found the really simple solution, thanks to Apothem. :mrgreen:
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by ReX »

Blade Nightflame wrote:If I understand you right, you pretty much want to go for the "If you already got <THIS> type of health/armor, do not pick lesser or go beyond", right? I think I already dabbled with the same problem as you have then. Take a look here.
However, I'm not sure how I'd apply this to a particular player class. :(

Code: Select all

And so on. Boy, did I hate this system before I found the really simple solution, thanks to Apothem. :mrgreen:[/quote]
Actually, my case seems to be simpler than yours:
[list]1. I have only one type of "armor" in the traditional sense (the HEV Suit, not counting the HEVBattery).
2. Once that is picked up, the only way to add armor is by using an electrical charging device on a wall (via a script), or an HEVBattery (pickup item).
3. The charging device provides armor in 1 unit increments, up to a maximum of 50 per device.
4. The HEVBattery provides a one-time boost in armor by 15 units. Once that is used up, it's removed from the game, like any other pickup item. All of the armor in this item is used up, even if the player has 85 to 99 armor points. In other words, say the player has 95% armor remaining and picks up the HEVBattery. The player's armor should only increase to 100%, but in my case it goes up to 110%.[/list]
I think I may know why the HEVBattery provides armor beyond 100% - I have defined it as a BasicArmorBonus. I will need to define it like a regular armor item (e.g., green armor, but with only 15% armor provided). [b][color=#FF0000]I still need a solution to the problem with scripted armor being able to go above 100%.[/color][/b]

The healing is very similar to that in DooM, except for the healing option that is delivered via a script:
[list]1. Healing is delivered by a device on a wall (via a script), or a MedKit (pickup item).
2. The charging device provides health in 1 unit increments, up to a maximum of 50 per device.
3. The MedKit provides a one-time boost in health by 15 units, but otherwise works just like DooM's StimPack (i.e., it only provides healing up to 100%).[/list]

Btw, what is the solution Apotherm offered. Is that in the definition you posted in this thread?
User avatar
Ryan Cordell
Posts: 4349
Joined: Sun Feb 06, 2005 6:39 am
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)
Location: Capital of Explodistan

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by Ryan Cordell »

Yeah, the solution is what I posted. Sorry if I wasn't helpful. D=
User avatar
Project Shadowcat
Posts: 9369
Joined: Thu Jul 14, 2005 8:33 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: Blacksburg, SC USA
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by Project Shadowcat »

Regarding the HEV Battery, you can add -ALWAYSPICKUP (note the hyphen) and if you're at 100, it won't pick up.

As for the script, for each "use", simply check the activator's armor rating.

if (CheckInventory("[ArmorType]") < 100)
{
GiveInventory("[ArmorType]", 1);
[go on...]
}
else
{
[do nothing]
}
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by ReX »

Blade and Dark Fox, let me try what you guys have suggested and I'll let you know how it goes. Thanks very much.
User avatar
Apothem
Posts: 2070
Joined: Sat Nov 29, 2003 7:13 pm
Location: Performing open heart surgery on an ACS compiler.

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by Apothem »

I believe the solution I came up with for my shielding system was to have one armor type for the actual shield, and then another for shield(armor) bonuses. If you use two different armors for the same effect, it should look just fine. Think about it, in the original game, the armor bonuses just simply gave you +1 armor, regardless of which one you're using. So all you have to do is make an armor bonus for your armors that has the max amount you want in it. Or, well, that's how I got it to work...
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by ReX »

I tried the solutions suggested above. The problem persists in the scripted health and armor delivery. Here is an example:

Each MedicStation needs to count down from 50, in 10-unit increments. Here's what I tried to do:

Code: Select all

int healthuse;
script 3 (void)
{
	{
		healthuse++;
		if (healthuse < 6 && GetActorProperty(0,APROP_Health)<100)

		{HealThing(10);
		}

		if (healthuse == 5)

		setlinetexture(2, SIDE_FRONT, TEXTURE_TOP, "XMEDIC02");
	}
}
In other words, while healthuse is not greater than 5 uses AND while the player has less than 100 health, the device is supposed to give 10 health. As soon as one or the other conditions becomes false (i.e., the device has been used 5 times OR player health reaches 100) the device stops giving health.

Unfortunately, even with this modification the device continues to give health (i.e., be used/wasted). The same issue would likely be the case for the armor script too.

I notice that Dark Fox's script had an "else" in there, but mine does not. Would this actually make a difference? I'm off to try it now.
carlcyber
Posts: 163
Joined: Thu Jan 27, 2005 1:04 am

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by carlcyber »

I can't see the problem, but I still write one from what I've understood from your script.

If HealThing automatically detects the health of the player and will not exceed the health more than 100, the script can be simplified as

Code: Select all

int healthuse;
script 3 (void)
{
    if(healthuse < 5)
    {
        HealThing(10);

        if(++healthuse == 5)
        {
            setlinetexture(2, SIDE_FRONT, TEXTURE_TOP, "XMEDIC02");
        }
    }
}   
If I am guessing wrong, then try this

Code: Select all

int healthuse;
script 3 (void)
{
    if(healthuse < 5)
    {
        int ph = GetActorProperty(0, APROP_Health);

        if(ph <= 90) HealThing(10);
        else         HealThing(100 - ph);

        if(++healthuse == 5)
        {
            setlinetexture(2, SIDE_FRONT, TEXTURE_TOP, "XMEDIC02");
        }
    }
}   
You can print some debug information like Print(s:"script 3, healthuse = ", d:healthuse); to see what's happening in your script.
ReX wrote:I notice that Dark Fox's script had an "else" in there, but mine does not. Would this actually make a difference?
He leaves a space for you to do more things when something is already full. (ex: Printing "Your armor is full" message.) It deosn't affect the result.
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by ReX »

carlcyber wrote:... try this

Code: Select all

int healthuse;
script 3 (void)
{
    if(healthuse < 5)
    {
        int ph = GetActorProperty(0, APROP_Health);

        if(ph <= 90) HealThing(10);
        else         HealThing(100 - ph);

        if(++healthuse == 5)
        {
            setlinetexture(2, SIDE_FRONT, TEXTURE_TOP, "XMEDIC02");
        }
    }
}   
I tried this too, and it doesn't change anything. There's one thing I neglected to mention, and I wonder if that might have anything to do with the problem (although I'm guessing not). The Medic Station is a 3D construct, with the front face (i.e., line ID 2, in the example above) "delivering" the health. I will also try this on a non-3D surface.
carlcyber
Posts: 163
Joined: Thu Jan 27, 2005 1:04 am

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by carlcyber »

Have you tried printing some debug information to make sure healthuse behaves as you want? Or this problem is caused by preceding steps that leads this part of script to behave unexpected?
User avatar
Project Shadowcat
Posts: 9369
Joined: Thu Jul 14, 2005 8:33 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: Blacksburg, SC USA
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by Project Shadowcat »

Code: Select all

int healthuse;
script 3 (void)
{
if (GetActorProperty(0, APROP_Health) < 100) // If I remember the Health Station right, it checks health first BEFORE depleting.  Check health first.
    {
    healthuse++; // He has less than 100, let's keep going.
    if (healthuse < 6)
        {
        HealThing(10);
        }
    if (healthuse == 5) 
        {
        setlinetexture(2, SIDE_FRONT, TEXTURE_TOP, "XMEDIC02");
        }
    }
}
The if statements have been worked around a bit. While I knew what you wanted, I followed my own experience with the Health Station from Half-Life.

Oh, yeah. else is optional, though for playing sounds it'll be useful.
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by ReX »

Project Dark Fox wrote:

Code: Select all

New code for Medic Station
While I knew what you wanted, I followed my own experience with the Health Station from Half-Life.
Fox, I kiss the ground on which you walk. The code works perfectly.

Thanks to everyone else who contributed too.
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by ReX »

I got the solution for the MedicStation to work via the use of APROP_Health. Unfortunately, armor does not have the same feature, and I can't use that to check the player's armor inventory. I have tried using CheckInventory, and have discovered that I need to define an armor class that gives only one unit of armor at a time. Here is the current definition:

Code: Select all

int armoruse;
script 12 (void)
{ 
	if (CheckInventory("HEVCharge") < 100)
	{
		armoruse++;
		if (armoruse < 51)
		{	GiveInventory("HEVCharge", 1); 
		}

		if (armoruse == 50)
		{	setlinetexture (5, SIDE_FRONT, TEXTURE_TOP, "XARMOR02");
		}
	}
}
Every definition I've seen has included a Spawn state.
  • 1. So if I create a custom actor named HEVCharge, will I be able to create a DECORATE definition that does not require a Spawn state?
    2. If such a state is required, how would I prevent the sprite from being spawned each time the script is activated?
    3. If I can't prevent it from spawning, could I simply have a "dummy" sprite, consisting of a 1*1 pixel transparent graphic?
    4. Would using "stop" instead of "loop" work (in which case I can spawn a standard armor bonus, which won't appear in-game and won't do anything)?
User avatar
Project Shadowcat
Posts: 9369
Joined: Thu Jul 14, 2005 8:33 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: Blacksburg, SC USA
Contact:

Re: Setting MaxHealth & MaxArmor for Custom Player Class?

Post by Project Shadowcat »

ReX wrote:Fox, I kiss the ground on which you walk. The code works perfectly.
I sure as hell am not HotWax or Isle, but I try. :P

Anyway, I'm certain we can actually use the same approach with the armor charger - and I'm going to assume that each Charge from the station will be 10 again. Check this out:

Code: Select all

int armoruse;
script 12 (void)
{
   int armorspill;
   if (CheckInventory("HEVCharge") < 100) // Checkin' armor...
   {
      armoruse++;
      if (armoruse < 6)
      {   GiveInventory("HEVCharge", 10);
          if (CheckInventory("HEVCharge") > 100)
          {
             armorspill = CheckInventory("HEVCharge") - 100
             TakeInventory("HEVCharge", armorspill);
          }
      }

      if (armoruse == 5)
      {   setlinetexture (5, SIDE_FRONT, TEXTURE_TOP, "XARMOR02");
      }
   }
}
Before this code is applied, do you have an explicit inventory.maxamount set for said HEVCharge? If not it takes care of that...

EDIT: Whoops! Questions.
1. So if I create a custom actor named HEVCharge, will I be able to create a DECORATE definition that does not require a Spawn state?
2. If such a state is required, how would I prevent the sprite from being spawned each time the script is activated?
3. If I can't prevent it from spawning, could I simply have a "dummy" sprite, consisting of a 1*1 pixel transparent graphic?
4. Would using "stop" instead of "loop" work (in which case I can spawn a standard armor bonus, which won't appear in-game and won't do anything)?
1. No, but you can set the Spawn state to loop with a single TNT1 sprite.
2. If it is given to you, you will never see the sprite.
3. TNT1.
4. I'm not sure if it really matters, really, but if you're making sure that this is an item that is not supposed to be on the ground at any one time, then don't set up a DoomEd number if you want to put it on the map.
Locked

Return to “Editing (Archive)”