Array index is out of bounds
#1

When I'm not near house pickup its shows this error from crashdetect and I need help to fix it or give me tutorial to read more about this problems

Код:
[22:01:45] [debug] Run time error 4: "Array index out of bounds"
[22:01:45] [debug]  Accessing element at negative index -1
[22:01:45] [debug] AMX backtrace:
[22:01:45] [debug] #0 000a36e0 in public cmd_buyhouse (playerid=0, params[]=@010b9b8c "") at Drift GM\gamemodes\drift.pwn:10292
[22:01:45] [debug] #1 native CallLocalFunction () from samp-server.exe
[22:01:45] [debug] #2 000216e8 in ?? (... <2 arguments>) at Drift GM\pawno\include\zcmd.inc:102
[22:01:45] [debug] #3 00006cf4 in public OnPlayerCommandText (playerid=0, cmdtext[]=@010b9b64 "/buyhouse") at Drift GM\pawno\include\YSI\y_hooks/impl.inc:929
PHP код:
CMD:buyhouse(playeridparams[])
{
    new 
string[128];
    new 
sendername[MAX_PLAYER_NAME];
    
GetPlayerName(playeridsendername24);
    new 
IsPlayerNearHouse(playerid);
    if(
IsPlayerNearHouse(playerid))
    {
          if(
PlayerInfo[playerid][pHouseKey] != 999) return SendClientMessage(playeridCOLOR_RED"Вие вече имате къща.");
        if(
HouseInfo[i][hOwned]) return SendClientMessage(playeridCOLOR_RED"Тази къща принадлежи на друг играч.");
        if(
GetPlayerCash(playerid) > HouseInfo[i][hPrice])
        {
            
PlayerInfo[playerid][pHouseKey] = i;
            
HouseInfo[i][hOwned] = 1;
            
strmid(HouseInfo[i][hOwner], sendername0strlen(sendername), 255);
            
GivePlayerCash(playerid, -HouseInfo[i][hPrice]);
            
SetPlayerPos(playeridHouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]);
            
SetPlayerInterior(playerid ,HouseInfo[i][hExitInt]);
            
HouseInfo[i][hExitVW] = 100+i;
            
SetPlayerVirtualWorld(playerid100+i);
            
InHouse[playerid] = i;
            
DestroyDynamic3DTextLabel(HouseInfo[i][hLable]);
            
format(stringsizeof(string), "Тази къща принадлежи на\n%s\nИнтериор: %s\nИД: %d"HouseInfo[i][hOwner], HouseInfo[i][hType], i);
            
HouseInfo[i][hLable] = CreateStreamed3DTextLabel(stringCOLOR_GREENHouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ], 10.00);
            
SaveHouses();
            
SavePlayer(playerid);
            
SendClientMessage(playeridCOLOR_GREEN"Добре дошли в новата ви къща. Можете да излезете като натиснте 'N'.");
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"Вие нямате достатъчно пари, за да си купите тази къща!");
            return 
1;
        }
    }
    else
    {
        
SendClientMessage(playeridCOLOR_RED"Ти не си в близост до къща, която се продава!"); // Line 10292
        
return 1;
    }
    return 
1;

Reply
#2

show your IsPlayerNearHouse and your definition of HouseInfo
Reply
#3

Can you show the code of IsPlayerNearHouse()?
Reply
#4

PHP код:
stock IsPlayerNearHouse(playerid)
{
    for(new 
0MAX_HOUSESi++)
    {
        if(
HouseIDTaken[i] && IsPlayerInRangeOfPoint(playerid1.0HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ])) return i;
    }
    return -
1;

Reply
#5

dont return -1,change IsPlayerNearHouse to:
pawn Код:
stock IsPlayerNearHouse(playerid)
{
    for(new i = 1; i < MAX_HOUSES; i++)
    {
        if(HouseIDTaken[i] && IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ])) return i;
    }
    return 0;
}
and change other loops that are like this:
pawn Код:
for(new i = 0; i < MAX_HOUSES; i++)
to:
pawn Код:
for(new i = 1; i < MAX_HOUSES; i++)
Reply
#6

Just return an error message that the player is not near at any house:
pawn Код:
new i = IsPlayerNearHouse(playerid);
if (i == -1) return SendClientMessage(...);
and it'll be fine.

Quote:
Originally Posted by R0
Посмотреть сообщение
dont return 1,change IsPlayerNearHouse to:
pawn Код:
stock IsPlayerNearHouse(playerid)
{
    for(new i = 1; i < MAX_HOUSES; i++)
    {
        if(HouseIDTaken[i] && IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ])) return i;
    }
    return 0;
}
and change other loops that are like this:
pawn Код:
for(new i = 0; i < MAX_HOUSES; i++)
to:
pawn Код:
for(new i = 1; i < MAX_HOUSES; i++)
I see no reason on doing that like this.
Reply
#7

Thanks,

Problem Fixed
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)