Spec problem
#1

Well I tried to do a function which will do that if there is still someone in your team and you die then it sets you to spec him, it's just not working.
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(killerid, playerid, reason);
    SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
    if(gTeam[playerid] == TEAM_SWAT && gSWAT > 0) gSWAT--;
    else if(gTeam[playerid] == TEAM_CRIMINALS && gCriminals > 0) gCriminals--;
    if(gCriminals <= 0)
    {
        SendClientMessageToAll(COLOR_BLUE, "SWAT has won this round!");
        gRounds++;
        SetEveryoneToSpawn(playerid);
    }
    else if(gSWAT <= 0)
    {
        SendClientMessageToAll(COLOR_RED, "Criminals has won this round!");
        gRounds++;
        SetEveryoneToSpawn(playerid);
    }
    if(gCriminals > 0 && gSWAT > 0)
    {
        gSpectating[playerid] = 1;
        SetToSpectate(playerid);
    }
    CancelSpectate(playerid);
    return 1;
}

SetToSpectate(playerid)
{
	for(new i; i < 10; i++)
	{
     	if(!IsPlayerConnected(i)) continue;
	    if(gSpectating[i]) continue;
	    if(gTeam[i] != gTeam[playerid]) continue;
	    new string[128];
	    TogglePlayerSpectating(playerid, 1);
    	PlayerSpectatePlayer(playerid, i);
     	new Name[MAX_PLAYER_NAME]; GetPlayerName(i, Name, sizeof(Name));
		format(string, sizeof(string), "[Info:] You are now spectating %s", Name);
		SendClientMessage(playerid, COLOR_WHITE, string);
	}
	return 1;
}
Reply
#2

Why do you start spectate mode here:

pawn Код:
if(gCriminals > 0 && gSWAT > 0)
    {
        gSpectating[playerid] = 1;
        SetToSpectate(playerid);
    }
when you cancel it two lines below again:
pawn Код:
CancelSpectate(playerid);
I guess CancelSpectate has to be removed, or an 'else' has to be placed before, depending on your other stuff. The else might be the one to fit better.
Reply
#3

No, it has nothing to do with it, I just named it CancelSpectate, when it's basically just running a loop to check if any player is spectating the player who died and if yes it cancels their spec.
Yeah I should have named it CheckSpec or something but still.. it has nothing to do with this.
Reply
#4

Alright. Try to set a timer of 5 seconds at OnPlayerDeath, which will set the player to spectate mode after those 5 seconds. Maybe you can't set a player to spectate mode directly after the player died. If this works then, try to lower the time to 4,3,2,1,0.5,... seconds.
If this does not work, could you show the CancelSpecate please.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)