Example #1
0
void UTIL_HostSay( edict_t *pEntity, char *message )
{
   int   j;
   char  text[128];
   char *pc;
   edict_t *client;

   // make sure the text has content
   for ( pc = message; pc != NULL && *pc != 0; pc++ )
   {
      if ( isprint( *pc ) && !isspace( *pc ) )
      {
         pc = NULL;   // we've found an alphanumeric character,  so text is valid
         break;
      }
   }

   if ( pc != NULL )
      return;  // no character found, so say nothing

   // turn on color set 2  (color on,  no sound)
   sprintf( text, "%c%s: ", 2, STRING( pEntity->v.netname ) );

   j = sizeof(text) - 2 - strlen(text);  // -2 for /n and null terminator
   if ( (int)strlen(message) > j )
      message[j] = 0;

   strcat( text, message );
   strcat( text, "\n" );

   // loop through all players
   // Start with the first player.
   // This may return the world in single player if the client types something between levels or during spawn
   // so check it, or it will infinite loop

   if (gmsgSayText == 0)
      gmsgSayText = REG_USER_MSG( "SayText", -1 );

   client = NULL;
   while ( ((client = UTIL_FindEntityByClassname( client, "player" )) != NULL) &&
           (!FNullEnt(client)) ) 
   {
      if ( client == pEntity )  // skip sender of message
         continue;

      MESSAGE_BEGIN( MSG_ONE_UNRELIABLE, gmsgSayText, NULL, client );
         WRITE_BYTE( ENTINDEX(pEntity) );
         WRITE_STRING( text );
      MESSAGE_END();
   }

   // print to the sending client
   MESSAGE_BEGIN( MSG_ONE_UNRELIABLE, gmsgSayText, NULL, pEntity );
      WRITE_BYTE( ENTINDEX(pEntity) );
      WRITE_STRING( text );
   MESSAGE_END();
}
Example #2
0
// Find the next client in the game for this player to spectate
void CBasePlayer::Observer_FindNextPlayer( bool bReverse )
{
	// MOD AUTHORS: Modify the logic of this function if you want to restrict the observer to watching
	//				only a subset of the players. e.g. Make it check the target's team.

	int		iStart;
	if ( m_hObserverTarget )
		iStart = ENTINDEX( m_hObserverTarget->edict() );
	else
		iStart = ENTINDEX( edict() );
	int	    iCurrent = iStart;
	m_hObserverTarget = NULL;
	int iDir = bReverse ? -1 : 1; 

	do
	{
		iCurrent += iDir;

		// Loop through the clients
		if (iCurrent > gpGlobals->maxClients)
			iCurrent = 1;
		if (iCurrent < 1)
			iCurrent = gpGlobals->maxClients;

		CBaseEntity *pEnt = UTIL_PlayerByIndex( iCurrent );
		if ( !pEnt )
			continue;
		if ( pEnt == this )
			continue;
		// Don't spec observers or players who haven't picked a class yet
		if ( ((CBasePlayer*)pEnt)->IsObserver() || (pEnt->pev->effects & EF_NODRAW) )
			continue;

		// MOD AUTHORS: Add checks on target here.

		m_hObserverTarget = pEnt;
		break;

	} while ( iCurrent != iStart );

	// Did we find a target?
	if ( m_hObserverTarget )
	{
		// Move to the target
		UTIL_SetOrigin( pev, m_hObserverTarget->pev->origin );

		// ALERT( at_console, "Now Tracking %s\n", STRING( m_hObserverTarget->pev->netname ) );

		// Store the target in pev so the physics DLL can get to it
		if (pev->iuser1 != OBS_ROAMING)
			pev->iuser2 = ENTINDEX( m_hObserverTarget->edict() );
	
		
		
	}
}
Example #3
0
void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *shooter, TraceResult *ptr) {
	TRACE_LINE(v1, v2, fNoMonsters, shooter, ptr);
	if ( ptr->pHit && (ptr->pHit->v.flags& (FL_CLIENT | FL_FAKECLIENT))
	&& shooter && (shooter->v.flags & (FL_CLIENT | FL_FAKECLIENT)) ) {
		int shooterIndex = ENTINDEX(shooter);
		if ( !(g_bodyhits[shooterIndex][ENTINDEX(ptr->pHit)] & (1<<ptr->iHitgroup)) )
			ptr->flFraction = 1.0;
	}
	RETURN_META(MRES_SUPERCEDE);
}
Example #4
0
//=========================================================
// PlayerKilled - someone/something killed this player
//=========================================================
void CHalfLifeMultiplay :: PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor )
{
	DeathNotice( pVictim, pKiller, pInflictor );

	pVictim->m_iDeaths += 1;


	FireTargets( "game_playerdie", pVictim, pVictim, USE_TOGGLE, 0 );
	CBasePlayer *peKiller = NULL;
	CBaseEntity *ktmp = CBaseEntity::Instance( pKiller );
	if ( ktmp && (ktmp->Classify() == CLASS_PLAYER) )
		peKiller = (CBasePlayer*)ktmp;

	if ( pVictim->pev == pKiller )  
	{  // killed self
		pKiller->frags -= 1;
	}
	else if ( ktmp && ktmp->IsPlayer() )
	{
		// if a player dies in a deathmatch game and the killer is a client, award the killer some points
		pKiller->frags += IPointsForKill( peKiller, pVictim );
		
		FireTargets( "game_playerkill", ktmp, ktmp, USE_TOGGLE, 0 );
	}
	else
	{  // killed by the world
		pVictim->pev->frags -= 1;
	}

	// update the scores
	// killed scores
	MESSAGE_BEGIN( MSG_ALL, gmsgScoreInfo );
		WRITE_BYTE( ENTINDEX(pVictim->edict()) );
		WRITE_SHORT( pVictim->pev->frags );
		WRITE_SHORT( pVictim->m_iDeaths );
		WRITE_SHORT( pVictim->pev->team );
	MESSAGE_END();

	// killers score, if it's a player
	CBaseEntity *ep = CBaseEntity::Instance( pKiller );
	if ( ep && ep->Classify() == CLASS_PLAYER )
	{
		CBasePlayer *PK = (CBasePlayer*)ep;

		MESSAGE_BEGIN( MSG_ALL, gmsgScoreInfo );
			WRITE_BYTE( ENTINDEX(PK->edict()) );
			WRITE_SHORT( PK->pev->frags );
			WRITE_SHORT( PK->m_iDeaths );
			WRITE_SHORT( PK->pev->team );
		MESSAGE_END();

		// let the killer paint another decal as soon as he'd like.
		PK->m_flNextDecalTime = gpGlobals->time;
	}
}
Example #5
0
/*
========================
ClientUserInfoChanged

called after the player changes
userinfo - gives dll a chance to modify it before
it gets sent into the rest of the engine.
========================
*/
void ClientUserInfoChanged( edict_t *pEntity, char *infobuffer )
{
	// Is the client spawned yet?
	if ( !pEntity->pvPrivateData )
		return;

	// msg everyone if someone changes their name,  and it isn't the first time (changing no name to current name)
	if ( pEntity->v.netname && STRING(pEntity->v.netname)[0] != 0 && !FStrEq( STRING(pEntity->v.netname), g_engfuncs.pfnInfoKeyValue( infobuffer, "name" )) )
	{
		char sName[256];
		char *pName = g_engfuncs.pfnInfoKeyValue( infobuffer, "name" );
		strncpy( sName, pName, sizeof(sName) - 1 );
		sName[ sizeof(sName) - 1 ] = '\0';

		// First parse the name and remove any %'s
		for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
		{
			// Replace it with a space
			if ( *pApersand == '%' )
				*pApersand = ' ';
		}

		// Set the name
		g_engfuncs.pfnSetClientKeyValue( ENTINDEX(pEntity), infobuffer, "name", sName );

		char text[256];
		sprintf( text, "* %s changed name to %s\n", STRING(pEntity->v.netname), g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) );
		MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL );
			WRITE_BYTE( ENTINDEX(pEntity) );
			WRITE_STRING( text );
		MESSAGE_END();

		// team match?
		if ( g_teamplay )
		{
			UTIL_LogPrintf( "\"%s<%i><%s><%s>\" changed name to \"%s\"\n", 
				STRING( pEntity->v.netname ), 
				GETPLAYERUSERID( pEntity ), 
				GETPLAYERAUTHID( pEntity ),
				g_engfuncs.pfnInfoKeyValue( infobuffer, "model" ), 
				g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) );
		}
		else
		{
			UTIL_LogPrintf( "\"%s<%i><%s><%i>\" changed name to \"%s\"\n", 
				STRING( pEntity->v.netname ), 
				GETPLAYERUSERID( pEntity ), 
				GETPLAYERAUTHID( pEntity ),
				GETPLAYERUSERID( pEntity ), 
				g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) );
		}
	}

	g_pGameRules->ClientUserInfoChanged( GetClassPtr((CBasePlayer *)&pEntity->v), infobuffer );
}
void ChasePath::RefreshPath(INextBot *nextbot, CBaseEntity *ent, const IPathCost& cost_func, Vector *vec)
{
	VPROF_BUDGET("ChasePath::RefreshPath", "NextBot");
	
	if (this->IsValid() && nextbot->GetLocomotionInterface()->IsUsingLadder()) {
		if (nextbot->IsDebugging(DEBUG_PATH)) {
			DevMsg("%3.2f: bot(#%d) ChasePath::RefreshPath failed. Bot is on a ladder.\n",
				gpGlobals->curtime, ENTINDEX(nextbot->GetEntity()));
		}
		
		this->m_ctTimer2.Start(1.0f);
		return;
	}
	
	if (ent == nullptr) {
		if (nextbot->IsDebugging(DEBUG_PATH)) {
			/* misspelling is in original */
			DevMsg("%3.2f: bot(#%d) CasePath::RefreshPath failed. No subject.\n",
				gpGlobals->curtime, ENTINDEX(nextbot->GetEntity()));
		}
	}
	
	if (this->m_ctTimer1.IsElapsed()) {
		CBaseEntity *subject = this->m_hChaseSubject();
		if (subject == nullptr || subject != ent) {
			if (nextbot->IsDebugging(DEBUG_PATH)) {
				DevMsg("%3.2f: bot(#%d) ChasePath::RefreshPath subject changed (from %p to %p).\n",
					gpGlobals->curtime, ENTINDEX(nextbot->GetEntity()),
					this->m_hChaseSubject(), ent);
			}
			
			this->Invalidate();
			this->m_ctTimer1.Invalidate();
		}
		
		if (!this->IsValid() || this->m_ctTimer2.IsElapsed()) {
			if (this->IsValid() && this->m_ctTimer3.HasStarted() &&
				this->m_ctTimer3.IsElapsed()) {
				this->Invalidate();
			}
			
			if (!this->IsValid() || this->IsRepathNeeded(nextbot, ent)) {
				// TODO
				
				
				// eventually: this->Compute(...)
			}
			
			// TODO
		}
		
		// TODO
	}
}
Example #7
0
/*
========================
ClientUserInfoChanged

called after the player changes
userinfo - gives dll a chance to modify it before
it gets sent into the rest of the engine.
========================
*/
void ClientUserInfoChanged( edict_t *pEntity, char *infobuffer )
{
	// Is the client spawned yet?
	if ( !pEntity->pvPrivateData )
		return;

	// msg everyone if someone changes their name,  and it isn't the first time (changing no name to current name)
	if ( pEntity->v.netname && STRING(pEntity->v.netname)[0] != 0 && !FStrEq( STRING(pEntity->v.netname), g_engfuncs.pfnInfoKeyValue( infobuffer, "name" )) )
	{
		char sName[256];
		char *pName = g_engfuncs.pfnInfoKeyValue( infobuffer, "name" );
		strncpy( sName, pName, sizeof(sName) - 1 );
		sName[ sizeof(sName) - 1 ] = '\0';

		// First parse the name and remove any %'s
		for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
		{
			// Replace it with a space
			if ( *pApersand == '%' )
				*pApersand = ' ';
		}

		// Set the name
		g_engfuncs.pfnSetClientKeyValue( ENTINDEX(pEntity), infobuffer, "name", sName );

		char text[256];
		sprintf( text, "* %s changed name to %s\n", STRING(pEntity->v.netname), g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) );
		MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL );
			WRITE_BYTE( ENTINDEX(pEntity) );
			WRITE_STRING( text );
		MESSAGE_END();

		UTIL_LogPrintf( "\"%s<%i><%s><%i>\" changed name to \"%s\"\n", 
			STRING( pEntity->v.netname ), 
			GETPLAYERUSERID( pEntity ), 
			GETPLAYERAUTHID( pEntity ),
			GETPLAYERUSERID( pEntity ), 
			g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) );
	}

	g_pGameRules->ClientUserInfoChanged( GetClassPtr((CBasePlayer *)&pEntity->v), infobuffer );

	// Override model
	if ( (!strcmp( "models/player/female/female.mdl", g_engfuncs.pfnInfoKeyValue( infobuffer, "model" ) )) )//&& (!strcmp( "models/player/hgrunt/hgrunt.mdl" )) )
		SET_MODEL( pEntity, "models/player/male/male.mdl" );
	g_engfuncs.pfnSetClientKeyValue( ENTINDEX( pEntity ), infobuffer, "model", "male" );

	// Set colors
	int iHue = GetHueFromRGB( g_iaDiscColors[ pEntity->v.team][0] / 255, g_iaDiscColors[pEntity->v.team][1] / 255, g_iaDiscColors[pEntity->v.team][2] / 255 );
	g_engfuncs.pfnSetClientKeyValue( ENTINDEX( pEntity ), infobuffer, "topcolor", UTIL_VarArgs("%d", iHue) );
	g_engfuncs.pfnSetClientKeyValue( ENTINDEX( pEntity ), infobuffer, "bottomcolor", UTIL_VarArgs("%d", iHue - 10) );
}
Example #8
0
void StartFrame()
{
	edict_t* ent = NULL;
	while( !FNullEnt( ent = FIND_ENTITY_BY_STRING( ent, "classname", "player" ) ) )
	{
		if( esfmodels[ENTINDEX(ent)-1].bSet )
		{
			ent->v.modelindex = MODEL_INDEX( esfmodels[ENTINDEX(ent)-1].szModel );
			ent->v.model = MAKE_STRING( esfmodels[ENTINDEX(ent)-1].szModel );
		}
	}
	RETURN_META( MRES_HANDLED );
}
Example #9
0
/*
===========
ClientPutInServer

called when the player is first put in the server
============
*/
void ClientPutInServer( edict_t *pEntity )
{
	CBasePlayer *pPlayer;

	entvars_t *pev = &pEntity->v;

	pPlayer = GetClassPtr((CBasePlayer *)pev);
	pPlayer->SetCustomDecalFrames(-1); // Assume none;

	// Allocate a CBasePlayer for pev, and call spawn
	pPlayer->Spawn();

	pPlayer->m_bHasDisconnected = FALSE;

	// Reset interpolation during first frame
	pPlayer->pev->effects |= EF_NOINTERP;
	pPlayer->m_pCurrentArena = NULL;
	pPlayer->m_flKnownItemTime = gpGlobals->time + 0.3;
	pPlayer->m_iLastGameResult = GAME_DIDNTPLAY;	

	// Add to an Arena (1 maxplayer allows mapmakers to run around their map)
	if ( InArenaMode() )
	{
		AddClientToArena( pPlayer );
	}
	else
	{
		// Put everyone on different teams
		pPlayer->pev->team = ENTINDEX( pEntity );
		pPlayer->pev->iuser4 = pPlayer->pev->team;

		// Set colors
		int iHue = GetHueFromRGB( g_iaDiscColors[ pPlayer->pev->team][0] / 255, g_iaDiscColors[pPlayer->pev->team][1] / 255, g_iaDiscColors[pPlayer->pev->team][2] / 255 );
		g_engfuncs.pfnSetClientKeyValue( ENTINDEX( pEntity ), g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "topcolor", UTIL_VarArgs("%d", iHue) );
		g_engfuncs.pfnSetClientKeyValue( ENTINDEX( pEntity ), g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "bottomcolor", UTIL_VarArgs("%d", iHue - 10) );
	}

	static char sName[128];
	strcpy(sName,STRING(pPlayer->pev->netname));
	
	// First parse the name and remove any %'s
	for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
	{
		// Replace it with a space
		if ( *pApersand == '%' )
				*pApersand = ' ';
	}

	// notify other clients of player joining the game
	UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_connected", sName[0] != 0 ? sName : "<unconnected>" );
}
	/* show team ownership of nav areas based on flag position and owner capture
	 * points */
	void DrawOverlay_Ownership(long frame)
	{
		if (frame % 3 != 0) return;
		
		// TODO: default ownership when there's no bomb is wrong
		// TODO: handle areas that have incursion value of -1.0f
		
		float flag_inc = 0.0f;
		
		CCaptureFlag *flag = TheFlagTracker.GetFrontFlag();
		if (flag != nullptr) {
			auto area = static_cast<CTFNavArea *>(TheNavMesh->GetNearestNavArea(flag));
			if (area != nullptr) {
				flag_inc = area->GetIncursionDistance(TF_TEAM_RED);
			}
		}
		
		for (auto area : (CUtlVector<CTFNavArea *>&)TheNavAreas) {
			float inc = area->GetIncursionDistance(TF_TEAM_RED);
			
			if (inc < 0.0f || area->HasTFAttributes(BLUE_SPAWN_ROOM)) {
				/* gray */
			//	area->DrawFilled(0x80, 0x80, 0x80, 0x00, 3 * gpGlobals->interval_per_tick, true, 0.0f);
				area->DrawFilled(0x80, 0x80, 0x80, 0x80, 3 * gpGlobals->interval_per_tick, true, 3.0f);
			} else {
				if (flag_inc > 0.0f && inc > flag_inc) {
					/* blue */
				//	area->DrawFilled(0x20, 0x20, 0xff, 0x00, 3 * gpGlobals->interval_per_tick, true, 0.0f);
					area->DrawFilled(0x20, 0x20, 0xff, 0x80, 3 * gpGlobals->interval_per_tick, true, 3.0f);
				} else {
					/* red */
				//	area->DrawFilled(0xff, 0x20, 0x20, 0x00, 3 * gpGlobals->interval_per_tick, true, 0.0f);
					area->DrawFilled(0xff, 0x20, 0x20, 0x80, 3 * gpGlobals->interval_per_tick, true, 3.0f);
				}
			}
		}
		
#if 0
		for (const auto& pair : TheFlagTracker.GetFlagInfos()) {
			CCaptureFlag *flag   = pair.first;
			const FlagInfo& info = pair.second;
			
			NDebugOverlay::EntityText(ENTINDEX(flag), 0, "FLAG", 3 * gpGlobals->interval_per_tick, 0xff, 0xff, 0xff, 0xff);
			NDebugOverlay::EntityText(ENTINDEX(flag), 2, "Hatch path dist:", 3 * gpGlobals->interval_per_tick, 0xff, 0xff, 0xff, 0xff);
			NDebugOverlay::EntityText(ENTINDEX(flag), 3, CFmtStrN<256>("%.0f HU", info.hatch_path_dist), 3 * gpGlobals->interval_per_tick, 0xff, 0xff, 0xff, 0xff);
		}
#endif
		
		// TODO: draw gates
	}
