Coding trigger_camera Created 11 years ago2013-04-13 10:56:07 UTC by Zhouy Zhouy

Created 11 years ago2013-04-13 10:56:07 UTC by Zhouy Zhouy

Posted 11 years ago2013-04-13 10:56:07 UTC Post #313311
I'm having a trigger_camera for a Multiplayer map, and want all players to be able to be affected when it's triggered instead of just 1. I know a way how to do this with just entities, but I want to do this with coding instead.. Anyway , code looks like this from triggers.cpp:

void CTriggerCamera::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
if ( !ShouldToggle( useType, m_state ) )
return;
// Toggle state
m_state = !m_state;
if (m_state == 0)
{
	m_flReturnTime = gpGlobals->time;
	return;
}
if ( !pActivator || !pActivator->IsPlayer() )
{
	pActivator = CBaseEntity::Instance(g_engfuncs.pfnPEntityOfEntIndex( 1 ));
}
I guess this says that it's the activator of the camera that gets affected. What does the g_engfuncs.pfnPEntityOfEntIndex really do? Some change in this code to make all players see through camera? Still learning :P
Posted 11 years ago2013-04-14 14:56:55 UTC Post #313317
EntityOfEntIndex gets the first entity that's loaded into the engine, which in singleplayer is the player entity, in multiplayer that obviously doesn't work.

You have to loop through all of them.

 // search the world for players...
   for (int i = 1; i <= gpGlobals->maxClients; i++)
   {
      CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
      // skip invalid players
      if (!pPlayer)
         continue;

      pActivator = pPlayer;

     //All the rest of the code here - Must be within the loop
   }
It's probably more efficient to do it with entities, tho.
ChickenFist ChickenFist<Witty Title>
Posted 11 years ago2013-04-17 16:28:22 UTC Post #313329
Okay, thanks for answering again, tried simular before but didn't get it right, but I will try again. I have one more question, when a player cross a trigger, I want the activator to get different default_fov value. Tried with 'CVAR_SET_FLOAT( "default_fov", 120 );' but that will only make the Client have his default_fov changed, no matter which player that triggers it. Have any clue? I appreciate that you take time to answer my questions, thanks.
Posted 11 years ago2013-04-17 19:43:18 UTC Post #313332
Changing fov is easy.

CBasePlayer *pPlayer = dynamic_cast<CBasePlayer *>(pActivator);
pPlayer->pev->fov = 120;

No problems :)
ChickenFist ChickenFist<Witty Title>
Posted 11 years ago2013-04-18 17:19:18 UTC Post #313334
EntityOfEntIndex gets the first entity that's loaded into the engine, which in singleplayer is the player entity, in multiplayer that obviously doesn't work.

You have to loop through all of them.

// search the world for players...
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
// skip invalid players
if (!pPlayer)
continue;

pActivator = pPlayer;

//All the rest of the code here - Must be within the loop
}

It's probably more efficient to do it with entities, tho.
hmmm i think it would be better:

if( pPlayer )
{
pActivator = pPlayer;
}

than

if (!pPlayer)
continue;

pActivator = pPlayer;
Posted 11 years ago2013-04-18 21:34:58 UTC Post #313336
Doesn't matter, the end result is the same. Syntax preference, I guess.
ChickenFist ChickenFist<Witty Title>
You must be logged in to post a response.