Keeping powerup across a hub (PERSISTENTPOWER and HUBPOWER isn't working??)

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
IvDraco830
Posts: 14
Joined: Mon Nov 05, 2018 8:43 pm
Location: Tangoland

Keeping powerup across a hub (PERSISTENTPOWER and HUBPOWER isn't working??)

Post by IvDraco830 »

Ok, so I want to keep the effects of a power up across levels on a hub and thus I added the +INVENTORY.PERSISTENTPOWER and +INVENTORY.HUBPOWER to the powerup (not the powerup giver) but as I test it out it just... doesnt work at all :/
I have no idea of why this is happening.

This is my code:

Code: Select all

Class PowerCarPlayer : PowerMorph
{
	Default
	{
	Powerup.Duration 0x7FFFFFFF;
	PowerMorph.PlayerClass "CarPlayer";
	PowerMorph.MorphStyle (MRF_ADDSTAMINA|MRF_FULLHEALTH);
	PowerMorph.MorphFlash "NoFlash";
	PowerMorph.UnMorphFlash "NoFlash";
	+INVENTORY.PERSISTENTPOWER
	+INVENTORY.HUBPOWER
  }
}
User avatar
Player701
 
 
Posts: 1707
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: Keeping powerup across a hub (PERSISTENTPOWER and HUBPOWER isn't working??)

Post by Player701 »

The flags definitely do work in the sense that the powerup remains in the player's inventory after changing maps.

I suspect the real problem here is that the player is automatically unmorphed at the end of the level and is not morphed again because InitEffect does not get called. (Persistent morph powerups have apparently never been considered by the devs?)

To work around this, you could add a Travelled override to call InitEffect manually:

Code: Select all

override void Travelled()
{
    InitEffect();
}
Note that I haven't tested this, and it might be buggy or even cause a crash. If it does, you should probably file a bug report.
User avatar
IvDraco830
Posts: 14
Joined: Mon Nov 05, 2018 8:43 pm
Location: Tangoland

Re: Keeping powerup across a hub (PERSISTENTPOWER and HUBPOWER isn't working??)

Post by IvDraco830 »

Hey! First I want to thank you for your answer. I wouldn't imagine such a thing could be the issue. Next I want to say sorry for taking such a long time in answering, I hope this doesn't count as a bump or something.
So I've tried this method you shared but sadly it didn't work :/ Not that it crashed or anything, it just did nothing as far as I can tell.
User avatar
Player701
 
 
Posts: 1707
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: Keeping powerup across a hub (PERSISTENTPOWER and HUBPOWER isn't working??)

Post by Player701 »

Yeah, unfortunately it doesn't appear to be as simple as I thought. The problem is that the unmorphing code removes all PowerMorph items from the inventory.

We can attempt to circumvent this by giving the player an additional inventory item that indicates that they should be morphed upon level change:

Code: Select all

class MorphToken : Inventory
{
    Default
    {
        +INVENTORY.UNDROPPABLE;
    }

    override void Travelled()
    {
        if (Owner != null)
        {
            Owner.GiveInventory('PowerCarPlayer', 1);
        }
    }
}

class PowerCarPlayer : PowerMorph
{
    Default
    {
        ...
    }

    override void InitEffect()
    {
        Owner.GiveInventory('MorphToken', 1);
        Super.InitEffect();
    }

    override void DepleteOrDestroy()
    {
        Owner.TakeInventory('MorphToken', 1);
        Super.DepleteOrDestroy();
    }
}
Note that you do not need to explicitly take away the MorphToken when you want to undo the effect because the above code already accounts for it (taking away PowerCarPlayer will also remove the token). Also, the code assumes that the powerup will never expire on its own.

Return to “Scripting”