Add sv_coopsharekeys - in coop, picking up a key will distribute it to all online players

This commit is contained in:
nashmuhandes 2023-11-12 01:47:52 +08:00 committed by Rachael Alexanderson
parent 22203cbc1a
commit a04f909d06
4 changed files with 25 additions and 1 deletions

View file

@ -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);
//==========================================================================
//

View file

@ -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.

View file

@ -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;

View file

@ -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();
}