View Single Post
Re: Traceline navigation
Old
  (#5)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: Traceline navigation - 16-03-2004

Seeing as how this thread is fairly new I'll post a new question in it rather than make a new one.

===========================

I've been looking over my code for a while now and I cannot see anything wrong with it.
It's supposed to hurt people who decide to stand ontop of the hive and attack it ( NS ) but it only works for the first map, then becomes unreliable.

I may just be tired, but heres what I have...

Code:
#include <extdll.h>
#include <meta_api.h>
#include <cbase.h>
#include <player.h>
#include <progdefs.h>
float g_flNextDamageTime[ 33 ];
float g_flNextWarnTime[ 33 ];
int DispatchSpawn( edict_t* pEdict )
{
   if ( FClassnameIs( pEdict, "worldspawn" ) )
   {
	  memset( g_flNextWarnTime, 0, sizeof( float ) * 33 );
	  memset( g_flNextDamageTime, 0, sizeof( float ) * 33 );
   }
   RETURN_META_VALUE( MRES_IGNORED, 0 );
}
void PlayerPostThink( edict_t* pEdict )
{
   int iIndex = ENTINDEX( pEdict );   
   CBasePlayer* pPlayer = NULL;
   CBaseEntity* pEntity = NULL;
   TraceResult tr;
   pPlayer = ( CBasePlayer* ) CBaseEntity::Instance( pEdict );
   if ( pPlayer &&						   // Null pointer check
		pPlayer->pev &&					  // ^^
		pPlayer->pev->iuser3 == 1 &&		 // Are we a marine?
		pPlayer->pev->deadflag == DEAD_NO	// Are we alive?
	  )
   {
	  pEntity = CBaseEntity::Instance( pPlayer->pev->groundentity );
	  if ( pEntity &&
		   pEntity->pev &&
		   FClassnameIs( pEntity->pev, "team_hive" ) &&  // A Hive? ( Dont worry about unstarted hives )
		 )
	  {
		 // Trace down to make sure we are still ontop of the hive
		 TRACE_LINE( pPlayer->pev->origin, pPlayer->pev->origin + Vector( 0, 0, -64 ), dont_ignore_monsters, ENT( pPlayer->pev ), &tr );
		 if ( tr.pHit &&
			  tr.pHit == pEntity->edict( )
			)
		 {
			if ( gpGlobals->time >= g_flNextDamageTime[ iIndex ] )
			{
			   // Cause pain sometime in the future
			   g_flNextDamageTime[ iIndex ] = gpGlobals->time + RANDOM_FLOAT( 0.1f, 0.5f );  
			   // Do the damage
			   pPlayer->TakeDamage( VARS( pEntity->pev->owner ), VARS( pEntity->pev ), RANDOM_FLOAT( 15.0f, 50.0f ), DMG_NERVEGAS ); 
			}
			if ( gpGlobals->time >= g_flNextWarnTime[ iIndex ] )
			{
			   g_flNextWarnTime[ iIndex ] = gpGlobals->time + 3.0f;
			   MESSAGE_BEGIN( MSG_ONE_UNRELIABLE, GET_USER_MSG_ID( PLID, "SayText", NULL ), NULL, pPlayer->pev );
				  WRITE_BYTE( -1 );
				  WRITE_STRING( "> You cannot stand ontop of the hive!\n" );
			   MESSAGE_END( );
			}
		 }
	  }
   }
   
   RETURN_META( MRES_IGNORED );
}
  
Reply With Quote