From b6f33c964a9f1b74e08bc6e2f02364e4354af2c5 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Sun, 24 Nov 2019 23:15:26 +0500 Subject: [PATCH] Add item_flashlight. --- cl_dll/flashlight.cpp | 2 +- dlls/items.cpp | 30 ++++++++++++++++++++++++++++++ dlls/player.cpp | 2 +- dlls/weapons.h | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cl_dll/flashlight.cpp b/cl_dll/flashlight.cpp index 3ec69973..718595d6 100644 --- a/cl_dll/flashlight.cpp +++ b/cl_dll/flashlight.cpp @@ -111,7 +111,7 @@ int CHudFlashlight::Draw( float flTime ) if( gEngfuncs.IsSpectateOnly() ) return 1; - if( !( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) ) ) + if( !( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_FLASHLIGHT ) ) ) ) return 1; if( m_fOn ) diff --git a/dlls/items.cpp b/dlls/items.cpp index 08a13711..38d8a270 100644 --- a/dlls/items.cpp +++ b/dlls/items.cpp @@ -70,6 +70,9 @@ void CWorldItem::Spawn( void ) case 45: // ITEM_SUIT: pEntity = CBaseEntity::Create( "item_suit", pev->origin, pev->angles ); break; + case 46: // ITEM_FLASHLIGHT: + pEntity = CBaseEntity::Create( "item_flashlight", pev->origin, pev->angles ); + break; } if( !pEntity ) @@ -298,6 +301,33 @@ class CItemSecurity : public CItem LINK_ENTITY_TO_CLASS( item_security, CItemSecurity ) +class CItemFlashlight : public CItem +{ + void Spawn( void ) + { + Precache(); + SET_MODEL( ENT( pev ), "models/w_flashlight.mdl" ); + CItem::Spawn(); + } + void Precache( void ) + { + PRECACHE_MODEL( "models/w_flashlight.mdl" ); + PRECACHE_SOUND( "items/gunpickup2.wav" ); + } + BOOL MyTouch( CBasePlayer *pPlayer ) + { + if( pPlayer->pev->weapons & ( 1 << WEAPON_FLASHLIGHT ) ) + return FALSE; + + EMIT_SOUND( pPlayer->edict(), CHAN_ITEM, "items/gunpickup2.wav", 1, ATTN_NORM ); + + pPlayer->pev->weapons |= ( 1 << WEAPON_FLASHLIGHT ); + return TRUE; + } +}; + +LINK_ENTITY_TO_CLASS( item_flashlight, CItemFlashlight ) + class CItemLongJump : public CItem { void Spawn( void ) diff --git a/dlls/player.cpp b/dlls/player.cpp index 6b741778..8d20e865 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -3295,7 +3295,7 @@ void CBasePlayer::FlashlightTurnOn( void ) return; } - if( (pev->weapons & ( 1 << WEAPON_SUIT ) ) ) + if( (pev->weapons & ( 1 << WEAPON_FLASHLIGHT ) ) ) { EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, SOUND_FLASHLIGHT_ON, 1.0, ATTN_NORM, 0, PITCH_NORM ); SetBits( pev->effects, EF_DIMLIGHT ); diff --git a/dlls/weapons.h b/dlls/weapons.h index 312f5531..03d07b6a 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -81,6 +81,7 @@ public: #define WEAPON_ALLWEAPONS (~(1<