示例#1
0
//--------------------------------------------
// Health Touch
BOOL CItemHealth::MyTouch( CBasePlayer *pPlayer )
{
	// Don't heal in DM==4 if they're invincible
	if (gpGlobals->deathmatch == 4 && pPlayer->m_flInvincibleFinished > 0)
		return FALSE;

	if (pPlayer->pev->health <= 0)
		return FALSE;

	if (m_iHealType == H_MEGA)
	{
		if (pPlayer->pev->health >= 250)
			return FALSE;
		if ( !pPlayer->TakeHealth( m_iHealAmount, DMG_GENERIC | DMG_IGNORE_MAXHEALTH) )
			return FALSE;
	}
	else
	{
		// Heal the Player
		if ( !pPlayer->TakeHealth( m_iHealAmount, DMG_GENERIC ) )
			return FALSE;
	}

	ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#Get_Health", UTIL_dtos1(m_iHealAmount) );
	EMIT_SOUND( ENT(pev), CHAN_ITEM, STRING(pev->noise), 1, ATTN_NORM );

	// Setup for respawn
	if (m_iHealType == H_MEGA)
	{
		// Go invisible and fire targets
		pev->effects |= EF_NODRAW;
		SetTouch( NULL );
		SUB_UseTargets( pPlayer, USE_TOGGLE, 0 );

		pPlayer->m_iQuakeItems |= IT_SUPERHEALTH;
		if (gpGlobals->deathmatch != 4)
		{
			SetThink( &CItemHealth::MegahealthRot );
			pev->nextthink = gpGlobals->time + 5;
		}
		m_hRotTarget = pPlayer;

		// Return FALSE, because we want to handle our respawn ourselves
		return FALSE;
	}

	// Respawn as normal
	return TRUE;
}
void CHalfLifeMultiplay :: GoToIntermission( void )
{
	if ( g_fGameOver )
		return;  // intermission has already been triggered, so ignore.

	MESSAGE_BEGIN(MSG_ALL, SVC_INTERMISSION);
	MESSAGE_END();

	// bounds check
	int time = (int)CVAR_GET_FLOAT( "mp_chattime" );
	if ( time < 1 )
		CVAR_SET_STRING( "mp_chattime", "1" );
	else if ( time > MAX_INTERMISSION_TIME )
		CVAR_SET_STRING( "mp_chattime", UTIL_dtos1( MAX_INTERMISSION_TIME ) );

	m_flIntermissionEndTime = gpGlobals->time + ( (int)mp_chattime.value );
	g_flIntermissionStartTime = gpGlobals->time;

	g_fGameOver = true;
	m_iEndIntermissionButtonHit = FALSE;
}
//=========================================================
//=========================================================
void CHalfLifeMultiplay :: Think ( void )
{
	g_VoiceGameMgr.Update(gpGlobals->frametime);

	///// Check game rules /////
	static int last_frags;
	static int last_time;

	int frags_remaining = 0;
	int time_remaining = 0;

	if ( g_fGameOver )   // someone else quit the game already
	{
		// bounds check
		int time = (int)CVAR_GET_FLOAT( "mp_chattime" );
		if ( time < 1 )
			CVAR_SET_STRING( "mp_chattime", "1" );
		else if ( time > MAX_INTERMISSION_TIME )
			CVAR_SET_STRING( "mp_chattime", UTIL_dtos1( MAX_INTERMISSION_TIME ) );

		m_flIntermissionEndTime = g_flIntermissionStartTime + mp_chattime.value;

		// check to see if we should change levels now
		if ( m_flIntermissionEndTime < gpGlobals->time )
		{
			if ( m_iEndIntermissionButtonHit  // check that someone has pressed a key, or the max intermission time is over
				|| ( ( g_flIntermissionStartTime + MAX_INTERMISSION_TIME ) < gpGlobals->time) ) 
				ChangeLevel(); // intermission is over
		}

		return;
	}

	float flTimeLimit = timelimit.value * 60;
	float flFragLimit = fraglimit.value;

	time_remaining = (int)(flTimeLimit ? ( flTimeLimit - gpGlobals->time ) : 0);
	
	if ( flTimeLimit != 0 && gpGlobals->time >= flTimeLimit )
	{
		GoToIntermission();
		return;
	}

	if ( flFragLimit )
	{
		int bestfrags = 9999;
		int remain;

		// check if any player is over the frag limit
		for ( int i = 1; i <= gpGlobals->maxClients; i++ )
		{
			CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );

			if ( pPlayer && pPlayer->pev->frags >= flFragLimit )
			{
				GoToIntermission();
				return;
			}


			if ( pPlayer )
			{
				remain = flFragLimit - pPlayer->pev->frags;
				if ( remain < bestfrags )
				{
					bestfrags = remain;
				}
			}

		}
		frags_remaining = bestfrags;
	}

	// Updates when frags change
	if ( frags_remaining != last_frags )
	{
		g_engfuncs.pfnCvar_DirectSet( &fragsleft, UTIL_VarArgs( "%i", frags_remaining ) );
	}

	// Updates once per second
	if ( timeleft.value != last_time )
	{
		g_engfuncs.pfnCvar_DirectSet( &timeleft, UTIL_VarArgs( "%i", time_remaining ) );
	}

	last_frags = frags_remaining;
	last_time  = time_remaining;
}
示例#4
0
// Pickup backpack
BOOL CItemBackpack::MyTouch( CBasePlayer *pPlayer )
{
	if (pPlayer->pev->health <= 0)
		return FALSE;
	if (gpGlobals->deathmatch == 4 && pPlayer->m_flInvincibleFinished > 0)
		return FALSE;


 
	if (gpGlobals->deathmatch == 4)
	{       
		pPlayer->pev->health += 10;
		ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#Additional_Health" );
		if ((pPlayer->pev->health > 250) && (pPlayer->pev->health < 300))
			EMIT_SOUND( ENT(pPlayer->pev), CHAN_ITEM, "items/protect3.wav", 1, ATTN_NORM );
		else
			EMIT_SOUND( ENT(pPlayer->pev), CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM );
		
		// Become invulnerable if the player's reached 300 health
		if (pPlayer->pev->health > 299)
		{               
			if (pPlayer->m_flInvincibleFinished == 0)
			{                       
				// Give player invincibility and quad
				pPlayer->m_flInvincibleFinished = gpGlobals->time + 30;
				pPlayer->m_flSuperDamageFinished = gpGlobals->time + 30;
				pPlayer->m_iQuakeItems |= (IT_INVULNERABILITY | IT_QUAD);
				pPlayer->m_iAmmoCells = 0;		

				// Make player glow red
				pPlayer->pev->renderfx = kRenderFxGlowShell;
				pPlayer->pev->rendercolor = Vector( 255, 128, 0 );	// RGB
				pPlayer->pev->renderamt = 100;	// Shell size

				EMIT_SOUND( ENT(pPlayer->pev), CHAN_VOICE, "items/sight1.wav", 1, ATTN_NORM );
				UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Bonus_Power", STRING(pPlayer->pev->netname) );
			}
		}

		UTIL_Remove( this );

		// We've removed ourself, so don't let CQuakeItem handle respawn
		return FALSE;
	}

	BOOL bPrintComma = FALSE;

	// Get the weapon from the pack
	if (m_iItems)
	{
		if ( !(pPlayer->m_iQuakeItems & m_iItems) )
		{
			bPrintComma = TRUE;

			switch ( m_iItems )
			{
			case IT_SUPER_SHOTGUN:
				ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#You_Get_SS", UTIL_dtos1( ammo_shells ), UTIL_dtos2 ( ammo_nails ), UTIL_dtos3 ( ammo_rockets ), UTIL_dtos4 ( ammo_cells ) ); break;
			case IT_NAILGUN:
				ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#You_Get_NG", UTIL_dtos1( ammo_shells ), UTIL_dtos2 ( ammo_nails ), UTIL_dtos3 ( ammo_rockets ), UTIL_dtos4 ( ammo_cells ) ); break;
			case IT_SUPER_NAILGUN:
				ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#You_Get_SG", UTIL_dtos1( ammo_shells ), UTIL_dtos2 ( ammo_nails ), UTIL_dtos3 ( ammo_rockets ), UTIL_dtos4 ( ammo_cells ) ); break;
			case IT_GRENADE_LAUNCHER:
				ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#You_Get_GL", UTIL_dtos1( ammo_shells ), UTIL_dtos2 ( ammo_nails ), UTIL_dtos3 ( ammo_rockets ), UTIL_dtos4 ( ammo_cells ) ); break;
			case IT_ROCKET_LAUNCHER:
				ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#You_Get_RL", UTIL_dtos1( ammo_shells ), UTIL_dtos2 ( ammo_nails ), UTIL_dtos3 ( ammo_rockets ), UTIL_dtos4 ( ammo_cells ) ); break;
			case IT_LIGHTNING:
				ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#You_Get_LG", UTIL_dtos1( ammo_shells ), UTIL_dtos2 ( ammo_nails ), UTIL_dtos3 ( ammo_rockets ), UTIL_dtos4 ( ammo_cells ) ); break;
			}
		}
		else
			ClientPrint( pPlayer->pev, HUD_PRINTNOTIFY, "#You_Get_NoGun", UTIL_dtos1( ammo_shells ), UTIL_dtos2 ( ammo_nails ), UTIL_dtos3 ( ammo_rockets ), UTIL_dtos4 ( ammo_cells ) );
	}
 
	// Get ammo from pack
	pPlayer->m_iAmmoShells += ammo_shells;
	pPlayer->m_iAmmoNails += ammo_nails;
	pPlayer->m_iAmmoRockets += ammo_rockets;
	pPlayer->m_iAmmoCells += ammo_cells;
	pPlayer->CheckAmmo();

	int iNewWeapon = m_iItems;
	if (!iNewWeapon)
		iNewWeapon = pPlayer->m_iQuakeWeapon;
	int iOldWeapon = pPlayer->m_iQuakeItems;
	pPlayer->m_iQuakeItems |= m_iItems;

	// Give them at least 5 rockets in DM==3 and DM==5
	if ( (gpGlobals->deathmatch==3 || gpGlobals->deathmatch == 5) & ( (WeaponCode(iNewWeapon)==6) || (WeaponCode(iNewWeapon)==7) ) & (pPlayer->m_iAmmoRockets < 5) )
		pPlayer->m_iAmmoRockets = 5;

	EMIT_SOUND( ENT(pPlayer->pev), CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM );

	// Switch to a better weapon
	if ( WeaponCode(iNewWeapon) <= pPlayer->m_iBackpackSwitch )
	{
		if (pPlayer->pev->flags & FL_INWATER)
		{
			if (iNewWeapon != IT_LIGHTNING)
			{
				pPlayer->Deathmatch_Weapon(iOldWeapon, iNewWeapon);
			}
		}
		else
		{                
			pPlayer->Deathmatch_Weapon(iOldWeapon, iNewWeapon);
		}
	}
	pPlayer->W_SetCurrentAmmo();
	pPlayer->m_iClientQuakeWeapon  = -1;
	pPlayer->m_fWeapon = FALSE;
	pPlayer->m_fKnownItem = FALSE;
	pPlayer->UpdateClientData();

	UTIL_Remove( this );

	// We've removed ourself, so don't let CQuakeItem handle respawn
	return FALSE;
}