OnPlayerDeath
#1

The system does the opposite from what I wanted, if all SWAT team members die it says SWAT won and if all Criminals team members die it says Criminals won.
What's wrong in this function?
PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    
SendDeathMessage(killeridplayeridreason);
    
SetPlayerScore(killeridGetPlayerScore(killerid)+1);
    if(
gTeam[playerid] == TEAM_SWATgSWAT--;
    else if(
gTeam[playerid] == TEAM_CRIMINALSgCriminals--;
    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 && gSWAT 0)
    {
        
gSpectating[playerid] = 1;
        
SetToSpectate(playerid);
    }
    
CancelSpectate(playerid);
    if(
gRounds >= 6GameModeExit();
    return 
1;

Reply
#2

Try like:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(killerid, playerid, reason);
    SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
    if(gTeam[playerid] == TEAM_SWAT) return gSWAT--;
    else if(gTeam[playerid] == TEAM_CRIMINALS) return 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);
    if(gRounds >= 6) GameModeExit();
    return 1;
}
Reply
#3

Ain't working just like I thought, return will just stop the function after gSWAT--; or gCriminals--;
Reply
#4

Try this
pawn Код:
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);
    if(gRounds >= 6) GameModeExit();

    return 1;
}
Reply
#5

Still not working
Reply
#6

Please help?
Reply
#7

i think the onplayerdeath code is alright,
but somewhere else in your script you define criminals as swat and the other way around
Reply
#8

jop9888 is right... if u made swat team meber as crimal and crimal as swat..
just tmp fix u reallllly needed
PHP код:
public OnPlayerDeath(playeridkilleridreason

    
SendDeathMessage(killeridplayeridreason); 
    
SetPlayerScore(killeridGetPlayerScore(killerid)+1); 
    if(
gTeam[playerid] == TEAM_SWATgSWAT--; 
    else if(
gTeam[playerid] == TEAM_CRIMINALSgCriminals--; 
    if(
gSWAT== 0
    { 
        
SendClientMessageToAll(COLOR_BLUE"SWAT has won this round!"); 
        
gRounds++; 
        
SetEveryoneToSpawn(playerid); 
    } 
    else if(
gCriminals  == 0
    { 
        
SendClientMessageToAll(COLOR_RED"Criminals has won this round!"); 
        
gRounds++; 
        
SetEveryoneToSpawn(playerid); 
    } 
    if(
gCriminals && gSWAT 0
    { 
        
gSpectating[playerid] = 1
        
SetToSpectate(playerid); 
    } 
    
CancelSpectate(playerid); 
    if(
gRounds >= 6GameModeExit(); 
    return 
1

Reply
#9

Tried this and still not working for some reason O:
Reply
#10

I realized there was no problem, since I was the only one online then both gCriminals and gSWAT were set to 0 and gSWAT was the first one to be checked.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)