Array index out of bonus
#1

I have this problem on my command: /attack

Line:
Код:
if(GetWeekDay() == 1 || GetWeekDay() == 4 || GetWeekDay() == 6) return SCM(playerid, COLOR_WHITE,, "You can use this command only Monday, Wednesday, Friday and Sunday.");
getweekday function:
Код:
public GetWeekDay()
{
	new year,month,day;
    getdate(year, month, day);

	new
		weekday,
		j,
		e;

	if (month <= 2)
	{
		month += 12;
		--year;
	}

	j = year % 100;
	e = year / 100;

	switch ((day + (month+1)*26/10 + j + j/4 + e/4 - 2*e) % 7)
	{
		case 0: weekday = 1;
		case 1: weekday = 2;
		case 2: weekday = 3;
		case 3: weekday = 4;
		case 4: weekday = 5;
		case 5: weekday = 6;
		case 6: weekday = 7;
	}
	return weekday;
}
error:
Код:
[18:10:10] [debug] Run time error 4: "Array index out of bounds"
[18:10:10] [debug] AMX backtrace:
[18:10:10] [debug] #0 001a86d0 in public cmd_attack (playerid=9, params[]=@0155f83c "") at D:\gamemode\gamemodes\exgaming.pwn:25599
[18:10:10] [debug] #1 native CallLocalFunction () from samp03svr
[18:10:10] [debug] #2 0003c25c in public OnPlayerCommandText (playerid=9, cmdtext[]=@0155f81c "/attack") at D:\gamemode\pawno\include\zcmd.inc:102
Reply
#2

The problem is in /attack command, specifically at line 25599. When you receive a run time error 4, always post the whole logs so we can know the upper bound index and the index it tried to access element from.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The problem is in /attack command, specifically at line 25599. When you receive a run time error 4, always post the whole logs so we can know the upper bound index and the index it tried to access element from.
See here /attack: https://pastebin.com/uHme1dZm
And what i give you above is all the logs that appears in server_log
Reply
#4

Not all, it's missing one important part. An example of what I meant in my previous post is:
pawn Код:
Attempted to read/write array element at negative index -1
You also did not mention what line 25599 is in the command so I will have to guess until you do. "IsAMember" function takes care of many things and "turf" is also checked so what is left is:
Код:
InWar[TurfInfo[turf][zOwned]]
But again, without the line I can't tell you it is certainly this.
Reply
#5

#deleted.
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Not all, it's missing one important part. An example of what I meant in my previous post is:
pawn Код:
Attempted to read/write array element at negative index -1
You also did not mention what line 25599 is in the command so I will have to guess until you do. "IsAMember" function takes care of many things and "turf" is also checked so what is left is:
Код:
InWar[TurfInfo[turf][zOwned]]
But again, without the line I can't tell you it is certainly this.


This is all bro, here you have a print of my server_log https://i.imgur.com/XEmBLoL.png


This is the line
Код:
if(TurfInfo[turf][zOwned] == faction) return SS(playerid, COLOR_WHITE, "Nu iti poti ataca propriul turf.", "You can't attack your own turf.");
Reply
#7

Is the version of the crashdetect plugin you have loaded an old one? It is apparently off (the line reported) and neither does print the index accessed/upper bound. Try to update to the latest version for more details.

Alright, this is a different report so post IsPlayerInTurf function.
Reply
#8

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Is the version of the crashdetect plugin you have loaded an old one? It is apparently off (the line reported) and neither does print the index accessed/upper bound. Try to update to the latest version for more details.

Alright, this is a different report so post IsPlayerInTurf function.
Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Is the version of the crashdetect plugin you have loaded an old one? It is apparently off (the line reported) and neither does print the index accessed/upper bound. Try to update to the latest version for more details.

Alright, this is a different report so post IsPlayerInTurf function.
the 2nd picture (if you saw it) was mistakenly put. just the one that's right now is the error that i get in server_logs.

here:
Код:
public IsPlayerInTurf(playerid, turfid)
{
	if(IsPlayerConnected(playerid))
	{
		if(turfid == -1 || turfid >= MAX_TURFS || turfid < 1)
		{
			return 0;
		}
		new Float:x, Float:y, Float:z;
		GetPlayerPos(playerid,x,y,z);
		if(x >= TurfInfo[turfid][zMinX] && x < TurfInfo[turfid][zMaxX] && y >= TurfInfo[turfid][zMinY] && y < TurfInfo[turfid][zMaxY])
		{
	 		return 1;
		}
	}
	return 0;
}

public GetPlayerTurf(playerid)
{
    for(new i = 1; i < sizeof(Turfs); i++)
    {
        if(IsPlayerInTurf(playerid, i))
        {
            return i;
        }
    }
    return -1;
}
Reply
#9

Problem is here:

Код:
new turf = GetPlayerTurf(playerid), faction = PlayerInfo[playerid][pMember], string[128], players;
        if(turf == 0 || turf >= MAX_TURFS) return SS(playerid, COLOR_WHITE, "Nu esti pe turf.", "You are not on a turf.");
        if(TurfInfo[turf][zOwned] == faction) return SS(playerid, COLOR_WHITE, "Nu iti poti ataca propriul turf.", "You can't attack your own turf.");
GetPlayerTurf returns -1, not 0.


So, change this:


Код:
if(turf == 0 || turf >= MAX_TURFS) return SS(playerid, COLOR_WHITE, "Nu esti pe turf.", "You are not on a turf.");
To this:

Код:
if(turf == -1 || turf >= MAX_TURFS) return SS(playerid, COLOR_WHITE, "Nu esti pe turf.", "You are not on a turf.");
Reply
#10

Quote:
Originally Posted by raydx
Посмотреть сообщение
Problem is here:

Код:
new turf = GetPlayerTurf(playerid), faction = PlayerInfo[playerid][pMember], string[128], players;
        if(turf == 0 || turf >= MAX_TURFS) return SS(playerid, COLOR_WHITE, "Nu esti pe turf.", "You are not on a turf.");
        if(TurfInfo[turf][zOwned] == faction) return SS(playerid, COLOR_WHITE, "Nu iti poti ataca propriul turf.", "You can't attack your own turf.");
GetPlayerTurf returns -1, not 0.


So, change this:


Код:
if(turf == 0 || turf >= MAX_TURFS) return SS(playerid, COLOR_WHITE, "Nu esti pe turf.", "You are not on a turf.");
To this:

Код:
if(turf == -1 || turf >= MAX_TURFS) return SS(playerid, COLOR_WHITE, "Nu esti pe turf.", "You are not on a turf.");
I have changed with < 1.
Thanks bro!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)