From bd5b421578be9cebf722d50e348f938eff120279 Mon Sep 17 00:00:00 2001 From: mittorn Date: Wed, 28 Sep 2016 02:42:48 +0700 Subject: [PATCH] Coop weapon list --- dlls/multiplay_gamerules.cpp | 31 +++++++++++++++++++++++++++++++ dlls/weapons.cpp | 1 + 2 files changed, 32 insertions(+) diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index be100079..0de78034 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -64,6 +64,28 @@ public: static CMultiplayGameMgrHelper g_GameMgrHelper; #endif + +// Collect all weapons tat player touchet in coop ant give to all players at spawn +class CWeaponList +{ + char weapons[64][256]; + int m_iWeapons; +public: + void AddWeapon( const char *classname ) + { + int i; + for(i = 0; i < m_iWeapons;i++) + if(!strcmp(weapons[i], classname)) + return; + strcpy(weapons[m_iWeapons++], classname); + } + void GiveToPlayer(CBasePlayer *player) + { + for(int i = 0; i < m_iWeapons;i++) + player->GiveNamedItem(weapons[i]); + } +} g_WeaponList; + //********************************************************* // Rules for the half-life multiplayer game. //********************************************************* @@ -587,6 +609,8 @@ void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer ) pPlayer->GiveAmmo( cvar_ar2_balls.value, "AR2grenades", 3 ); } pPlayer->GiveAmmo( 68, "9mm", _9MM_MAX_CARRY );// 4 full reloads + if(mp_coop.value) + g_WeaponList.GiveToPlayer(pPlayer); } } @@ -903,6 +927,8 @@ void CHalfLifeMultiplay::DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, //========================================================= void CHalfLifeMultiplay::PlayerGotWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ) { + if(mp_coop.value) + g_WeaponList.AddWeapon(STRING(pWeapon->pev->classname)); } //========================================================= @@ -1011,6 +1037,8 @@ BOOL CHalfLifeMultiplay::CanHaveItem( CBasePlayer *pPlayer, CItem *pItem ) //========================================================= void CHalfLifeMultiplay::PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem ) { + if(mp_coop.value) + g_WeaponList.AddWeapon(STRING(pItem->pev->classname)); } //========================================================= @@ -1046,6 +1074,9 @@ Vector CHalfLifeMultiplay::VecItemRespawnSpot( CItem *pItem ) //========================================================= void CHalfLifeMultiplay::PlayerGotAmmo( CBasePlayer *pPlayer, char *szName, int iCount ) { + + if(mp_coop.value) + g_WeaponList.AddWeapon(szName); } //========================================================= diff --git a/dlls/weapons.cpp b/dlls/weapons.cpp index e918cffe..c0970471 100644 --- a/dlls/weapons.cpp +++ b/dlls/weapons.cpp @@ -1205,6 +1205,7 @@ void CBasePlayerAmmo::DefaultTouch( CBaseEntity *pOther ) if( AddAmmo( pOther ) ) { + g_pGameRules->PlayerGotAmmo( NULL, (char*)STRING(pev->classname), 0); if( g_pGameRules->AmmoShouldRespawn( this ) == GR_AMMO_RESPAWN_YES ) { Respawn();