Example #11
0
void ParaEnable( edict_t *pEntity )
{
	
	if (ChuteState[ ENTINDEX( pEntity ) ] != 1) {
		ClientPrint( VARS(pEntity), HUD_PRINTTALK, "* You don't have a parachute! Go pick one up!\n");
		return;
	}
	// cant use the parachute when you are on the ground

	if (pEntity->v.flags & FL_ONGROUND) {
		ClientPrint( VARS(pEntity), HUD_PRINTTALK, "* Parachutes only work in the air!\n");
		return;
	}
	
	// turns on the parachute
	ChuteState[ ENTINDEX( pEntity ) ] = 2;
	entvars_t *pev = VARS( pEntity );

	// set initial vars
	pev->gravity = 0.1;
	pev->speed = 0;
	pev->velocity = g_vecZero;

	// give them the parachute model

	int i = 1;
	edict_t *frontEnt;
	entvars_t *pModelPev;

	int mdlfound = 0;

	for (i; i < 1025; i++) {

		frontEnt = INDEXENT ( i );
		if (frontEnt) {
			pModelPev =  VARS(frontEnt);
			if (FStrEq((char *)STRING(pModelPev->netname), "para")) {
				// Touch this ent.
				(*other_gFunctionTable.pfnTouch)(frontEnt, pEntity);
			}
		}
	}

	// The parachute has been given to em
	// Now, we just wait for em to hit the ground then we take the chute again


}
Example #12
0
void FakespawnPlayer(edict_t *pEdict)
{
	int team = GetPlayerTeam(pEdict);

	if (team != TEAM_T && team != TEAM_CT)
	{
		return;
	}

	int index = ENTINDEX(pEdict);

	player_states *pPlayer = GET_PLAYER(index);

	if (pPlayer->spawning)
		return;

	pPlayer->spawning = true;

	if (g_PreSpawn > 0  && MF_ExecuteForward(g_PreSpawn, (cell)index, (cell)1) > 0)
	{
		pPlayer->spawning = false;
		return;
	}

	SpawnHandler(index, true);
	pPlayer->spawning = false;
}
Example #13
0
void DispatchThink( edict_t *pent )
{
	CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE(pent);
	if (pEntity)
	{
		if ( FBitSet( pEntity->pev->flags, FL_DORMANT ) )
			ALERT( at_error, "Dormant entity %s is thinking!!\n", STRING(pEntity->pev->classname) );

		//LLAPb begin
		if (!pEntity->scripted || !ScriptsActive())
		{
			pEntity->Think();

			return;
		}

		GenericFunction *pfn = pEntity->my_script->funcs->GetFn(M_THINK);

		if (!pfn)
		{
			pEntity->Think();

			return;
		}

		if (NoErrors())
		{
			pfn->PreExecute();

			int i = ENTINDEX(pent);
			double f = gpGlobals->frametime;

			if (pfn->argc > 0)
				pfn->PassArg(0, Type(&i, _INT));

			if (pfn->argc > 1)
				pfn->PassArg(1, Type(&f, DOUBLE));

			switch (pfn->specification)
			{
			case SPECIFICATION_BEFORE:
				pfn->Execute();
				pEntity->Think();
				break;

			case SPECIFICATION_INSTEAD:
				pfn->Execute();
				break;

			default:
				pEntity->Think();
				pfn->Execute();
				break;
			}
		}
		else
			//LLAPb end
			pEntity->Think();
	}
}
Example #14
0
int GetTeam (edict_t *ent)
{
	// SyPB Pro P.1
	// new get team off set, return player true team
	int client = ENTINDEX (ent) - 1, player_team;
	
	 // SyPB Pro P.5
	if (!IsValidPlayer (ent))
	{
		player_team = 0;
		edict_t *entity = null;
		ITERATE_ARRAY (g_entityName, j)
		{
			while (!FNullEnt (entity = FIND_ENTITY_BY_CLASSNAME (entity, g_entityName[j])))
			{
				if (ent == entity)
				{
					player_team = g_entityTeam[j];
					break;
				}
			}
		}
		player_team--;
		
		if (GetGameMod () == 99 && g_DelayTimer > engine->GetTime ())
			player_team = 2;
		
		return player_team;
	}
Example #15
0
void CServer::BotCreate(struct bot_profile_s *profile)
{
   edict_t *BotEnt = CreateFakeClient(profile->name);

   if (!FNullEnt(BotEnt)) {
      char *infobuffer = GET_INFOBUFFER(BotEnt);
      int clientIndex = ENTINDEX(BotEnt);

      CBaseBot *pBot = NewBotInstance();
      pBot->pev = &BotEnt->v;
      pBot->m_pProfile = profile;

      if (!IsTeamplay()) {
         SET_CLIENT_KEY_VALUE(clientIndex, infobuffer, "model", profile->skin);

         // use random colors
         SET_CLIENT_KEY_VALUE(clientIndex, infobuffer, "topcolor", va("%d", RandomLong(0, 255)));
         SET_CLIENT_KEY_VALUE(clientIndex, infobuffer, "bottomcolor", va("%d", RandomLong(0, 255)));
      }

      AddBot(pBot);

      pBot->m_pProfile->is_used = true;
   }
}
Example #16
0
/*
==============
UTIL_PlayerDecalTrace

A player is trying to apply his custom decal for the spray can.
Tell connected clients to display it, or use the default spray can decal
if the custom can't be loaded.
==============
*/
void UTIL_PlayerDecalTrace( TraceResult *pTrace, int playernum, int decalNumber, const bool bIsCustom )
{
	int index;
	
	if (!bIsCustom)
	{
		if ( decalNumber < 0 )
			return;

		index = gDecals[ decalNumber ].index;
		if ( index < 0 )
			return;
	}
	else
		index = decalNumber;

	if (pTrace->flFraction == 1.0)
		return;

	MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
		WRITE_BYTE( TE_PLAYERDECAL );
		WRITE_BYTE ( playernum );
		WRITE_COORD( pTrace->vecEndPos.x );
		WRITE_COORD( pTrace->vecEndPos.y );
		WRITE_COORD( pTrace->vecEndPos.z );
		WRITE_SHORT( (short)ENTINDEX(pTrace->pHit) );
		WRITE_BYTE( index );
	MESSAGE_END();
}
Example #17
0
static cell AMX_NATIVE_CALL find_ent_by_owner(AMX *amx, cell *params)  // native find_ent_by_owner(start_from_ent, classname[], owner_index); = 3 params
{
	int iEnt = params[1];
	int oEnt = params[3];
	// Check index to start searching at, 0 must be possible for iEnt.
	CHECK_ENTITY_SIMPLE(oEnt);

	edict_t *pEnt = INDEXENT2(iEnt);
	edict_t *entOwner = INDEXENT2(oEnt);

	//optional fourth parameter is for jghg2 compatibility
	const char* sCategory = NULL; 
	switch(params[4]){ 
		case 1: sCategory = "target"; break; 
		case 2: sCategory = "targetname"; break; 
		default: sCategory = "classname"; 
	}

	// No need to check if there is a real ent where entOwner points at since we don't access it anyway.

	int len;
	char* classname = MF_GetAmxString(amx, params[2], 0, &len);

	while (true) {
		pEnt = FIND_ENTITY_BY_STRING(pEnt, sCategory, classname);
		if (FNullEnt(pEnt)) // break and return 0 if bad
			break;
		else if (pEnt->v.owner == entOwner) // compare pointers
			return ENTINDEX(pEnt);
	}

	// If it comes here, the while loop ended because an ent failed (FNullEnt() == true)
	return 0;
}
Example #18
0
void CPlayer::Disconnect()
{
	ingame = false;
	initialized = false;
	authorized = false;
	teamIdsInitialized = false;

	if (newmenu != -1)
	{
		Menu *pMenu = g_NewMenus[newmenu];
		if (pMenu)
		{
			//prevent recursion
			newmenu = -1;
			menu = 0;
			executeForwards(pMenu->func, 
				static_cast<cell>(ENTINDEX(pEdict)),
				static_cast<cell>(pMenu->thisId),
				static_cast<cell>(MENU_EXIT));
		}
	}

	List<ClientCvarQuery_Info *>::iterator iter, end=queries.end();
	for (iter=queries.begin(); iter!=end; iter++)
	{
		unregisterSPForward((*iter)->resultFwd);
		delete [] (*iter)->params;
		delete (*iter);
	}
	queries.clear();

	menu = 0;
	newmenu = -1;
}
Example #19
0
int ClientConnect(edict_t *pPlayer, const char *pszName, const char *pszAddress, char szRejectReason[128])
{
	// Reset stuff:
	FUNUTIL_ResetPlayer(ENTINDEX(pPlayer));

	RETURN_META_VALUE(MRES_IGNORED, 0);
}
Example #20
0
void ParaGiveChute( edict_t *pEntity )
{

	// Gives this person a parachute
	ChuteState[ ENTINDEX( pEntity ) ] = 1;

}
Example #21
0
int SENTENCEG_PlayRndSz(edict_t *entity, const char *szgroupname, 
					  float volume, soundlevel_t soundlevel, int flags, int pitch)
{
	char name[64];
	int ipick;
	int isentenceg;

	if (!fSentencesInit)
		return -1;

	name[0] = 0;

	isentenceg = engine->SentenceGroupIndexFromName(szgroupname);
	if (isentenceg < 0)
	{
		Warning( "No such sentence group %s\n", szgroupname );
		return -1;
	}

	ipick = engine->SentenceGroupPick(isentenceg, name, sizeof( name ));
	if (ipick >= 0 && name[0])
	{
		int sentenceIndex = SENTENCEG_Lookup( name );
		CPASAttenuationFilter filter( GetContainingEntity( entity ), soundlevel );
		CBaseEntity::EmitSentenceByIndex( filter, ENTINDEX(entity), CHAN_VOICE, sentenceIndex, volume, soundlevel, flags, pitch );
		return sentenceIndex;
	}

	return -1;
}
Example #22
0
const char *TraceTexture(edict_t *pTextureEntity, const float *v1, const float *v2)
{
	PREPARE_VECTOR(v1);
	PREPARE_VECTOR(v2);
	FM_ENG_HANDLE(FM_TraceTexture, (Engine[FM_TraceTexture].at(i), (cell)ENTINDEX(pTextureEntity), p_v1, p_v2));
	RETURN_META_VALUE(mswi(lastFmRes), mlStringResult);
}
	DETOUR_DECL_MEMBER(void, CTFTankBoss_TankBossThink)
	{
		static CountdownTimer ctNodes;
		
		if (ctNodes.IsElapsed()) {
			ctNodes.Start(0.5f);
			
			ForEachEntityByRTTI<CPathTrack>([](CPathTrack *node){
				NDebugOverlay::Box(node->GetAbsOrigin(), Vector(-10.0f, -10.0f, -10.0f), Vector(10.0f, 10.0f, 10.0f),
					0xff, 0xff, 0xff, 0x80, 0.5f);
				NDebugOverlay::EntityTextAtPosition(node->GetAbsOrigin(), 0, CFmtStrN<16>("#%d", i), 0.5f, 0xff, 0xff, 0xff, 0xff);
				
				CPathTrack *next = node->GetNext();
				if (next != nullptr) {
					NDebugOverlay::HorzArrow(node->GetAbsOrigin(), next->GetAbsOrigin(), 3.0f, 0xff, 0xff, 0xff, 0xff, true, 0.5f);
				}
			});
		}
		
		auto tank = reinterpret_cast<CTFTankBoss *>(this);
		
		NDebugOverlay::EntityText(ENTINDEX(tank), 0, CFmtStrN<256>("%.1f%%", GetTankProgress(tank) * 100.0f),
			gpGlobals->interval_per_tick, 0xff, 0xff, 0xff, 0xff);
		
	//	NDebugOverlay::EntityText(ENTINDEX(tank), 0, CFmtStrN<256>("m_hCurrentNode:    #%d", ENTINDEX(*m_hCurrentNode)),
	//		gpGlobals->interval_per_tick, 0xff, 0xff, 0xff, 0xff);
	//	NDebugOverlay::EntityText(ENTINDEX(tank), 1, CFmtStrN<256>("m_iCurrentNode:    %d", *m_iCurrentNode),
	//		gpGlobals->interval_per_tick, 0xff, 0xff, 0xff, 0xff);
	//	NDebugOverlay::EntityText(ENTINDEX(tank), 2, CFmtStrN<256>("m_flTotalDistance: %.0f", *m_flTotalDistance),
	//		gpGlobals->interval_per_tick, 0xff, 0xff, 0xff, 0xff);
	//	NDebugOverlay::EntityText(ENTINDEX(tank), 3, CFmtStrN<256>("m_NodeDists[i]:    %.0f", (*m_NodeDists)[*m_iCurrentNode]),
	//		gpGlobals->interval_per_tick, 0xff, 0xff, 0xff, 0xff);
		
		DETOUR_MEMBER_CALL(CTFTankBoss_TankBossThink)();
	}
Example #24
0
bool CSetRuntimeAttributeValue::callme(edict_t *pEnt, CAttributeList *list, CEconItemAttributeDefinition *attrib,int value)
{
	int bret = 0;
	void *thefunc = m_func;

	int iEntityIndex = ENTINDEX(pEnt);

	if ( list && attrib && thefunc )
	{
		//*(DWORD*)&CAttributeListSetValue = (DWORD)SetRuntimeAttributeValue;
		//(*list.*CAttributeListSetValue)(attrib,value);
		//void *preveax1 = 0x0;
		
#ifdef _WIN32
		__asm 
		{
			mov ecx, list;
			push attrib;
			push value;
			call thefunc;
			mov bret, eax;
		};
#else
		FUNC_SET_ATTRIB_VALUE func = (FUNC_SET_ATTRIB_VALUE)thefunc;

		bret = func(list,attrib,value);
#endif
	}
Example #25
0
int SENTENCEG_PlaySequentialSz(edict_t *entity, const char *szgroupname, 
					  float volume, soundlevel_t soundlevel, int flags, int pitch, int ipick, int freset)
{
	char name[64];
	int ipicknext;
	int isentenceg;

	if (!fSentencesInit)
		return -1;

	name[0] = 0;

	isentenceg = engine->SentenceGroupIndexFromName(szgroupname);
	if (isentenceg < 0)
		return -1;

	ipicknext = engine->SentenceGroupPickSequential(isentenceg, name, sizeof( name ), ipick, freset);
	if (ipicknext >= 0 && name[0])
	{
		int sentenceIndex = SENTENCEG_Lookup( name );
		CPASAttenuationFilter filter( GetContainingEntity( entity ), soundlevel );
		CBaseEntity::EmitSentenceByIndex( filter, ENTINDEX(entity), CHAN_VOICE, sentenceIndex, volume, soundlevel, flags, pitch );
		return sentenceIndex;
	}
	
	return -1;
}
Example #26
0
static cell AMX_NATIVE_CALL find_ent_by_model(AMX *amx, cell *params) { 
	int iStart = params[1];
	int iLength, iLength2;
	char *szClass = MF_GetAmxString(amx, params[2], 0, &iLength);
	char *szModel = MF_GetAmxString(amx, params[3], 1, &iLength2);

	edict_t *pStart;

	if (iStart == -1)
	{
		pStart = NULL;
	} else {
		if (!is_ent_valid(iStart))
			pStart = NULL;
		else
			pStart = INDEXENT2(iStart);
	}

	edict_t *pEdict = FIND_ENTITY_BY_STRING(pStart, "classname", szClass);

	const char *check;

	while (pEdict && !FNullEnt(pEdict))
	{
		check = STRING(pEdict->v.model);
		if (!check || strcmp(check, szModel))
			pEdict = FIND_ENTITY_BY_STRING(pEdict, "classname", szClass);
		else
			return ENTINDEX(pEdict);
	}

	return 0;
}
Example #27
0
/*
===========
ClientDisconnect

called when a player disconnects from a server

GLOBALS ASSUMED SET:  g_fGameOver
============
*/
void ClientDisconnect( edict_t *pEntity )
{
	if (g_fGameOver)
		return;

	char text[256];
	sprintf( text, "- %s has left the game\n", STRING(pEntity->v.netname) );
	MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL );
		WRITE_BYTE( ENTINDEX(pEntity) );
		WRITE_STRING( text );
	MESSAGE_END();

	CSound *pSound;
	pSound = CSoundEnt::SoundPointerForIndex( CSoundEnt::ClientSoundIndex( pEntity ) );
	{
		// since this client isn't around to think anymore, reset their sound. 
		if ( pSound )
		{
			pSound->Reset();
		}
	}

// since the edict doesn't get deleted, fix it so it doesn't interfere.
	pEntity->v.takedamage = DAMAGE_NO;// don't attract autoaim
	pEntity->v.solid = SOLID_NOT;// nonsolid
	UTIL_SetOrigin ( &pEntity->v, pEntity->v.origin );

	g_pGameRules->ClientDisconnected( pEntity );
}
Example #28
0
void UTIL_EmitSoundSuit(edict_t *entity, const char *sample)
{
	float fvol;
	int pitch = PITCH_NORM;

	fvol = suitvolume.GetFloat();
	if (random->RandomInt(0,1))
		pitch = random->RandomInt(0,6) + 98;

	// If friendlies are talking, reduce the volume of the suit
	if ( !g_AIFriendliesTalkSemaphore.IsAvailable( GetContainingEntity( entity ) ) )
	{
		fvol *= 0.3;
	}

	if (fvol > 0.05)
	{
		CPASAttenuationFilter filter( GetContainingEntity( entity ) );
		filter.MakeReliable();

		EmitSound_t ep;
		ep.m_nChannel = CHAN_STATIC;
		ep.m_pSoundName = sample;
		ep.m_flVolume = fvol;
		ep.m_SoundLevel = SNDLVL_NORM;
		ep.m_nPitch = pitch;

		CBaseEntity::EmitSound( filter, ENTINDEX(entity), ep );
	}
}
Example #29
0
//
// make a body que entry for the given ent so the ent can be respawned elsewhere
//
// GLOBALS ASSUMED SET:  g_eoBodyQueueHead
//
void CopyToBodyQue(entvars_t *pev) 
{
	// DISCWAR: No corpses
	return;

	if (pev->effects & EF_NODRAW)
		return;

	entvars_t *pevHead	= VARS(g_pBodyQueueHead);

	pevHead->angles		= pev->angles;
	pevHead->model		= pev->model;
	pevHead->modelindex	= pev->modelindex;
	pevHead->frame		= pev->frame;
	pevHead->colormap	= pev->colormap;
	pevHead->movetype	= MOVETYPE_TOSS;
	pevHead->velocity	= pev->velocity;
	pevHead->flags		= 0;
	pevHead->deadflag	= pev->deadflag;
	pevHead->renderfx	= kRenderFxDeadPlayer;
	pevHead->renderamt	= ENTINDEX( ENT( pev ) );

	pevHead->effects    = pev->effects | EF_NOINTERP;
	//pevHead->goalstarttime = pev->goalstarttime;
	//pevHead->goalframe	= pev->goalframe;
	//pevHead->goalendtime = pev->goalendtime ;
	
	pevHead->sequence = pev->sequence;
	pevHead->animtime = pev->animtime;

	UTIL_SetOrigin(pevHead, pev->origin);
	UTIL_SetSize(pevHead, pev->mins, pev->maxs);
	g_pBodyQueueHead = pevHead->owner;
}
Example #30
0
void CBotVisibles::SetVisible(edict_t *pEdict, bool bVisible)
{
	static int iIndex;
	static int iByte;
	static int iBit;
	static int iFlag;

	iIndex = ENTINDEX(pEdict) - 1;
	iByte = iIndex / 8;
	iBit = iIndex % 8;
	iFlag = 1 << iBit;

	if (bVisible)
	{
		// visible now
		if (((*(m_iIndicesVisible + iByte) & iFlag) != iFlag))
			m_VisibleList.Push(pEdict);

		*(m_iIndicesVisible + iByte) |= iFlag;
	}
	else
	{
		// not visible anymore
		if (pEdict && ((*(m_iIndicesVisible + iByte) & iFlag) == iFlag))
			m_VisibleList.Remove(pEdict);

		*(m_iIndicesVisible + iByte) &= ~iFlag;
	}
}