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
}
////////
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
}
}
////////
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