[CAUTION] OnPlayerDeath (killerid can cause BUG!)
#5

Re-ordering the execution of code so it "doesn't matter" is not correct! You are still silent crashing the server, you are still possibly corrupting memory with your out-of-bounds array write. You should be checking if the killerid is invalid by using:

pawn Код:
if (killerid != INVALID_PLAYER_ID)
or
pawn Код:
if (IsPlayerConnected(killerid))
The correct way this code should be written is like so (also used the increment/decrement operators to shorten it),

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(killerid, playerid, reason);

    PlayerInfo[playerid][pDeaths]++;
    PlayerInfo[playerid][pScore]--;

    SetPlayerScore(playerid, GetPlayerScore(playerid) - 1);

    if (killerid != INVALID_PLAYER_ID)
        PlayerInfo[killerid][pScore]++;
        PlayerInfo[killerid][pKills]++;
        PlayerInfo[killerid][pGameKills]++;

        SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
    }

    return 1;
}
Reply


Messages In This Thread
[CAUTION] OnPlayerDeath (killerid can cause BUG!) - by Rolyy - 26.07.2011, 06:48
Re: [CAUTION] OnPlayerDeath (killerid can cause BUG!) - by System64 - 26.07.2011, 06:58
Re: [CAUTION] OnPlayerDeath (killerid can cause BUG!) - by Rolyy - 26.07.2011, 07:01
Re: [CAUTION] OnPlayerDeath (killerid can cause BUG!) - by System64 - 26.07.2011, 07:04
Re: [CAUTION] OnPlayerDeath (killerid can cause BUG!) - by Simon - 26.07.2011, 07:42

Forum Jump:


Users browsing this thread: 1 Guest(s)