SA-MP Forums Archive
OnPlayerDeath - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerDeath (/showthread.php?tid=335727)



OnPlayerDeath - Tomer!.$ - 19.04.2012

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;




Re: OnPlayerDeath - sleepysnowflake - 19.04.2012

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;
}



Re : OnPlayerDeath - Tomer!.$ - 19.04.2012

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


Re: OnPlayerDeath - ViniBorn - 19.04.2012

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;
}



Re : OnPlayerDeath - Tomer!.$ - 20.04.2012

Still not working


Re : OnPlayerDeath - Tomer!.$ - 20.04.2012

Please help?


Re: OnPlayerDeath - jop9888 - 20.04.2012

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


Re: OnPlayerDeath - Unknown1234 - 20.04.2012

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




Re : OnPlayerDeath - Tomer!.$ - 20.04.2012

Tried this and still not working for some reason O:


Re : OnPlayerDeath - Tomer!.$ - 20.04.2012

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.