Hello, someone to help me with this problem.
I want to assign the last 2 live players a different variable for each 1.
But I assigned the variable to a dead player
What am I doing wrong?
Цитата:
Код:
int iNumbers, iPlayers[33];
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayerLoop = (CBasePlayer*)UTIL_PlayerByIndex(i);
if (pPlayerLoop)
{
if (pPlayerLoop->IsAlive())
{
iNumbers++;
}
iPlayers[iNumbers] = i;
}
}
CBasePlayer *pPlayer1 = (CBasePlayer*)UTIL_PlayerByIndex(iPlayers[1]);
CBasePlayer *pPlayer2 = (CBasePlayer*)UTIL_PlayerByIndex(iPlayers[2]);
if (pPlayer1 && pPlayer2)
{
printf("Player1: %d\nPlayer2: %d\n", pPlayer1->entindex(), pPlayer2->entindex());
}
//Example:
if (pPlayer1)
{
pPlayer1->pev->health = 200;
}
if (pPlayer2)
{
pPlayer2->pev->health = 250;
}