Removing active powerups from the player through DECORATE

Handy guides on how to do things, written by users for users.

Moderators: GZDoom Developers, Raze Developers

Forum rules
Please don't start threads here asking for help. This forum is not for requesting guides, only for posting them. If you need help, the Editing forum is for you.
Post Reply
User avatar
MephistoII
Posts: 44
Joined: Wed Apr 23, 2008 3:34 pm
Location: Spain... *COUGH*

Removing active powerups from the player through DECORATE

Post by MephistoII »

Hi everybody!

So, I needed a way to remove/deactivate currently active custom powerups from the player in order to create a weapon that, upon using alt-fire, would make you invisible until you attacked. However, I didn't find any info on how to do that in google or these forums.
I managed to figure out how to do it through experimentation, and it's quite easy, actually!

We'll start by defining a custom powerup class (you can skip this step if you are going to use one of the built-in powerup classes like PowerInvisibility).
We'll inherit from the built in class PowerInvisibility for simplicity, through you probably can just extend the native Powerup class.

Code: Select all

////////
ACTOR PowerSpectreStealth : PowerInvisibility
{
  Powerup.Duration 0x7FFFFFFF
  Powerup.Strength 50
  Powerup.Mode "Fuzzy"
  Powerup.Color blue 0.25
}
////////
Note: USUALLY the powerup class name MUST start with the "Power" word if you want to give it to the player through a PowerupGiver (item pickup). If you want your powerup class to be named, say, "ImInvincible", you need to name your powerup class "PowerImInvincible".
This is necessary for the PowerupGiver to recognize your custom Powerup. Since here we'll give the powerup directly through decorate, we DON'T need to do that and we could just use "ImInvincible" as the class name, but I'll do it anyway just for consistency.

And then, the weapon to give and take the powerup. It'll give our custom powerup to the player when using alt-fire, and will remove it when using primary fire.
This could be done just as well in the player class or anywhere else with access to the player's inventory.

Code: Select all

////////
actor SpectreJaws : weapon
{
  /* Weapon properties */
  States
  {
    /* Deselect, Select, Ready, and other states */

    AltFire:
      DEMH A 0 A_GiveInventory ("PowerSpectreStealthPower",1)
/* By directly putting the powerup class in the player's inventory it'll be immediately activated, and we don't need to define a PowerupGiver. */

      DEMH A 0 A_PlaySoundEx ("demon/sight", "Weapon")
      DEMH A 0 A_TakeInventory ("SpectreMana",200)
      DEMH A 24
      goto ready

    Fire:
      DEMH A 0 A_TakeInventory ("PowerSpectreStealthPower", 0x7fffffff) 
/* Indeed, it's this stupid simple. Just remove the powerup class from the inventory and the effect will immediately end. 0x7fffffff used as the quantity to ensure every instance of the powerup is removed, but you could just remove 1 at a time if you're sure the player will have only 1. */

      DEMH A 8 A_PlaySoundEx ("demon/melee", "Weapon")
      DEMH A 8 A_CustomPunch (5)
      DEMH A 16
      DEMH A 8 A_ReFire
      Goto Ready
  }
}
////////
And that's it! When using alt-fire we'll get a weaker partial invisibility until we use the primary fire. Note that you'd probably want to take away the powerup in the deselect state too, to prevent carryover to other weapons.
If you don't need to define a custom powerup, you could just A_GiveInventory/A_TakeInventory ("PowerInvisibility", 1), or "PowerInvincible", or whatever you need.

P.S.: I can't seem to make the

Code: Select all

tags
work. My apologies. If someone helps me getting them to work I'll clean up this post with them ASAP.
User avatar
Rachael
Posts: 13530
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Removing active powerups from the player through DECORAT

Post by Rachael »

You should be able to use

Code: Select all

 tags now.
Post Reply

Return to “Tutorials”