Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
HenKonen

Printing the air supply while underwater

Recommended Posts

Hi!

I was wondering, does anyone know how to make the air supply of a player show on the screen while underwater? I thought it would be cool to let the player know how much time he has got before starting to take drowning damage.

To my luck, I found a page in Zdoom wiki with a pretty neat example script, but trying to use it, something went wrong with me. When compiling the script, I get a error message that function Getairsupply is not defined. I'm using Zdoom 2.5.

Has anyone stumbled upon the same problem?

Share this post


Link to post

Update your ACC, since it's the one program that is complaining. While you're there, you can get an updated ACS pack as well.

Share this post


Link to post

Okay, I got the basic form of the code to work, but I tried to modify the script a bit by changing the color of the font to light blue and change the place of the text. I can't get the Getairsupply script to work with Hudmessages though. All that happens with this script is that upon diving into the pool of water the number 196 is printed on the screen until the player starts to drown, changing the text to "You'd better go up for air!"

How come changing the print type from print to hudmessage screws up the getairsupply script? I'm clueless. Help, anyone?

int print_air[8];

script 188 (void)
{
  print_air[PlayerNumber()]++;
  print_air[PlayerNumber()] %= 2;
  while (print_air[PlayerNumber()])
  {
    if (GetAirSupply(PlayerNumber()) > 0)
      hudmessage(i:"GetAirSupply(PlayerNumber()) / 35";HUDMSG_plain, 5, CR_Lightblue, 0.5, 0.5, 0);
    else
      hudmessage(s:"You'd better go up for air!";HUDMSG_plain, 5, CR_Lightblue, 0.5, 0.5, 0);
      
    delay(1);
  }
}

Share this post


Link to post

In ACS, all variables are actually internally represented as integers. Strings cheat. There's a string table containing all the strings from the BEHAVIOR lump, and the string variable are just an index to that string.

So if you have a script like

script 1 ENTER
{
    Print(s:"Hello World!");
}
The compiler will see it a bit like this:
stringtable[0] = "Hello World!";
script 1 ENTER
{
    Print(s:0);
}
(Don't try to compile that code, it wouldn't work. It's just for illustration.)

Anyway, let's take a look at your script. The lesson to be learned here is that every string is also an integer value.
int print_air[8];

script 188 (void)
{
  print_air[PlayerNumber()]++;
  print_air[PlayerNumber()] %= 2;
  while (print_air[PlayerNumber()])
  {
    if (GetAirSupply(PlayerNumber()) > 0)
      hudmessage(i:"GetAirSupply(PlayerNumber()) / 35";HUDMSG_plain, 5, CR_Lightblue, 0.5, 0.5, 0);
    else
      hudmessage(s:"You'd better go up for air!";HUDMSG_plain, 5, CR_Lightblue, 0.5, 0.5, 0);
      
    delay(1);
  }
}
See the problem? Let's zoom on it:
      hudmessage(i:"GetAirSupply(PlayerNumber()) / 35";HUDMSG_plain, 5, CR_Lightblue, 0.5, 0.5, 0);
Righty. You're telling it to print the string "GetAirSupply(PlayerNumber()) / 35" as an int, which it is perfectly capable to do since a string is an int. In your case, it yields 196 because that's the index of this string in the string table.

Since you put it between quotes, it is taken as a string (not as an instruction), and since you use the i: qualifier, it is displayed as an int.

Share this post


Link to post

Okay, I'm trying to understand.

So if I want the message to be printed to be a sum of a math operation it cannot be "written as a script"?

And Btw, I got it to work! Thanks :)

Share this post


Link to post

A slightly unrelated question.

I'm trying to have the air supply not displayed when the player has a nodrown powerup in his inventory. I tried looking in the Zdoom wiki but couldn't find a solution to this one. Anyway, here's the code:

int print_air[8];

script 184 (void)
{
  print_air[PlayerNumber()]++;
  print_air[PlayerNumber()] %= 2;
  while (print_air[PlayerNumber()])
  {
    if (GetAirSupply(PlayerNumber()) > 0)
    {SetFont("BIGFONT");
      hudmessage(i:(GetAirSupply(PlayerNumber()) +34) / 35;HUDMSG_plain,5,CR_lightblue,0.02,0.91,0);}
    if (checkinventory("powernodrown"))
    {SetFont("BIGFONT");
    hudmessage(s:"Safe";HUDMSG_plain,5,CR_white,0.02,0.91,0);}
    else
     {SetFont("BIGFONT");
      hudmessage(s:"0";HUDMSG_PLAIN,5,CR_lightblue,0.02,0.93,0);}
      
    delay(1);
  }
}
I added the second "if" line to check the player's inventory for that item and print out text "safe" when he has the powerup is in the inventory. However, when testing the map, the air supply shows 0 whenever player is in water without the powerup.

Share this post


Link to post

Two potential sources of problem:

1. If you type the command "printinv" in the console while testing your map, do you actually have a powernodrown in your inventory?

2. Is the player really the activator of the script? It's a void script, so how is it triggered?

Share this post


Link to post
Gez said:

Two potential sources of problem:

1. If you type the command "printinv" in the console while testing your map, do you actually have a powernodrown in your inventory?

2. Is the player really the activator of the script? It's a void script, so how is it triggered?


Yes, player does have the powernodrown in his inventory and the script is triggered by the "eyes go below fake floor" thing in the deep water sector.

Share this post


Link to post

int print_air[8];

script 184 (void)
{
  print_air[PlayerNumber()]++;
  print_air[PlayerNumber()] %= 2;
  while (print_air[PlayerNumber()])
  {
    if (checkinventory("powernodrown")) // The Rebreather by Captain Toenail
    {SetFont("BIGFONT"); // http://www.realm667.com/index.php?option=com_docman&task=doc_download&gid=482&Itemid=
    hudmessage(s:"Rebreather\nUtilized";HUDMSG_plain,5,CR_white,0.01,0.9,0);}
    else
    {
    if (GetAirSupply(PlayerNumber()) > 0)
    {SetFont("BIGFONT");
      hudmessage(i:(GetAirSupply(PlayerNumber()) +34) / 35;HUDMSG_plain,5,CR_lightblue,0.02,0.9,0);}
    else
     {SetFont("BIGFONT");
      hudmessage(s:"0";HUDMSG_PLAIN,5,CR_lightblue,0.02,0.9,0);}
    }
    
    delay(1);
  }
}
I managed to make a fairly functional script, feel free to use it if you're looking for a similar effect as I was. When the player has the rebreather powerup in his possession, the script prints the text "Rebreather Utilized" in the low-eft corner above your health and armor meters when using screen size 11. Otherwise it just prints out the air supply in seconds. When the player starts drowning, the counter just stays at zero without any additional messages.

The air supply number stays in the lower-left corner until the end of the level, so this is a useful script for levels with lots of underwater sections. In a level with only one small pond to dive into it might be a bit awkward, though. Set this script to be executed by the "eyes go below surface" -thing in the deep water sector.

I feel so great about myself for getting this to work :D

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×