Health Monitoring Script

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.
Locked
Dave_B
Posts: 54
Joined: Tue Jun 08, 2010 8:20 am

Health Monitoring Script

Post by Dave_B »

How would I go about writing a script that monitors your health constantly and displays a message when it gets to or below a certain point? I've spent hours trying to get something like this work and I'm completely frustrated. :x
disposable_username2
Posts: 168
Joined: Tue Mar 08, 2011 1:25 pm

Re: Health Monitoring Script

Post by disposable_username2 »

There's one in the "Call of Dooty" jokewad, for example.
Here's the relevant parts.
Regeneration:

Code: Select all

script 1 ENTER
{
    //Give player ID
    Thing_ChangeTID(0, 1337); //only works correctly in single player. See http://zdoom.org/wiki/PlayerNumber for method that works in MP. You'll have to modify script accordingly.
    
//level specific stuff was here    
    
    //Health Regeneration
    While(True)
    {
            //level-specific stuff removed
            //Constantly work while health is under 100
            While(GetActorProperty(1337,APROP_Health)<100 && GetActorProperty(1337,APROP_Health)>0)
            {
                //After each hit you take, wait for regeneration
                If(GetActorProperty(1337,APROP_Health)<health)
                {
                    ThingSound(1337,"SHLDDEPL",100);
                    Delay(175);
                    ThingSound(1337,"SHLDRCHR",100);
                }
                health = GetActorProperty(0, APROP_Health);
                SetActorProperty(1337, APROP_Health, health + 1);
                Delay(2);
            }

    Delay(1);
    }
}
And message:

Code: Select all

While(True) {
//removed level-specific stuff
    //If health drops below 100, tell player to take cover
    If(GetActorProperty(1337,APROP_Health)<100 && GetActorProperty(1337,APROP_Health)>0)
    {
        SetFont("BIGFONT");
        HudMessage(s:"You're hurt!  Take cover!"; HUDMSG_PLAIN, 100, CR_RED, 0.5, 0.2, 0.1);
    }
        
//removed level-specific stuff

    Delay(1);
    }
Dave_B
Posts: 54
Joined: Tue Jun 08, 2010 8:20 am

Re: Health Monitoring Script

Post by Dave_B »

Thanks for that. I'll see what I can do with it.
Dave_B
Posts: 54
Joined: Tue Jun 08, 2010 8:20 am

Re: Health Monitoring Script

Post by Dave_B »

To clarify what I'm trying to do, I'm trying to come up with a library script that monitors a player's health across all maps in a hub, then displays a message when the game is ended if the health remains above a percentage at all times during gameplay. Whenever the player's health falls below this percentage the message isn't displayed at the end.
User avatar
TheDarkArchon
Posts: 7656
Joined: Sat Aug 07, 2004 5:14 am
Location: Some cold place

Re: Health Monitoring Script

Post by TheDarkArchon »

You want something like this.

In each map the player will be in this hub, this needs to be in.

Code: Select all

//Sets up an integer that can be referenced across all maps
global int 1:youreshitandyouknowyouare;

script 1 ENTER
{
  
    //Loop while game is playing, always.
    While(True)
    {
         //If the players health drops below 50 at any point, note down that it has.
         //Use TID zero to refer to the activator. The player is always the activator of an ENTER script.
         if(GetActorProperty(0,APROP_Health)<50)        
         {
               youreshitandyouknowyouare = 1;
         }
    Delay(1);
    }
}
and then when the hub is done:

Code: Select all

global int 1:youreshitandyouknowyouare;

script 100 (void)
{
     //If the player hasn't been flagged as noted above, show the message
     if(!youreshitandyouknowyouare)
     {
          print(s:"Congratulations! You are not utterly hopeless in this game!");
     }
}
Last edited by TheDarkArchon on Wed Nov 23, 2011 1:26 am, edited 1 time in total.
Dave_B
Posts: 54
Joined: Tue Jun 08, 2010 8:20 am

Re: Health Monitoring Script

Post by Dave_B »

It worked! Thanks for that! :D
Locked

Return to “Editing (Archive)”