[debug] Run time error 4: "Array index out of bounds"
#1

Something is wrong. I hope someone solve this.

Код:
[20:20:36] [debug] Run time error 4: "Array index out of bounds"
[20:20:36] [debug]  Accessing element at index 65535 past array upper bound 499
[20:20:36] [debug] AMX backtrace:
[20:20:36] [debug] #0 0004bac4 in public cmd_report (playerid=0, params[]=@0x0004dadc "1 23") at 6113
[20:20:36] [debug] #1 native CallLocalFunction () [00471ef0] from samp-server.exe
[20:20:36] [debug] #2 00007228 in public OnPlayerCommandText (playerid=0, cmdtext[]=@0x0004daa8 "/report 1 23") at pawno\include\zcmd.inc:110
Line 6113
Quote:

PlayerInfo[player][ReportCount]++;

Код:
COMMAND:report(playerid,params[]) //level0
{
	new player, reason[128];
	if(sscanf(params, "rs[128]", player, reason))
	{
		return 	GameTextForPlayer(playerid, "~g~/report ~w~<id/name> <reason>", 3000, 3);
	}
    PlayerInfo[player][ReportCount]++;

 	if(IsPlayerConnected(player) && player != INVALID_PLAYER_ID && player != playerid && PlayerInfo[player][AdminLevel] == 0)
	{
		if(strlen(reason) < 2)
		{
      		GameTextForPlayer(playerid, "~r~Write a valid reason", 3000, 3);
		    return 1;
		}
		new hour,minute,second, string[128];
		gettime(hour,minute,second);
		format(string, sizeof(string), "[REPORT]: %s(%d) has reported %s(%d) (Reason: %s) |@%d:%d:%d|", GetName(playerid), playerid, GetName(player), player, reason, hour, minute, second);
		AdminMSG(RED,string);
		format(string, sizeof(string), "Report(%d:%d:%d): %s(%d) reported %s(%d) Reason: %s", hour, minute, second, GetName(playerid), playerid, GetName(player), player, reason);
		for(new i = 1; i < MAX_REPORTS-1; i++) Reports[i] = Reports[i+1];
		Reports[MAX_REPORTS-1] = string;
		GameTextForPlayer(playerid, "~g~Report has been sent", 3000, 3);
	}
	else
	{
		GameTextForPlayer(playerid, "~r~Player is unavailable", 3000, 3);
	}
	return 1;
}
Reply
#2

Replace player with [playerid]
Reply
#3

Quote:
Originally Posted by Avi Raj
Посмотреть сообщение
Replace player with [playerid]
Are you trying to add Report Count to a player who is trying to report? Srsly.

Edit:

player = someone but not you
playerid = Yourself
Reply
#4

The id you typed was an invalid player (INVALID_PLAYER_ID = 65535).

Basically, before you pass values such as players' ID in array make sure that the player is valid first. You do but after accessing the invalid index.

pawn Код:
COMMAND:report(playerid,params[]) //level0
{
    new player, reason[128];
    if(sscanf(params, "rs[128]", player, reason)) return GameTextForPlayer(playerid, "~g~/report ~w~<id/name> <reason>", 3000, 3);
    if(player == INVALID_PLAYER_ID || player == playerid || PlayerInfo[player][AdminLevel] != 0) return GameTextForPlayer(playerid, "~r~Player is unavailable", 3000, 3);
    if(strlen(reason) < 2) return GameTextForPlayer(playerid, "~r~Write a valid reason", 3000, 3);
    PlayerInfo[player][ReportCount]++;
    new hour,minute,second, string[128];
    gettime(hour,minute,second);
    format(string, sizeof(string), "[REPORT]: %s(%d) has reported %s(%d) (Reason: %s) |@%d:%d:%d|", GetName(playerid), playerid, GetName(player), player, reason, hour, minute, second);
    AdminMSG(RED,string);
    format(string, sizeof(string), "Report(%d:%d:%d): %s(%d) reported %s(%d) Reason: %s", hour, minute, second, GetName(playerid), playerid, GetName(player), player, reason);
    for(new i = 1; i < MAX_REPORTS-1; i++) Reports[i] = Reports[i+1];
    Reports[MAX_REPORTS-1] = string;
    GameTextForPlayer(playerid, "~g~Report has been sent", 3000, 3);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)