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;
}
PlayerInfo[killerid][pKills] ++; //for stats
PlayerInfo[playerid][pDeaths] ++; //for stats
new BonusCash = PlayerInfo[killerid][pCash];
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! |
if(killerid != INVALID_PLAYER_ID) PlayerInfo[killerid][pKills]++;
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;
}