31.08.2011, 23:38
Hey,
I have the following code:
But sometimes it goes in the -1, -2, or 0 (Nobody).
It need to start spectating on the first not yourself id, When there isnt another player online, than it need to say 'Nobody online' or something.
I'll hope somebody can help me.
Thanks!
I have the following code:
pawn Код:
stock SpectateOn(playerid)
{
TogglePlayerSpectating(playerid, 1);
for(new i=0; i<MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || i==playerid) continue;
if(IsPlayerInAnyVehicle(i))
{
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(i));
}
else
{
PlayerSpectatePlayer(playerid, i);
}
}
IsPlayerSpectating[playerid] = true;
new str[128];
format(str, 128, "You are now spectating %s (ID:%d).", GetName(SpectatedPlayer[playerid]), SpectatedPlayer[playerid]);
SendClientMessage(playerid, COLOR_FADE1, str);
}
stock SpectateOff(playerid)
{
TogglePlayerSpectating(playerid, 0);
SpectatedPlayer[playerid] = 0;
IsPlayerSpectating[playerid] = false;
}
stock SpectateNext(playerid)
{
SpectatedPlayer[playerid]++;
for(new i=SpectatedPlayer[playerid]; i<MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || i==playerid) continue;
if(IsPlayerInAnyVehicle(i))
{
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(i));
}
else
{
PlayerSpectatePlayer(playerid, i);
}
SpectatedPlayer[playerid] = i;
break;
}
new str[128];
format(str, 128, "You are now spectating %s (ID:%d).", GetName(SpectatedPlayer[playerid]), SpectatedPlayer[playerid]);
SendClientMessage(playerid, COLOR_FADE1, str);
}
stock SpectatePrevious(playerid)
{
SpectatedPlayer[playerid]--;
for(new i=SpectatedPlayer[playerid]; i>-1; i--)
{
if(!IsPlayerConnected(i) || i==playerid) continue;
if(IsPlayerInAnyVehicle(i))
{
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(i));
}
else
{
PlayerSpectatePlayer(playerid, i);
}
SpectatedPlayer[playerid] = i;
break;
}
new str[128];
format(str, 128, "You are now spectating %s (ID:%d).", GetName(SpectatedPlayer[playerid]), SpectatedPlayer[playerid]);
SendClientMessage(playerid, COLOR_FADE1, str);
}
stock GetName(i)
{
new name[24];
GetPlayerName(i, name, 24);
return name;
}
It need to start spectating on the first not yourself id, When there isnt another player online, than it need to say 'Nobody online' or something.
I'll hope somebody can help me.
Thanks!