Making an infinite "hold time" hudmessage disappear at will

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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.

Making an infinite "hold time" hudmessage disappear at will

Postby Grey-Wolf » Sun Feb 10, 2019 8:06 pm

Here I am, flooding this section of the forum another day!

This time, I'm trying to create "data logs" items that tells the player about doom lore, monster strengths and weaknesses (they'll have them in the final mod), and other mod mechanics, in an immersive way. To do this, I made my first step in to the oh, so magic land of ACS.

What I managed to do until now, is this:

Here's my datalog prototype (still incomplete):
Spoiler:


And this is the script for it:
Spoiler:


So, everything works just fine, the .png picture for my pda shows and it stays forever, just lke I want.

My question is: how can I make it disappear when the player decides to do so? And even better: is there a way to show a "second page" of the datalog before preparing it to be closed?
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018

Re: Making an infinite "hold time" hudmessage disappear at w

Postby KeksDose » Mon Feb 11, 2019 10:26 am

You can stop a hudmessage by printing an empty message with the same id:

HudMessage(s:""; 0, 100, 0, 0, 0, 0);

A counter for the players to store how often they executed the script each would let you use the same inventory to also stop showing the picture. To also add more pages, you'd need:
1. Some way to address the pictures shown
2. Some way to do so in sequence

You could store the pictures in an array or use strparam with a strict naming scheme, but I'll use arrays. Then you'd implement some counter. A user variable seems mostly fitting, cuz the player is the script's activator, among many other benefits an inventory counter or a player count sized map array don't have.

You'd add user int user_page_index to the player, then the acs could look like so. You can also extend the same script to make more inventory for more monsters, which might be interesting. (Also didn't test but it looks good!)

Code: Select allExpand view
#define MAX_PAGES 2

script "IMPLOG" (void)
{
    str log_pages[MAX_PAGES] = { "pdaimp1", "pdaimp2" };
    int i = GetUserVariable(0, "user_page_index");
    
    
// Flipping pages
    if(<= i && i < MAX_PAGES)
    {
        SetFont(log_pages[i]);
        SetHudSize(640, 480, true);
        HudMessage(s:"a"; HUDMSG_PLAIN, 100, CR_UNTRANSLATED, 320.0, 240.0, 0);
        i++;
    }
    
    
// Done reading
    else
    
{
        HudMessage(s:""; 0, 100, 0, 0, 0, 0);
        i = 0;
    }
    
    SetUserVariable
(0, "user_page_index", i);
}

// When somebody exits while you're reading, the message gets cleared, so
// the page count should be reset, too.
script "Reset Page" enter
{
    SetUserVariable(0, "user_page_index", 0);
}


edit: saw a missing ,
User avatar
KeksDose
Hmhmhm!
 
Joined: 05 Jul 2007
Location: Cookie Hill, Germany

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Grey-Wolf » Mon Feb 11, 2019 4:24 pm

Oh wow, I didn't expect such a comprehensive anwer! Thanks you very much, I'll get to work right away!
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Grey-Wolf » Mon Feb 11, 2019 7:32 pm

I don't think it's working... When I use the inventory item a second time, it stay on the first page. Not even disappearing... it's just as I didn't change nothing from before... and yes I have two graphics called pdaimp1 and 2, and yes I recompiled the script. What could be going wrong?
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018

Re: Making an infinite "hold time" hudmessage disappear at w

Postby KeksDose » Tue Feb 12, 2019 5:07 am

The counter isn't going up, maybe cuz there isn't a place to save it. I kinda handwaved the "add a user int" part, so yea...

You'd replace the player class and add this line to it:

var int user_page_index;

If you didn't add a player class, here's how. (I thought you already did given the screenshot in the other thread looked kinda solid already x])
User avatar
KeksDose
Hmhmhm!
 
Joined: 05 Jul 2007
Location: Cookie Hill, Germany

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Grey-Wolf » Tue Feb 12, 2019 6:23 am

It works! I feel so dumb now, lol. Sorry if I made you lose your time, but I'm still new at doom modding, and even newer at ACS scripting.

I have one last question: what if I want to make the player appear with no weapon in his hands while reading? would something like r_drawplayersprites 0 work? And what to make the player unable to shoot? Or mybe I should just make a dummy weapon with no sprites and no firing mode that the player switches to while reading? What would be the "cleanest" solution?
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Blue Shadow » Tue Feb 12, 2019 9:37 am

Grey-Wolf wrote:Or mybe I should just make a dummy weapon with no sprites and no firing mode that the player switches to while reading?

