Removing active powerups from the player through DECORATE

Handy guides on how to do things, written by users for users.
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.

Removing active powerups from the player through DECORATE

Postby MephistoII » Sun Dec 03, 2017 2:55 am

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 allExpand view
////////
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 allExpand view
////////
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 allExpand view
tags

work. My apologies. If someone helps me getting them to work I'll clean up this post with them ASAP.
User avatar
MephistoII
Look at my eyes... you see blood? No? Damnit, that means I'm becoming crazy!
 
Joined: 23 Apr 2008
Location: Spain... *COUGH*

Re: Removing active powerups from the player through DECORAT

Postby Rachael » Tue Dec 05, 2017 4:42 am

You should be able to use [code] tags now.
User avatar
Rachael
Not all elves needs a stocking hat...
 
Joined: 13 Jan 2004


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest