Skip to content

Commit

Permalink
Add sv_coopsharekeys - in coop, picking up a key will distribute it…
Browse files Browse the repository at this point in the history
… to all online players
  • Loading branch information
nashmuhandes authored and madame-rachelle committed Nov 12, 2023
1 parent 22203cb commit a04f909
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/d_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

//==========================================================================
//
Expand Down
1 change: 1 addition & 0 deletions src/doomdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions wadsrc/static/zscript/actors/inventory/inv_misc.zs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript/actors/player/player.zs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit a04f909

Please sign in to comment.