Having trouble with some commands
#1

Hello, I've just been testing my commands to make sure all of them are working fine and are at their top, but as I was testing I was watching my command panel and the debug kept picking errors on death, I've through it and I have no idea what is wrong with it, I will show you itand see if you can spot what I have been doing wrong.

I have a problem when I die or when anyone dies, even if I use a command to kill them this error keeps happening,
Код:
[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
I have been over this like 300 times and couldn't see what is wrong, here is everything to do with death,
pawn Код:
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;
}
OnPlayerSpawn
pawn Код:
if(pInfo[playerid][Wasted] == 1)
    {
        SetPlayerPos(playerid, 1579.0249,1769.8119,10.8203); //
        SetPlayerFacingAngle(playerid,201.1649);
        pInfo[playerid][Wasted] = 0;
        return 1;
    }
pawn Код:
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;
}
pawn Код:
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;
}
Like I said, i've been through this alot and couldn't find the error. It would be amazing if you are able to help me out here! this is being a real pain in the ass Thank you guys!
Reply
#2

"Accessing element at index 65535 past array upper bound 499"
This seems to be caused by a loop that doesn't stop through playerids. ( 499 is SA-MP default max_players ) 65635 is max a loop can reach I think. So yeah, check out your loop and add i<MAX_PLAYERS;

Also change ACMD to CMD in kill command, unless you have ACMD defined ( show us its code if possible )
Reply
#3

In OnPlayerDeath, who will the killerid be if you suicide? That's why you're crashing.
You need to perform a check to make sure that the killerid isn't INVALID_PLAYER_ID.
Specified on the wiki aswell.
Quote:
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.
Reply
#4

How will I do this check?
Reply
#5

Код:
if(killerid==INVALID_PLAYER_ID) return 0;
Reply
#6

I just told you, make sure killerid isn't INVALID_PLAYER_ID?
pawn Код:
if(killerid != INVALID_PLAYER_ID)
{
    // code
}
Again, it's also shown in the wiki.
Reply
#7

Код:
SpecStats = 0; //????
PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    if(
killerid != INVALID_PLAYER_ID)
    {
        
pInfo[killerid][Kills] += 1;
        
GiveXP(killerid, -100);
    }
    
pInfo[playerid][Deaths] += 1;
    
pInfo[playerid][Wasted]++;
    return 
true;

Reply
#8

It worked! I have rep'd all of you for helping me, thanks once again!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)