Display a visual cue as long as an item is in inventory

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.

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
Kzer-Za
Posts: 522
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Display a visual cue as long as an item is in inventory

Post by Kzer-Za »

This is not an item that a player can use, so it is not (and shouldn't be) visible in the inventory bar. In fact, it's a "curse" with a limited lifetime, that deals some damage to the player when this lifetime runs out. I want the player to know that he is cursed (and possibly, how much time is left).

I have tried reading some info on how HUDs can be changed, but I can't understand it at all. Could someone please provide a simple example of how to do this:

Display an icon and/or some short text in the top right corner of the screen if there is an item of a certain type in the player's possession. If it is not too complicated, then maybe also check if there is more than 1 item of this type, and if yes, display another icon/text on the left of the first.

Pretty please? :)
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Display a visual cue as long as an item is in inventory

Post by Jarewill »

If it's a powerup-based item, you can add a Inventory.Icon property to it to have it display an image in the top right corner of the screen.

Otherwise you can check for an item with a ZScript status bar this way:

Code: Select all

Inventory item = CPlayer.mo.FindInventory("itemname");
If(item!=null)
{...}
And for checking the amount:

Code: Select all

If(item.amount>=5)
{...}
When it comes to checking for powerups and durations, look here.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Display a visual cue as long as an item is in inventory

Post by Player701 »

If your item is not a powerup and you want to use SBARINFO, you can use InInventory / DrawImage. SBARINFO probably has more examples available than the ZScript HUD API does. You can also find an SBARINFO definition of the Doom HUD in gzdoom.pk3: sbarinfo/doom.txt

ZScript has similar methods (DrawImage, DrawString) but the parameter order is different, and with DrawString you also have to create a HUDFont instance (see the link in the previous post for how to do that).

If you're basing your HUD off of an existing built-in HUD (for example, Doom's), add your extra code to the Draw override but don't forget to call BeginHUD() first, otherwise your extra stuff will jump around the screen depending on whether you're in status bar or fullscreen HUD mode. If the user has disabled the HUD (state == HUD_None), you should probably not draw anything. To prevent drawing on the automap, check for automapactive to prevent that.

Code: Select all

class MyHud : DoomStatusBar
{    
    override void Draw(int state, double TicFrac)
    {
        Super.Draw(state, TicFrac);

        // Do not draw on the automap and when the HUD is disabled
        if (state == HUD_None || automapactive)
        {
            return;
        }
        
        // Initialize the full-screen mode (otherwise the coordinate system will be relative to the status bar area)
        BeginHUD();

        // TODO: Your code here
    }
}
And do not forget to set the HUD class in your MAPINFO:

Code: Select all

gameinfo
{
    StatusBarClass = "MyHud"
}
Damn, I really wish I had the time to write a detailed tutorial on ZScript HUDs. I may not have enough expertise though, since I haven't fully explored the entire API yet.
Kzer-Za
Posts: 522
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Display a visual cue as long as an item is in inventory

Post by Kzer-Za »

Thanks for the info! I'll try to figure it out.
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Display a visual cue as long as an item is in inventory

Post by Dan_The_Noob »

here's a curse that slows the player by half

Code: Select all

actor HieroSlow : PowerupGiver 
{ 
  Inventory.PickupMessage "Your legs feel heavy." 
  Powerup.color Yellow 0.33 
  Inventory.MaxAmount 0 
  Powerup.Type Slow
  Powerup.Duration -10 
  +AutoActivate
  +Inventory.AlwaysPickup
  states 
  { 
  Spawn: 
    TNT1 A 1
    Fail
  } 
}

Code: Select all

Actor PowerSlow : PowerSpeed
{
  Speed 0.5
  Inventory.Icon "CURSH1"
}
it shows the "CURSH1" icon in the top corner until it wears off. you could probably go further with it, but it really is this simple to get a display.
Kzer-Za
Posts: 522
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Display a visual cue as long as an item is in inventory

Post by Kzer-Za »

Thanks! For now I'm going with this, later I'm gonna try adjusting the HUD to display the time left for the powerup.
Post Reply

Return to “Scripting”