In Zscript, is there a way to get a powerup to continue being active after death and respawn in cooperative.
It seems to copy the item over correctly on respawn, but calls the destroy method on it for some reason.
Powerup survive death in coop
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!)
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!)
- Player701
-
- Posts: 1640
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Powerup survive death in coop
This is because the "Keep powerups" gameplay option is not enabled. This behavior is hard-coded in FilterCoopRespawnInventory, which is called by the engine from C++ code. I'm not sure if there is any way to affect this behavior.
-
- Posts: 369
- Joined: Fri Feb 07, 2014 6:45 am
Re: Powerup survive death in coop
Just trying to understand this a little better. From the Zscript side it looks like the property is "sv_cooplosepowerups" which is not on in this case, this runs in FilterCoopRespawnInventory in player.zs. But even with that value off, DestroyAllInventory() gets run at the end of the method and appears to call destroy on the powerup. As you've pointed out, there seems to also be something internal running doing something similar in the C++ codebase too. When I put checks in the endeffect on the powerup and the ondestroy I see them happen twice.
In this there are the following console printf statements to show the order:
For moving forward, is there an override or an event that can be used after BeginPlay to grant this item that won't destroy the new copy?
In this there are the following console printf statements to show the order:
- The Player's BeginPlay - Console print to show this method ran
- The Player's BeginPlay - Console print to show the item doesn't exist and a new was created
- Powerup's EndEffect - Console print to show end effect was called
- Powerup's OnDestroy- Console print to show Destroy was called
For moving forward, is there an override or an event that can be used after BeginPlay to grant this item that won't destroy the new copy?
- Player701
-
- Posts: 1640
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Powerup survive death in coop
DestroyAllInventory is called for the newly spawned PlayerPawn before transferring the inventory from the PlayerPawn that died. It should not affect existing items.peewee_RotA wrote:But even with that value off, DestroyAllInventory() gets run at the end of the method and appears to call destroy on the powerup.
What does affect it, however, is something I seem to have forgotten about - it is that by default, powerups are automatically destroyed when the player dies. So sv_cooplosepowerups does not have any effect at all on them. This can be mitigated, however, by inserting the following code in your powerup class:
Code: Select all
override void OwnerDied() {}
-
- Posts: 369
- Joined: Fri Feb 07, 2014 6:45 am
Re: Powerup survive death in coop
Yay, creating an OwnerDied override worked. That's awesome! Thanks!