[19:27:49] [debug] Run time error 4: "Array index out of bounds" [19:27:49] [debug] Accessing element at index 65535 past array upper bound 499 [19:27:49] [debug] AMX backtrace: [19:27:49] [debug] #0 0001f4e0 in ?? (0, 65535, 54) from Accounts1.0.amx [19:27:49] [debug] #1 0000551c in public OnPlayerDeath (0, 65535, 54) from Accounts1.0.amx
public OnPlayerDeath(playerid, killerid, reason)
{
pInfo[killerid][Kills] += 1;
pInfo[playerid][Deaths] += 1;
SpecStats = 0;
pInfo[playerid][Wasted]++;
GiveXP(killerid, -100); //return SCM(playerid, pink, "You have lost 100 XP for killing a player!");
return 1;
}
if(pInfo[playerid][Wasted] == 1)
{
SetPlayerPos(playerid, 1579.0249,1769.8119,10.8203); //
SetPlayerFacingAngle(playerid,201.1649);
pInfo[playerid][Wasted] = 0;
return 1;
}
CMD:die(playerid, params[])
{
SetPlayerHealth(playerid, 0);
SCM(playerid, red, "You have committed suicide");
pInfo[playerid][Wasted]= 1;
getdate(lyear, lmonth, lday);
gettime(lhour, lminute, lsecond);
GetPlayerName(ID, pName, sizeof(pName));
format(lstr, sizeof lstr, "(COMMAND)(%02d/%02d/%04d %02d:%02d:%02d):%s(%d): has used /die\r\n", lyear, lmonth, lday, lhour, lminute, lsecond,pName, ID);
AllLogs(lstr);
return 1;
}
ACMD:kill(playerid, params[])
{
if (pInfo[playerid][Adminlevel] < 1) return 0;
new reason[128];
if(sscanf(params, "us[50]", ID, reason)) return SCM(playerid, orange, "Kill a player: /kill <ID> <Reason>");
if(ID == IPI)return SCM(playerid, red, "*Player is not connected.");
GetPlayerName(playerid, pName, sizeof(pName));
GetPlayerName(ID, pName, sizeof(pName));
SetPlayerHealth(ID, 0);
format(ustr, sizeof(ustr), "%s %s has killed you for %d", AdminLevelName(playerid), pName, pName, reason);
SCM(ID, red, ustr);
format(ustr,sizeof(ustr),"*You have killed %s", pName);
SCM(playerid, Lblue, ustr);
return 1;
}
Originally Posted by Wiki
You MUST check whether 'killerid' is valid (not INVALID_PLAYER_ID) before using it in an array (or really anywhere), as it will cause the OnPlayerDeath script to crash (not the entire script). This is because INVALID_PLAYER_ID is defined as 65535, and if an array only has 'MAX_PLAYERS' elements, e.g. 500, you're trying to access an index that is above 499, which is out of bounds.
|
if(killerid==INVALID_PLAYER_ID) return 0;
if(killerid != INVALID_PLAYER_ID)
{
// code
}
SpecStats = 0; //????
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID)
{
pInfo[killerid][Kills] += 1;
GiveXP(killerid, -100);
}
pInfo[playerid][Deaths] += 1;
pInfo[playerid][Wasted]++;
return true;
}