Array index out of bounds.
#1

-- DELETED --
Reply
#2

Any details? Which array?
Reply
#3

If you are using YSI use iterator too.

Код:
stock GetRandomPlayer()
{
	my_label:
	new id = Iter_Random(Player);
	
	if (pInfo[id][pMember] == 8 && pInfo[id][pScore] < 3 && pInfo[id][aVar][23] != 0)
	{
		goto my_label
	}
	return id;
}
Reply
#4

Quote:
Originally Posted by Rdx
Посмотреть сообщение
Any details? Which array?
I have no clue. I think it happens when there are no users online, so the variable users returns 0, but when the timer check for an ID, it see ID 0 from variable users, thus it gives arrat index out of bounds in my pInfo because the player doesn't exist.
Reply
#5

Bump!
Reply
#6

the logs could have helped you the most.

Show us the logs and people will be able to help more.

Quote:
Originally Posted by danielpalade
Посмотреть сообщение
I have no clue. I think it happens when there are no users online, so the variable users returns 0, but when the timer check for an ID, it see ID 0 from variable users, thus it gives array index out of bounds in my pInfo because the player doesn't exist.
arrays would not go index out of bounds on MAX_PLAYERS it returns 0 to infinity

Try using GetPlayerPoolSize() rather than MAX_PLAYERS from now on, it's much better and more complex MAX_PLAYERS already.

EDIT:
Quote:
Originally Posted by danielpalade
Посмотреть сообщение
I'm getting the error Array index out of bounds with this code:

Код:
#include <YSI\y_timers>

stock GetRandomPlayer()
{
	new users[MAX_PLAYERS], pl = 0;
	for(new i; i < MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i) && pInfo[i][pMember] != 8 && pInfo[i][pScore] >= 3 && pInfo[i][aVar][23] == 0)
		{
			users[pl] = i;
			pl++;
		}
	}
	return users[random(pl)];
}

task AutoContracts[180000]()
{
	new string[128], amount = RandomEx(6000, 30000), id = GetRandomPlayer();
	if(IsPlayerConnected(id))
	{
		pInfo[id][aVar][23] += amount;
		mysql_format(MySQLCon, quMYSQL, 200, "UPDATE `players` SET `Contract`=%d WHERE `ID`=%d", pInfo[id][aVar][23], pInfo[id][pID]), mysql_tquery(MySQLCon, quMYSQL);

		format(string, sizeof(string), "HITMAN: A new hit is available. Name: %s | Amount: %s$, (/hits).", GetName(id), FormatNumber(pInfo[id][aVar][23]));
	    SendTeamMessage(8, COLOR_HITMAN, string);
	}
    return 1;
}
also rather than using for(new i; i < MAX_PLAYERS; i++)
foreach(new i : Player) was born to be used by everyone
if you don't have foreach then
you can use for(new i; i < GetPlayerPoolSize(); i++)
just like what I said earlier
Reply
#7

if there is no players online random(0) returns huge numbers
change to
pawn Код:
return users[((pl < 2) ? 0 : random(pl))];
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)