regenerating health up to a certain point

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
skeletronmk666
Posts: 21
Joined: Sun Dec 06, 2020 9:53 pm

regenerating health up to a certain point

Post by skeletronmk666 »

Hi Im very new to Zscript and im trying to make an IF statement and an Until statment that gives a specific playerclass a custom health item untill he reaches 30 health

Code: Select all

class LiquidMetalHealth : custominventory {
DEFAULT{
+COUNTITEM;
+INVENTORY.ALWAYSPICKUP;
}
states{
 Pickup:
    TNT1 A 0{
                if (health < 30)
                {
                 A_giveinventory("HealthReginT1000");
				 until(health == 30);
                }
            }
        loop;
	  }
}
here is code for the custom inventory, the if and until statment

Code: Select all

class HealthReginT1000 : health{
Default
	{
Inventory.Amount 1;
Inventory.Maxamount 30;
 +INVENTORY.ALWAYSPICKUP;
	}
}
and here is code for the health item it'self

it doesn't seem to be working at all, it runs, but does nothing :?: :?: :?:
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: regenerating health up to a certain point

Post by Dan_The_Noob »

are you giving the class the item? can't see the class code.

-edit- the "LiquidMetalHealth" item, i mean.
User avatar
skeletronmk666
Posts: 21
Joined: Sun Dec 06, 2020 9:53 pm

Re: regenerating health up to a certain point

Post by skeletronmk666 »

Code: Select all

Player.StartItem "Class2Inv"
  Player.CrouchSprite "PLYC"
  Player.StartItem "FastPistol"
  Player.StartItem "T1000SWORD"
  Player.StartItem"HandSpear"
  Player.StartItem"LiquidMetal"
  Player.StartItem"LiquidMetalHealth"
  Player.StartItem "Clip", 50
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: regenerating health up to a certain point

Post by Dan_The_Noob »

maybe try change "class" to "actor" on LiquidMetalHealth?
everything else seems like it makes sense to me.

and maybe add a checkinventory for "health" somewhere?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: regenerating health up to a certain point

Post by Player701 »

If you want to add this ability to a specific player class, then place the following code in your player class definition:

Code: Select all

override void Tick()
{
    Super.Tick();

    let plr = player;

    // Check for dummy players/voodoo dolls
    if (plr == null || plr.mo != self)
    {
        return;
    }

    if (plr.Health > 0 && plr.Health < 30)
    {
        plr.Health++;
    }
}
This will give the player 1 health up to 30 every tick, unless they're dead (the player can still be killed if the damage received is greater than or equal to their current health). Replace "plr.Health++" with "plr.Health = 30" if you want to give the health immediately instead of gradually. You do not need any inventory items here.
Last edited by Player701 on Mon Dec 07, 2020 4:19 am, edited 1 time in total.
User avatar
Misery
Posts: 158
Joined: Sun Nov 04, 2018 4:57 pm

Re: regenerating health up to a certain point

Post by Misery »

Dan_The_Noob wrote:maybe try change "class" to "actor" on LiquidMetalHealth?
everything else seems like it makes sense to me.
Zscript recognizes Class, not Actor.
User avatar
skeletronmk666
Posts: 21
Joined: Sun Dec 06, 2020 9:53 pm

Re: regenerating health up to a certain point

Post by skeletronmk666 »

excellent! this is almost perfect, how do i make him regin slower? add delay somewhere? aslo thank you SOOO much i was trying to impliment this for hours with no progress made :D
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: regenerating health up to a certain point

Post by Player701 »

You can use the actor's own age in ticks, via GetAge(), or Level.maptime as a counter, and base the decision whether to add health or not on the value of that counter. For example, if you want to add health every second, do it each time when the counter divides evenly by GameTicRate - its value is equal to the amount of tics in one second.

Code: Select all

if (plr.Health > 0 && plr.Health < 30 && GetAge() % GameTicRate == 0)
{
    plr.Health++;
}
To add health every 2nd second, replace GameTicRate with (GameTicRate * 2) (with parentheses). Every half second is (GameTicRate / 2), although it will actually be slightly faster than that because the current tic rate in GZDoom is 35 tics per second, an odd number. If you would like more precise adjustment, simply replace GameTicRate with some integer constant (say, 10) and tweak it until you find a suitable enough regeneration rate. Reducing the value will speed it up, while increasing the value will slow it down.
Blue Shadow
Posts: 5043
Joined: Sun Nov 14, 2010 12:59 am

Re: regenerating health up to a certain point

Post by Blue Shadow »

Player701 wrote:

Code: Select all

    if (plr.Health > 0 && plr.Health < 30)
    {
        plr.Health++;
    }
self.health should be updated as well to keep it in-sync with plr.health.

Alternatively, one can save themselves the trouble and use [wiki]GiveBody[/wiki].
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: regenerating health up to a certain point

Post by Player701 »

Hmm. Thought it was synced automatically, guess I was wrong. Yeah, then, either add health++; or call GiveBody(1).
User avatar
skeletronmk666
Posts: 21
Joined: Sun Dec 06, 2020 9:53 pm

Re: regenerating health up to a certain point

Post by skeletronmk666 »

how would i implement givebody?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: regenerating health up to a certain point

Post by Player701 »

You don't have to, it's already implemented in GZDoom. Just replace "plr.Health++" with "GiveBody(1)" in your code.
Post Reply

Return to “Scripting”