whats wrong????
#1

Hello guys!

I wanted to ask you why i get this:

Код:
[01:02:22] [debug] Run time error 4: "Array index out of bounds"
[01:02:22] [debug]  Accessing element at index 100 past array upper bound 99
[01:02:22] [debug] AMX backtrace:
[01:02:22] [debug] #0 0002c558 in public cmd_nkurti (0x00000000, 0x01090d08) from Test.amx
[01:02:22] [debug] #1 native CallLocalFunction () [00472ef0] from samp-server.exe
[01:02:22] [debug] #2 00016314 in ?? (0x00000000, 0x01090ce8) from Test.amx
[01:02:22] [debug] #3 00005b1c in public OnPlayerCommandText (0x00000000, 0x01090ce8) from Test.amx
And why my command isn working?

pawn Код:
CMD:nkurti(playerid,params[])
{
    new Float:X,Float:Y,Float:Z,labelstring[300],string[30],houseid = 0,RandomInt;
    if(PlayerInfo[playerid][pAdmin] < 5) return 0;

    for(new h;h < MAX_HOUSES;h++)
    {
        houseid = h + 1;
    }

    GetPlayerPos(playerid, X, Y, Z);
    HouseInfo[houseid][hEnterX] = X;
    HouseInfo[houseid][hEnterY] = Y;
    HouseInfo[houseid][hEnterZ] = Z;

    HouseInfo[houseid][hCreated] = 1;
    HouseInfo[houseid][hOwned] = 0;
    HouseInfo[houseid][hLocked] = 1;
    HouseInfo[houseid][hAddress] = GetPlayer3DZone(playerid);
    HouseInfo[houseid][hVirtualWorld] = houseid;
    RandomInt = RandomEx(1,6);
    if(RandomInt == 1)
    {
        HouseInfo[houseid][hExitX] = 225.756989;
        HouseInfo[houseid][hExitY] = 1240.000000;
        HouseInfo[houseid][hExitZ] = 1082.149902;
        HouseInfo[houseid][hInterior] = 2;
        HouseInfo[houseid][hPrice] = RandomEx(50000,80000);
        format(HouseInfo[houseid][hDescription],32,"Small/1 story/1 bedroom");
        SaveHouseData(houseid);
    }
    if(RandomInt == 2)
    {
        HouseInfo[houseid][hExitX] = 235.508994;
        HouseInfo[houseid][hExitY] = 1189.169897;
        HouseInfo[houseid][hExitZ] = 1080.339966;
        HouseInfo[houseid][hInterior] = 3;
        HouseInfo[houseid][hPrice] = RandomEx(100000,150000);
        format(HouseInfo[houseid][hDescription],32,"Large/2 story/3 bedrooms");
        SaveHouseData(houseid);
    }
    if(RandomInt == 3)
    {
        HouseInfo[houseid][hExitX] = 328.493988;
        HouseInfo[houseid][hExitY] = 1480.589966;
        HouseInfo[houseid][hExitZ] = 1084.449951;
        HouseInfo[houseid][hInterior] = 15;
        HouseInfo[houseid][hPrice] = RandomEx(80000,100000);
        format(HouseInfo[houseid][hDescription],32,"Medium/1 story/2 bedrooms");
        SaveHouseData(houseid);
    }
    if(RandomInt == 4)
    {
        HouseInfo[houseid][hExitX] = 1299.14;
        HouseInfo[houseid][hExitY] = -794.77;
        HouseInfo[houseid][hExitZ] = 1084.00;
        HouseInfo[houseid][hInterior] = 5;
        HouseInfo[houseid][hPrice] = RandomEx(500000,1000000);
        format(HouseInfo[houseid][hDescription],32,"Mansion");
        SaveHouseData(houseid);
    }
    if(RandomInt == 5)
    {
        HouseInfo[houseid][hExitX] = 225.630997;
        HouseInfo[houseid][hExitY] = 1022.479980;
        HouseInfo[houseid][hExitZ] = 1084.069946;
        HouseInfo[houseid][hInterior] = 7;
        HouseInfo[houseid][hPrice] = RandomEx(120000,180000);
        format(HouseInfo[houseid][hDescription],32,"Very large/2 story/4 bedrooms");
        SaveHouseData(houseid);
    }
    format(labelstring,sizeof(labelstring),"Patalpa parduodama!\nKaina: %d LT\nAdresas: %s\nInformacija %s",HouseInfo[houseid][hPrice],HouseInfo[houseid][hAddress],HouseInfo[houseid][hDescription]);
    HouseInfo[houseid][hLabel] = CreateDynamic3DTextLabel(labelstring, COL_GREEN, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 300);
    HouseInfo[houseid][hPickup] = CreateDynamicPickup(1272, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ]);
    HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0,0);
    format(string, sizeof(string), "Namas sukurtas su ID: %d Kaina: %d Interjeras: %",houseid,HouseInfo[houseid][hPrice],HouseInfo[houseid][hInterior]);
    SendClientMessage(playerid, COL_ADMINGREEN, string);
    return 1;
}
oh yeah and this isnt working too.When i type wrong commnand it says Server:Unknown command.Not my text.

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	return SendClientMessage(playerid,COL_RED,"Tokios komandos nera!");
}
Reply
#2