That's how I'd go about doing it, personally, but there could be a better solution.

would something like r_drawplayersprites 0 work?

That's a user setting. You can't change that from a mod.

And what to make the player unable to shoot?

You could "freeze" the player while they're reading.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Grey-Wolf » Tue Feb 12, 2019 10:09 am

Hm, "prop_frozen" still lets the player fire his weapon, and prop_totallyfrozen doesn't let him use inventory items (so he can't flip pages or stop reading). So I think I'll go with the dummy weapon solution. Thanks for your advice!
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Grey-Wolf » Tue Feb 12, 2019 7:33 pm

Sorry, I hate to be "that guy", but I have to resurrect this topic again.
In the end, thanks to KeksDose's help, I managed to get the script working, and now I can make the player read the datalogs and switch between pages.

Another problem emerged (as always): I want the player to be unable to shoot or select any weapon while holding the datalogs in his hands (he would appear with 4 arms otherwise). So i took my chances with this:

Spoiler:


What I added are the str weapon = GetWeapon(); in the beginning, and the part after //Done reading. My idea was to check if the player is holding the blankweapon i made, and if he's NOT holding it, the datalog screen would disappear.
Thing is that when I use the datalog for the first time, the blankweapon is actually selected, so i can't shoot or see any weapon sprite (everything's good until here). But if I try to switch to another weapon WHILE reading, the switch is made normally, and I can see the weapon under the datalog screen (tha of course didn't disappear. So there's obviously something not working somewhere, but I don't know how I should solve it.

One last hint... please?
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018

Re: Making an infinite "hold time" hudmessage disappear at w

Postby KeksDose » Wed Feb 13, 2019 6:28 am

Don't worry about it. It's a problem with a lot of depth to it. We could try preventing deselecting the blank weapon whilst reading, but gzd doesn't offer a way to do this by itself, so we're going to get creative again.

Since you asked for hints, I won't spoil any implementation. :p

I set up the log script so that if the player's user_page_index is 0, he's not reading. A weapon can access its player's user variables, too, so you won't need to add any to the blank weapon. You can just use whatever the player already has. That should do the trick!
User avatar
KeksDose
Hmhmhm!
 
Joined: 05 Jul 2007
Location: Cookie Hill, Germany

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Grey-Wolf » Wed Feb 13, 2019 8:21 am

Here's what I did:
I restored your code as it was before I edited it, except for the sounds played and the Setweapon("BlankWeapon"); command. Then I went to one random weapon and I put TNT1 A 0 A_SetUserVar("user_page_index", 0) on the first line of its "Select" state.

Now, if while I'm reading I select the weapon, the weapon still pops up, but the datalog doesn't disappear: instead, it succesfully reset the page count, so if I use the datalog again, it will just re-view the first page, and then go forward from there until I used the datalog enough times to make it close.
I COULD create a separate script that print a blank hudmessage with the same ID of the datalog picture, and put it on the first line of every weapon's select state, But I'm pretty sure there's a more elegant and clean way to do this.

P.S.:I really appreciated the fact that you gave me a hint to make me think about the solution myself, after all I'm also here to learn and improve, but this will mean more headaches for you trying to bear with my ineptitude. :P
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018

Re: Making an infinite "hold time" hudmessage disappear at w

Postby KeksDose » Wed Feb 13, 2019 9:02 am

Nevermind that. I'm not royalty.

Aye, putting a "clear picture script" on every other weapon's select state is ridiculous. Maybe you could put one in the blank weapon's deselect, and that should be that. After all, this weapon only comes up when using the log, and if you keep it that way, great!
User avatar
KeksDose
Hmhmhm!
 
Joined: 05 Jul 2007
Location: Cookie Hill, Germany

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Grey-Wolf » Wed Feb 13, 2019 9:23 am

Worked like a charm. It was so simple...
Againt, thanks for your patience, now I can let you guys have a break from me for a while. And then, when I'll decide to write my wound/bleeding system, that's when bad stuff will happen... I know for sure it will. XD
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Blue Shadow » Wed Feb 13, 2019 10:10 am

As long as you don't ask questions out of laziness because you can't be bothered to to put in the effort to try and figure things out yourself, then it's fine, you can ask.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010

Re: Making an infinite "hold time" hudmessage disappear at w

Postby Grey-Wolf » Wed Feb 13, 2019 10:52 am

No of course, when I'll start with the bleeding system, I'll make sure to come here only after I've tried everything in my powers to make things work on my own. The only thing is that my "powers" are far from adequate.
User avatar
Grey-Wolf
 
Joined: 15 Jul 2018


Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests