How do I make powerup icons change based on duration?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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
juvenilemoogs
Posts: 4
Joined: Fri Jun 02, 2023 9:07 pm
Preferred Pronouns: He/Him

How do I make powerup icons change based on duration?

Post by juvenilemoogs »

I'm trying to code in this powerup for a project I'm working on, and I was thinking of making the little powerup icon and appears in the corner change based on the current duration, and the icon would change to a different sprite. Only problem is, I have no clue on how I would be able to detect the current duration of the powerup or change it's current icon. I was thinking of possibly using ACS to change it's properties but I think you can only really do that with monsters and such in a map.

Here's my code so far:

Code: Select all

Actor BuffBleeding : PowerProtection {
 DamageFactor "Normal", 2.0
 Inventory.Icon "BDNGA0"
}

Actor Bleeding : PowerupGiver {
 Inventory.PickupMessage "You are bleeding!"
 Inventory.MaxAmount 0
 Powerup.Type "BuffBleeding"
 Powerup.Duration 1050
 +INVENTORY.AUTOACTIVATE
}
Jarewill
 
 
Posts: 1641
Joined: Sun Jul 21, 2019 8:54 am

Re: How do I make powerup icons change based on duration?

Post by Jarewill »

It's not possible with DECORATE or ACS without the use of hacks.
However you can easily do this using ZScript, like so:

Code: Select all

Class TimeBlur : PowerInvisibility{
	Override void DoEffect(){
		Super.DoEffect();
		string ico = "PINS"; //This string will store the graphic you want to use as your icon
		If(EffectTics > (35*45)){ico = ico.."A0";} //If there are more than 45 seconds left, use PINSA0
		Else If(EffectTics > (35*30)){ico = ico.."B0";} //If there are between 30-45 seconds left, use PINSB0
		Else If(EffectTics > (35*15)){ico = ico.."C0";} //If there are between 15-30 seconds left, use PINSC0
		Else{ico = ico.."D0";} //If there are less than 15 seconds left, use PINSD0
		icon = TexMan.CheckForTexture(ico,TexMan.Type_Any); //Set the icon to the specified graphic
	}
}
User avatar
juvenilemoogs
Posts: 4
Joined: Fri Jun 02, 2023 9:07 pm
Preferred Pronouns: He/Him

Re: How do I make powerup icons change based on duration?

Post by juvenilemoogs »

Thanks for the help, man!

Return to “Scripting”