That's your mistake:
pawn Код:
houseid = h + 1;
MAX_HOUSES is 100 so the valid indexes are 0 - 99. If the h is 99 and adding 1 will be 100 (which is out of bounds). Just use "h" as houseid directly.

About the custom unknown command message, use OnPlayerCommandPerformed callback for it.
Reply
#3

when i type command it creates 99 houses....

pawn Код:
CMD:nkurti(playerid,params[])
{
    new Float:X,Float:Y,Float:Z,labelstring[300],string[30],RandomInt;
    if(PlayerInfo[playerid][pAdmin] < 5) return 0;

    for(new houseid;houseid < MAX_HOUSES;houseid++)
    {

        GetPlayerPos(playerid, X, Y, Z);
        HouseInfo[houseid][hEnterX] = X;
        HouseInfo[houseid][hEnterY] = Y;
        HouseInfo[houseid][hEnterZ] = Z;

        HouseInfo[houseid][hCreated] = 1;
        HouseInfo[houseid][hOwned] = 0;
        HouseInfo[houseid][hLocked] = 1;
        HouseInfo[houseid][hAddress] = GetPlayer3DZone(playerid);
        HouseInfo[houseid][hVirtualWorld] = houseid+1;
        RandomInt = RandomEx(1,6);
        if(RandomInt == 1)
        {
            HouseInfo[houseid][hExitX] = 225.756989;
            HouseInfo[houseid][hExitY] = 1240.000000;
            HouseInfo[houseid][hExitZ] = 1082.149902;
            HouseInfo[houseid][hInterior] = 2;
            HouseInfo[houseid][hPrice] = RandomEx(50000,80000);
            format(HouseInfo[houseid][hDescription],32,"Small/1 story/1 bedroom");
            SaveHouseData(houseid);
        }
        if(RandomInt == 2)
        {
            HouseInfo[houseid][hExitX] = 235.508994;
            HouseInfo[houseid][hExitY] = 1189.169897;
            HouseInfo[houseid][hExitZ] = 1080.339966;
            HouseInfo[houseid][hInterior] = 3;
            HouseInfo[houseid][hPrice] = RandomEx(100000,150000);
            format(HouseInfo[houseid][hDescription],32,"Large/2 story/3 bedrooms");
            SaveHouseData(houseid);
        }
        if(RandomInt == 3)
        {
            HouseInfo[houseid][hExitX] = 328.493988;
            HouseInfo[houseid][hExitY] = 1480.589966;
            HouseInfo[houseid][hExitZ] = 1084.449951;
            HouseInfo[houseid][hInterior] = 15;
            HouseInfo[houseid][hPrice] = RandomEx(80000,100000);
            format(HouseInfo[houseid][hDescription],32,"Medium/1 story/2 bedrooms");
            SaveHouseData(houseid);
        }
        if(RandomInt == 4)
        {
            HouseInfo[houseid][hExitX] = 1299.14;
            HouseInfo[houseid][hExitY] = -794.77;
            HouseInfo[houseid][hExitZ] = 1084.00;
            HouseInfo[houseid][hInterior] = 5;
            HouseInfo[houseid][hPrice] = RandomEx(500000,1000000);
            format(HouseInfo[houseid][hDescription],32,"Mansion");
            SaveHouseData(houseid);
        }
        if(RandomInt == 5)
        {
            HouseInfo[houseid][hExitX] = 225.630997;
            HouseInfo[houseid][hExitY] = 1022.479980;
            HouseInfo[houseid][hExitZ] = 1084.069946;
            HouseInfo[houseid][hInterior] = 7;
            HouseInfo[houseid][hPrice] = RandomEx(120000,180000);
            format(HouseInfo[houseid][hDescription],32,"Very large/2 story/4 bedrooms");
            SaveHouseData(houseid);
        }
        format(labelstring,sizeof(labelstring),"Patalpa parduodama!\nKaina: %d LT\nAdresas: %s\nInformacija %s",HouseInfo[houseid][hPrice],HouseInfo[houseid][hAddress],HouseInfo[houseid][hDescription]);
        HouseInfo[houseid][hLabel] = CreateDynamic3DTextLabel(labelstring, COL_GREEN, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 300);
        HouseInfo[houseid][hPickup] = CreateDynamicPickup(1272, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ]);
        HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0,0);
        format(string, sizeof(string), "Namas sukurtas su ID: %d Kaina: %d Interjeras: %",houseid,HouseInfo[houseid][hPrice],HouseInfo[houseid][hInterior]);
        SendClientMessage(playerid, COL_ADMINGREEN, string);
    }
    return 1;
}
Код:
[01:18:03] [debug] Run time error 4: "Array index out of bounds"
[01:18:03] [debug]  Accessing element at negative index -1
[01:18:03] [debug] AMX backtrace:
[01:18:03] [debug] #0 0000d3cc in ?? (0xffffffff) from Test.amx
[01:18:03] [debug] #1 00028ec4 in ?? (0x00000000) from Test.amx
[01:18:03] [debug] #2 0002243c in public Streamer_OnPlayerDisconnect (0x00000000, 0x00000001) from Test.amx
[01:18:03] [debug] #3 00015c00 in public SSCANF_OnPlayerDisconnect (0x00000000, 0x00000001) from Test.amx
[01:18:03] [debug] #4 0001009c in ?? (0x00000000, 0x00000001) from Test.amx
[01:18:03] [debug] #5 000052e4 in public OnPlayerDisconnect (0x00000000, 0x00000001) from Test.amx
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{

    SavePlayerData(playerid);
    new string[80],string0[80],pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    new DisconnectReason[3][] = {"Klaida","Isejo","Kick/Ban"};
    format(string, sizeof string, ""TCYELLOW"%s "TCCYAN"isejo is serverio["TCRED"%s""TCCYAN]", pName, DisconnectReason[reason]);
    format(string0, sizeof string0, "%s paliko serveri [%s]", pName, DisconnectReason[reason]);
    SendClientMessageToAll(COL_RED, string);
    print(string0);
    return 1;
}
Reply
#4

Post SavePlayerData from OnPlayerDisconnect.

About the houses, the last houseid might be 99 but it also starts from 0 so 100 houses unless you re-defined MAX_HOUSES to 99.
Reply
#5

Everything got fixed but now when i log in i cant see anything only me and houses that i created , its like objects is not loading...No errors or bugs , just this.What could be wrong?
Reply


Forum Jump:


Users browsing this thread: