Array index out of bounds
#1

Hi, I've wrote a thing that should save player's injuries, but when I show player the injuries I get these errors:

Код:
[17:05:47] [debug] Run time error 4: "Array index out of bounds"
[17:05:47] [debug]  Attempted to read/write array element at index 55 in array of size 55
[17:05:47] [debug] AMX backtrace:
[17:05:47] [debug] #0 0001d0e4 in ?? (0, 0) from LSLRP.amx
[17:05:47] [debug] #1 0002da48 in public cmd_injuries (0, 18456472) from LSLRP.amx
[17:05:47] [debug] #2 native CallLocalFunction () from samp-server.exe
[17:05:47] [debug] #3 00008590 in public OnPlayerCommandText (0, 18456412) from LSLRP.amx
Here's the code:

Код:
#define MAX_BODY_PARTS 6

new Injuries[MAX_PLAYERS][55][MAX_BODY_PARTS];

ShowInjuries(playerid, targetid)
{
	new injurycount, title[48];
	
	format(title, sizeof(title), "Injuries of %s", GetName(targetid, 0));
	
	for (new i; i < 54; i++) for (new j; j < MAX_BODY_PARTS; j++)
		if (Injuries[targetid][i][j]) injurycount++;
		
	if (injurycount)
	{
		new injuries[1000], string[64];
		
		format(string, sizeof(string), "Weapon\tBody Part\tTimes Injured\n");
		
		for (new i; i < 54; i++) for (new j; j < MAX_BODY_PARTS; i++) 
		{
			if (Injuries[targetid][i][j]) 
			{
				format(string, sizeof(string), "%s\t%s\t%d\n", ReturnWeaponName(i), ReturnBodyPartName(j + 3), Injuries[targetid][i][j]);
				strcat(injuries, string);
			}		 
		}
		ShowPlayerDialog(playerid, DIALOG_VIEW_INJURIES, DIALOG_STYLE_TABLIST_HEADERS, title, string, "Close", "");
	}
	else ShowPlayerDialog(playerid, DIALOG_VIEW_INJURIES, DIALOG_STYLE_MSGBOX, title, "There are no visible injuries.", "Close", "");
}
What's wrong here?
Reply
#2

can u show these functions
ReturnWeaponName()

ReturnBodyPartName()
?
Reply
#3

Here:
Код:
ReturnWeaponName(weaponid)
{
	new weaponname[32];
	
	if (weaponid == 0) weaponname = "Fist";
	else if (weaponid < 0 || weaponid > 46) weaponname = "None";
	else GetWeaponName(weaponid, weaponname, sizeof(weaponname));
	return weaponname;
}

ReturnBodyPartName(bodypart)
{
    new string[12];
	
    switch (bodypart)
    {
        case 3: string = "Chest";
        case 4: string = "Groin";
        case 5: string = "Left Arm";
        case 6: string = "Right Arm";
        case 7: string = "Left Leg";
        case 8: string = "Right Leg";
        case 9: string = "Head";
    }
    return string;
}
Reply
#4

delete.
Reply
#5

oh i forgot to tell you is there any cmd called injuries ?? show it.
Reply
#6

Here:
Код:
CMD:injuries(playerid, params[])
{
	new targetid;
	
	if (sscanf(params, "u", targetid))
		return SendUsageMessage(playerid, "/injuries [playerid/name]");
	
	if (targetid == INVALID_PLAYER_ID)
		return SendErrorMessage(playerid, "You have specified an invalid player.");
	
	if (!IsPlayerNearPlayer(playerid, targetid, 10.0))
		return SendErrorMessage(playerid, "You are not close enough to the specified player.");
		
	ShowInjuries(playerid, targetid);
	return 1;
}
Reply
#7

found creepy thing lol
change
Код:
for (new i; i < 54; i++) for (new j; j < MAX_BODY_PARTS; i++)
to
Код:
for (new i; i < 54; i++) for (new j; j < MAX_BODY_PARTS; j++)
Reply
#8

Thank you man, I wouldn't notice it without your help. By the way, the injuries look like this:
https://gyazo.com/cd9a0e82ba1cd39cb472a06a77f05d6d

But I have
Код:
string = "Weapon\tBody Part\tTimes Injured\n";
strcat(injuries, string);
before everything there. What's the problem?

EDIT: Wait nevermind, I could just do
Код:
strcat(injuries, "Weapon\tBody Part\tTimes Injured\n");
lol. I didn't think about that before.

EDIT 2: Still doesn't work though.

EDIT 3: Oh the problem was that I was showing player the "string", not the "injuries".
Reply
#9

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
Thank you man, I wouldn't notice it without your help. By the way, the injuries look like this:
https://gyazo.com/cd9a0e82ba1cd39cb472a06a77f05d6d

But I have
Код:
string = "Weapon\tBody Part\tTimes Injured\n";
strcat(injuries, string);
before everything there. What's the problem?

EDIT: Wait nevermind, I could just do
Код:
strcat(injuries, "Weapon\tBody Part\tTimes Injured\n");
lol. I didn't think about that before.

EDIT 2: Still doesn't work though.
you are displaying string var in showplayerdialog. It should be injuries no ?
Edit: oops i didnt refresh ...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)