Powerup survive death in coop

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!)
Post Reply
peewee_RotA
Posts: 369
Joined: Fri Feb 07, 2014 6:45 am

Powerup survive death in coop

Post by peewee_RotA »

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.
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Powerup survive death in coop

Post by Player701 »

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.
peewee_RotA
Posts: 369
Joined: Fri Feb 07, 2014 6:45 am

Re: Powerup survive death in coop

Post by peewee_RotA »

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.
xrpg_consolelog1.png
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
So in the screenshot there is a destroy before the player obituary is printed, then begin play and a new item is given, then a destroy item immediately after. So even though I include a line to give a new powerup item in BeginPlay it seems to run a destroy again. I think that's the C++ side of things.

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?
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Powerup survive death in coop

Post by Player701 »

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.
DestroyAllInventory is called for the newly spawned PlayerPawn before transferring the inventory from the PlayerPawn that died. It should not affect existing items.

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() {}
Besides that, you do not need any extra code to create new copies manually if you want your powerup to be transferred to the new player after death. I've just tested it myself and haven't encountered any issues whatsoever. That is, provided that sv_cooplosepowerups is false.
peewee_RotA
Posts: 369
Joined: Fri Feb 07, 2014 6:45 am

Re: Powerup survive death in coop

Post by peewee_RotA »

Yay, creating an OwnerDied override worked. That's awesome! Thanks!
Post Reply

Return to “Scripting”