text: //========= Copyright Bernt Andreas Eide, All rights reserved. ============//
  //
  // Purpose: Ammo Entity
  //
  //=============================================================================//
  
  #include "cbase.h"
  #include "gamerules.h"
  #include "baseanimating.h"
  #include "items.h"
  #include "hl2_player.h"
  #include "basecombatweapon.h"
  #include "player.h"
  #include "ammodef.h"
  #include "npcevent.h"
  #include "eventlist.h"
  
  class CP38Ammo : public CItem
  {
  public:
  	DECLARE_CLASS(CP38Ammo, CItem);
  	DECLARE_DATADESC();
  
  	CP38Ammo()
  	{
  		color32 col32 = { 150, 100, 100, 180 };
  		m_GlowColor = col32;
  	}
  
  	void Spawn(void);
  	void Precache(void);
  
  	void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
  
  private:
  
  	COutputEvent	m_OnUse;
  
  };
  
  LINK_ENTITY_TO_CLASS(p38_ammo, CP38Ammo);
  
  BEGIN_DATADESC(CP38Ammo)
  DEFINE_OUTPUT(m_OnUse, "OnUse"),
  END_DATADESC()
  
  PRECACHE_REGISTER(p38_ammo);
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  void CP38Ammo::Spawn(void)
  {
  	Precache();
  	SetModel("models/items/w_p38_ammo.mdl");
  	AddEffects(EF_NOSHADOW);
  	BaseClass::Spawn();
  }
  
  void CP38Ammo::Precache(void)
  {
  	PrecacheModel("models/items/w_p38_ammo.mdl");
  }
  
  void CP38Ammo::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
  {
  	if (!pActivator)
  		return;
  
  	if (!pActivator->IsPlayer())
  		return;
  
  	CBasePlayer *pPlayer = ToBasePlayer(pActivator);
  	if (!pPlayer)
  		return;
  
  	if (GiveAmmo(pPlayer, SIZE_AMMO_P38, "P38"))
  	{
  		m_OnUse.FireOutput(this, this);
  		EmitSound("Ammo.Pickup2");
  		UTIL_Remove(this);
  	}
  }