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

I want to warn those who are currently reading this topic, and those who are not aware of this bug so they can help others. Using killerid in top of your OnPlayerDeath function can cause bugs, once the playerid suicides/dies.

First I noticed there was something wrong with my OnPlayerDeath function because it only showed the SendDeathMessage and it didnt fully finish the function, so I was trying to find it out for longer than 40 minutes why it would work. And suddenly it just hitted me after removing everything involved with killerid, and it worked just fine after that. So I've posted this Warning message on forums.


Two Example: Once playerid suicides/dies (killerid not involved)
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(killerid, playerid, reason);
    PlayerInfo[playerid][pDeaths] = PlayerInfo[playerid][pDeaths] + 1;
    PlayerInfo[killerid][pScore] = PlayerInfo[killerid][pScore] + 1; /*the function will stop/end
here. Because killerid is not involved in playerids suicide/death.*/

    PlayerInfo[killerid][pKills] = PlayerInfo[killerid][pKills] + 1; //line wont be reached.
    PlayerInfo[killerid][pGameKills] = PlayerInfo[killerid][pGameKills] + 1; //line wont be reached.
    PlayerInfo[playerid][pScore] = PlayerInfo[playerid][pScore] - 1; //Etc.
    SetPlayerScore(playerid, GetPlayerScore(playerid) - 1);
    return 1;
}
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(killerid, playerid, reason);
    PlayerInfo[playerid][pDeaths] = PlayerInfo[playerid][pDeaths] + 1;
    PlayerInfo[playerid][pScore] = PlayerInfo[playerid][pScore] - 1;
    SetPlayerScore(playerid, GetPlayerScore(playerid) - 1);
    PlayerInfo[killerid][pScore] = PlayerInfo[killerid][pScore] + 1; /*the function will stop/end
here. Because killerid is not involved in playerids suicide/death.*/

    PlayerInfo[killerid][pKills] = PlayerInfo[killerid][pKills] + 1; //line wont be reached.
    PlayerInfo[killerid][pGameKills] = PlayerInfo[killerid][pGameKills] + 1; //line wont be reached.
    return 1; //Etc.
}

This post is just to warn the helpers that are NOT AWARE of this bug, so they can assist others.
Reply
#2

try this

pawn Код:
PlayerInfo[playerid][pDeaths] = PlayerInfo[playerid][pDeaths] =+ 1;
    PlayerInfo[killerid][pScore] = PlayerInfo[killerid][pScore] =+ 1; /*the function will stop/end
here. Because killerid is not involved in playerids suicide/death.*/

    PlayerInfo[killerid][pKills] = PlayerInfo[killerid][pKills] =+ 1; //line wont be reached.
    PlayerInfo[killerid][pGameKills] = PlayerInfo[killerid][pGameKills] =+ 1; //line wont be reached.
    PlayerInfo[playerid][pScore] = PlayerInfo[playerid][pScore] =- 1; //Etc.
Reply
#3

Try what? Have you even read the post and what i've trying to explain?
I don't need help, this is just to inform others.

Quote:
Originally Posted by Rolyy
Посмотреть сообщение
This post is just to warn the helpers that are NOT AWARE of this bug, so they can assist others.
Reply
#4

look at the code please, why you post if you don't need help? You just showing how you do that and that is little buged ha?

=+ 1
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)