diff --git a/src/d_main.cpp b/src/d_main.cpp index 64d29bb550..f1f5593633 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -573,6 +573,7 @@ CUSTOM_CVAR(Int, dmflags3, 0, CVAR_SERVERINFO | CVAR_NOINITCALL) } CVAR(Flag, sv_noplayerclip, dmflags3, DF3_NO_PLAYER_CLIP); +CVAR(Flag, sv_coopsharekeys, dmflags3, DF3_COOP_SHARE_KEYS); //========================================================================== // diff --git a/src/doomdef.h b/src/doomdef.h index 111bf7ad2c..a2ae2f35e4 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -180,6 +180,7 @@ enum : unsigned enum : unsigned { DF3_NO_PLAYER_CLIP = 1 << 0, // Players can walk through and shoot through each other + DF3_COOP_SHARE_KEYS = 1 << 1, // Keys will be given to all players in coop }; // [RH] Compatibility flags. diff --git a/wadsrc/static/zscript/actors/inventory/inv_misc.zs b/wadsrc/static/zscript/actors/inventory/inv_misc.zs index 1d31022ad9..5fc4e3fe23 100644 --- a/wadsrc/static/zscript/actors/inventory/inv_misc.zs +++ b/wadsrc/static/zscript/actors/inventory/inv_misc.zs @@ -59,6 +59,28 @@ class Key : Inventory return false; } + override void AttachToOwner(Actor other) + { + Super.AttachToOwner(other); + + if (multiplayer && !deathmatch && sv_coopsharekeys) + { + for (int i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + { + let pmo = players[i].mo; + + if (pmo == other) + continue; + + if (!pmo.FindInventory(GetClass())) + pmo.GiveInventoryType(GetClass()); + } + } + } + } + override bool ShouldStay () { return !!multiplayer; diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index 807835ebb1..235b97c8da 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -888,7 +888,7 @@ class PlayerPawn : Actor // inventory amount. let defitem = FindInventory (item.GetClass()); - if (sv_cooplosekeys && defitem == NULL && item is 'Key') + if ((sv_cooplosekeys && !sv_coopsharekeys) && defitem == NULL && item is 'Key') { item.Destroy(); }