16.02.2017, 23:01
the logs could have helped you the most.
Show us the logs and people will be able to help more.
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:
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
Show us the logs and people will be able to help more.
Quote:
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.
|
Try using GetPlayerPoolSize() rather than MAX_PLAYERS from now on, it's much better and more complex MAX_PLAYERS already.
EDIT:
Quote:
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; } |
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