14.04.2012, 15:00
(
Last edited by Stepashka; 15/04/2012 at 03:48 AM.
)
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
for(new x = 0; x < MAX_PLAYERS; x++)
{
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Player[x][gSpectateID] == playerid)
{
if(Player[x][pTeam] == T_REF)
AdvanceSpectate(x);
else
AdvanceTeamSpectate(x);
}
}
return true;
}
public OnPlayerDeath(playerid, killerid, reason)
{
for(new x = 0; x < MAXPLAYER; x++)
{
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Player[x][gSpectateID] == playerid)
{
if(Player[x][pTeam] == T_REF)
AdvanceSpectate(x);
else
AdvanceTeamSpectate(x);
}
}
return true;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
for (new x; x != MAXPLAYER; ++x)
{
if(IsPlayerConnected(x) && GetPlayerState(x) == PLAYER_STATE_SPECTATING && Player[x][gSpectateID] == playerid)
SetPlayerInterior(x, newinteriorid);
}
return true;
}
public OnPlayerEnterVehicle(playerid, vehicleid)
{
for (new x; x != MAXPLAYER; ++x)
{
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Player[x][gSpectateID] == playerid)
{
TogglePlayerSpectating(x, 1);
PlayerSpectateVehicle(x, vehicleid);
}
}
return true;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
for (new x; x != MAXPLAYER; ++x)
{
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Player[x][gSpectateID] == playerid )
{
TogglePlayerSpectating(x, 1);
PlayerSpectatePlayer(x, playerid);
}
}
return true;
}
public StartSpectate(playerid, specid)
{
SetPlayerInterior(playerid, GetPlayerInterior(specid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specid));
TogglePlayerSpectating(playerid, 1);
if(IsPlayerInAnyVehicle(specid))
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specid));
else
PlayerSpectatePlayer(playerid, specid);
Player[playerid][gSpectateID] = specid;
Player[playerid][Specing] = true;
Player[playerid][pPlaying] = false;
TextDrawShowForPlayer(playerid, Player[playerid][SpecText]);
UpdatePlayer(playerid);
return true;
}
stock StopSpectate(playerid)
{
KillTimer(SUT[playerid]);
TogglePlayerSpectating(playerid, 0);
Player[playerid][Specing] = false;
Player[playerid][gSpectateID] = INVALID_PLAYER_ID;
TextDrawHideForPlayer(playerid, Player[playerid][SpecText]);
return true;
}
stock adminspec_strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
index++;
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
AdvanceTeamSpectate(playerid)
{
if(GetActivePlayersOnTeam(Player[playerid][pTeam]) < 1)return StopSpectate(playerid);
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Player[playerid][gSpectateID] != INVALID_PLAYER_ID)
{
for (new x = Player[playerid][gSpectateID] + 1; x <= MAXPLAYER; x++)
{
if(x >= MAXPLAYER)x = 0;
if (IsPlayerConnected(x) && x != playerid && Player[x][pPlaying] == true && Player[x][pTeam] == Player[playerid][pTeam])
{
if (GetPlayerState(x) == PLAYER_STATE_SPECTATING && Player[x][gSpectateID] != INVALID_PLAYER_ID && Player[x][pPlaying] == true || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
{
continue;
}
else
{
StartSpectate(playerid, x);
return true;
}
}
}
}
return StopSpectate(playerid);
}
GetActivePlayersOnTeam(team)
{
new players = 0;
foreach(i)
{
if(Player[i][pTeam] == team && Player[i][pPlaying] == true)
players++;
}
return players;
}
AdvanceSpectate(playerid)
{
if(PlayersAvailable() < 1){StopSpectate(playerid); return true;}
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Player[playerid][gSpectateID] != INVALID_PLAYER_ID)
{
for(new x = Player[playerid][gSpectateID]+1; x <= MAXPLAYER; x++)
{
if(x == MAXPLAYER)x = 0;
if(IsPlayerConnected(x) && x != playerid && Player[x][pPlaying] == true)
{
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Player[x][gSpectateID] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
{
continue;
}
else
{
StartSpectate(playerid, x);
break;
}
}
}
}
return true;
}
PlayersAvailable()
{
new players = 0;
foreach(i) if(Player[i][pPlaying] == true && Player[i][pSpawned] && Player[i][Specing] == false && GetPlayerState(i) != PLAYER_STATE_SPECTATING && Player[i][pTeam] != T_REF)
players++;
return players;
}