OnPlayerDeath problem.
#1

Hi. I'm adding a lot of code into OnPlayerDeath but when I type /kill in game, im dying but codes are doesn't working :/ By the way I don't use GivePlayerMoney to anything. I made a special cash value for it and players can view their pocket cash with /stats, anyways code here. Any idea about this ?

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]+=1; //for stats
    PlayerInfo[playerid][pDeaths]+=1; //for stats

    new BonusCash = PlayerInfo[playerid][pCash]; // Special cash value, not about GivePlayerMoney.
    PlayerInfo[killerid][pCash]+=BonusCash; //player's cash to killer

    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash] = 0); // reset dead player's special cash value
    INI_Close(File);

    new Float:dX, Float:dY, Float:dZ; // cutscene
    GetPlayerPos( playerid, dX, dY, dZ );
    SetPlayerCameraPos(playerid,dX+8,dY,dZ+2);
    SetPlayerCameraLookAt(playerid, dX, dY, dZ);
   
    SendDeathMessage(killerid, playerid, reason);
   
    new string[50];
    new deadman[MAX_PLAYER_NAME];
    GetPlayerName(playerid, deadman, sizeof(deadman));
    format(string, sizeof(string), "You have killed %s", deadman);
    GameTextForPlayer(killerid, string, 3000, 1);
    new killerman[MAX_PLAYER_NAME];
    GetPlayerName(killerid, killerman, sizeof(killerman));
    format(string, sizeof(string), "You have been killed by %s", killerman);
    GameTextForPlayer(playerid, string, 3000, 1);
    return 1;
}
Reply
#2

pawn Код:
PlayerInfo[killerid][pKills] ++; //for stats
PlayerInfo[playerid][pDeaths] ++; //for stats

new BonusCash = PlayerInfo[killerid][pCash];
Try this
Reply
#3

I've said this in reply to about 69 topics about this.

You need to check whether killerid != INVALID_PLAYER_ID before you do ANYTHING with it. Especially arrays. Using [killerid] in arrays will crash your script if killerid is INVALID_PLAYER_ID!
Reply
#4

Quote:
Originally Posted by MP2
Посмотреть сообщение
I've said this in reply to about 69 topics about this.

You need to check whether killerid != INVALID_PLAYER_ID before you do ANYTHING with it. Especially arrays. Using [killerid] in arrays will crash your script if killerid is INVALID_PLAYER_ID!
Firstly I am not good about pawno and English. I mean when a player kill me, the codes are working succesfully but when I type /kill, the codes are doesn't working, anyways.
Reply
#5

That's because if you just die without another player being responsible, killerid = INVALID_PLAYER_ID, and you can't access PlayerInfo[INVALID_PLAYER_ID][pKills]

Just use this:

pawn Код:
if(killerid != INVALID_PLAYER_ID)  PlayerInfo[killerid][pKills]++;
Reply
#6

Thanks, its working;

pawn Код:
if(killerid == INVALID_PLAYER_ID)
    {
        SendDeathMessage(INVALID_PLAYER_ID, playerid, reason);
        PlayerInfo[playerid][pDeaths]+=1; //for stats
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash] = 0); // reset dead player's special cash value
        INI_Close(File);
        new Float:dX, Float:dY, Float:dZ; // cutscene
        GetPlayerPos( playerid, dX, dY, dZ );
        SetPlayerCameraPos(playerid,dX+8,dY,dZ+2);
        SetPlayerCameraLookAt(playerid, dX, dY, dZ);
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)