Weapon-Specific Hud elements

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!)
User avatar
LolaHThicc
Posts: 12
Joined: Wed Dec 10, 2025 1:08 pm
Preferred Pronouns: She/Her

Weapon-Specific Hud elements

Post by LolaHThicc »

I'm working on a custom hud and it's beeing going fairly well, but once again i'm reaching a wall to my knowledge.

I would like for when a specific weapon is selected for a hud element showing an integer value used by the weapon to appear, and I would like for it to only appear while the weapon is selected.
I have a vuage idea of what i might need to do, maybe an if statement using CPlayer.ReadyWeapon, but i'm not sure. Any input as always is greatly appriciated!
User avatar
Average Raven Fan
Posts: 22
Joined: Sat Oct 05, 2024 12:00 am

Re: Weapon-Specific Hud elements

Post by Average Raven Fan »

Let's give this a go. I've copy-pasted the whole Doom status bar to a new class and added these two bits to it!

Code: Select all

		if(CPlayer.ReadyWeapon is "Shotgun")
		{
			DrawString(mAmountFont, FormatNumber(CPlayer.mo.CountInv("Cell")), (44, 181), DI_TEXT_ALIGN_RIGHT, Font.CR_LIGHTBLUE);
		}
This is added to DrawMainBar, right after drawing the current weapon's ammo...

Code: Select all

		if(CPlayer.ReadyWeapon is "Shotgun")
		{
			DrawString(mHUDFont, FormatNumber(CPlayer.mo.CountInv("Cell")), (-30, -40), DI_TEXT_ALIGN_RIGHT, Font.CR_LIGHTBLUE);
		}
And this one is added to DrawFullScreenStuff, also right after the ammo display code!

This shows the amount of cells you have in light blue whenever you have the single shotgun selected in Doom. Give it a spin and see if that's what you wanted!
User avatar
LolaHThicc
Posts: 12
Joined: Wed Dec 10, 2025 1:08 pm
Preferred Pronouns: She/Her

Re: Weapon-Specific Hud elements

Post by LolaHThicc »

Yes, it does exactly that, Thank you!

Now, i have an integer stored in the weapon; whats the procedure to passing that number along to the hud?
User avatar
Average Raven Fan
Posts: 22
Joined: Sat Oct 05, 2024 12:00 am

Re: Weapon-Specific Hud elements

Post by Average Raven Fan »

Code: Select all

class RNGShotgun : Shotgun
{
	int num;
	
	override void Tick()
	{
		num = random(0,255);
		Super.Tick();
	}
}
This is a shotgun with a variable. Just showing this so the code afterwards makes some sense!

Code: Select all

		if(CPlayer.ReadyWeapon is "RNGShotgun")
		{
			RNGShotgun weap = RNGShotgun(CPlayer.ReadyWeapon);
			DrawString(mHUDFont, FormatNumber(weap.num), (-30, -40), DI_TEXT_ALIGN_RIGHT, Font.CR_LIGHTBLUE);
		}
This is added to DrawFullScreenStuff just like the last example but it shows the value of the "num" variable in the RNGShotgun weapon instead of your current energy cells!
User avatar
LolaHThicc
Posts: 12
Joined: Wed Dec 10, 2025 1:08 pm
Preferred Pronouns: She/Her

Re: Weapon-Specific Hud elements

Post by LolaHThicc »

works perfectly! thanks again for the help! :)

Return to “Scripting”