OnPlayerDeath Not getting called.
#1

Hello,

I was playing in my server and i fall from the building i found that OnPlayerDeath is not getting called when i die.I tried to debug by putting a print message which will get printed when i die and i found that its wasnt got printed when i died.

It gets called if someone other player kill me.
Reply
#2

You MUST check whether killerid equals INVALID_PLAYER_ID before using it in an array, as it will cause the script to stop. See example above.

If you don't have a check and that you have an array, it will stop.
Reply
#3

Quote:
Originally Posted by Vukilore
Посмотреть сообщение
You MUST check whether killerid equals INVALID_PLAYER_ID before using it in an array, as it will cause the script to stop. See example above.

If you don't have a check and that you have an array, it will stop.
And what i am supposed to do after checking if killerid = INVALID_PLAYER_ID.. ? Because i am talking about dying without a killer.Ex:Falling from a building etc/
Reply
#4

Could I see your OnPlayerDeath code?

I think there's something like this:

pawn Код:
if(killerid == INVALID_PLAYER_ID)
    return 1;
which blocks it.
Reply
#5

Quote:
Originally Posted by Black Wolf
Посмотреть сообщение
And what i am supposed to do after checking if killerid = INVALID_PLAYER_ID.. ? Because i am talking about dying without a killer.Ex:Falling from a building etc/
If you kill yourself (fall from a building), then it will be the case that killerid = INVALID_PLAYER_ID, but not playerid (since you commit suicide but not being killed by the others). If it is not handled correctly it can cause silent run-time errors, which makes the callback to be terminated before some of your code.
You should check that INVALID_PLAYER_ID before using something like playerlevel[playerid], because it can cause array index out of bounds error. I think that's what Vukilore said.

Btw, to ensure that it is a scripting problem, where does your print message put in the callback?
Reply
#6

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][Kills]++;
    PlayerInfo[playerid][Deaths]++;
    SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
    OnWeaponDrop(playerid);
    SendClientMessage(playerid, -1, "I am called.");
    if(killerid != TopKiller)
    {
        TopKiller = killerid;
        TopKills = 0;
    }
    TopKills++;
    if(TopKills == 5)
    {
        new String[128];
        format(String,sizeof(String),"You have filled the kills board with your name and recived a 25000$ bonus!");
        SendClientMessage(playerid,0xFF0000DD,String);
        GivePlayerMoney(killerid,25000);
        TopKills = 0;
    }
   
    if(playerid == CashboxOwner)
    {
        new str[128], pName[MAX_PLAYER_NAME];
        GetPlayerPos(playerid, CashboxX, CashboxY, CashboxZ);
        GetPlayerName(playerid, pName, sizeof(pName));
        format(str, 128, "Cashbox-Owner %s (ID: %d) has died and droped the cashbox!", pName, playerid);
        SendClientMessageToAll(0xFFD700AA, str);
        CashboxPickup = CreatePickup(1210, 3, CashboxX, CashboxY, CashboxZ);

        CashboxOwner = INVALID_PLAYER_ID;
        if(mode == 1)
        {
            for(new i; i<MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                    SetPlayerCheckpoint(i, CashboxX, CashboxY, CashboxZ, 1);
                }
            }
        }
    }
   
    if(PlayerInfo[playerid][InDerby] == 1)
    {
        SendFMessageToAll(COL_RED,"« Derby » "CBLUE"%s has died while in the derby!",PlayerName(playerid));
        derbyplayers--;
        PlayerInfo[playerid][InDerby] = 0;
    }
   
       
    if(Joined[playerid] == true)
    {
        JoinCount--;
        Joined[playerid] = false;
        DestroyVehicle(CreatedRaceVeh[playerid]);
        DisablePlayerRaceCheckpoint(playerid);
        TextDrawHideForPlayer(playerid, RaceInfo[playerid]);
        TextDrawHideForPlayer(playerid, RaceBox);
        TextDrawHideForPlayer(playerid, RaceLogo);
        TextDrawHideForPlayer(playerid, RaceOut1);
        TextDrawHideForPlayer(playerid, RaceOut2);
        CPProgess[playerid] = 0;
        KillTimer(InfoTimer[playerid]);
        #if defined RACE_IN_OTHER_WORLD
        SetPlayerVirtualWorld(playerid, 0);
        #endif
    }
    if(BuildRace == playerid+1) BuildRace = 0;

   
    return 1;
}
This is my onplayerdeath code and when i die myself death won't increase i am serisouly not getting your point friend because i haven't met this problem before.
Reply
#7

Basically you have to do this:
pawn Код:
if(IsPlayerConnected(killerid))
{
    anarray[killerid] = 1;
}
//OR
if(killerid != INVALID_PLAYER_ID)
{
    anarray[killerid] = 1;
}
Reply
#8

So you mean if i die myself then i ll be getting killerid not playerid ?
Reply
#9

No, if you kill yourself then killerid contains INVALID_PLAYER_ID, not your own ID.
Reply
#10

Quote:
Originally Posted by Black Wolf
Посмотреть сообщение
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][Kills]++;
    return 1;
}
Basically, when you suicide, you're crashing the callback right away with a run time error "index out of bounds", as killerid value equals INVALID_PLAYER_ID, which value is 0xFFFF (65535 in decimal system): quite FAR from playerid 499 isn't it?

Do the check "if (killerid!=INVALID_PLAYER_ID)" before doing ANYTHING with killerid, really.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)