Jump to content
  • 1

Array index out of bounds


TheGodfather

Question

Salut, uneori apare eroarea aceasta in logurile serverului si nu reusesc sa imi dau seama de ce da eroare la linia asta: 

foreach(PersonalVSpawned, idd) if(CarInfo[idd][cTime] < gettime() && CarInfo[idd][cTime] != -1) DestroyPlayerCar(idd); 

Eroarea data este:

[16:44:06] [debug] Run time error 4: "Array index out of bounds"
[16:44:06] [debug]  Accessing element at index 10001 past array upper bound 9999
[16:44:06] [debug] AMX backtrace:
[16:44:06] [debug] #0 003ed390 in public DecreaseTimer () at C:\Users\x\Desktop\y\gamemodes\z.pwn:36900

Tin sa mentionez ca limita unde da eroarea a fost marita de la 2k la 10k si tot asa face.

functia la care este problema este urmatoarea:

task DecreaseTimer[5000]() {
    new string[256];
    foreach(PersonalVSpawned, idd) if(CarInfo[idd][cTime] < gettime() && CarInfo[idd][cTime] != -1) DestroyPlayerCar(idd); 
    
    foreach(Player, i) {
        if(!IsPlayerConnected(i) && IsPlayerLogged[i] != 1)
            continue;

        new Float: playerArmour; 
        GetPlayerArmour(i, playerArmour);            
        if(playerArmour == 100 && PlayerInfo[i][pAdmin] == 0 && GetPVarInt(i, "Armour") == 0) {
            if(ServerSystem[3] == 0) NightBot(i, "Cheats (armour-hack)");    
        }
        //if(FPS2[i] == 0 && AFKSeconds[i] > 120 && PlayerInfo[i][pSleeping] == 0) NightBot(i, "rakdroid");
        new Float: playerHealth; 
        GetPlayerArmour(i, playerHealth);            
        if(playerHealth == 100 && PlayerInfo[i][pAdmin] == 0) {
            if(ServerSystem[8] == 0) NightBot(i, "Cheats (health-hack)");    
        }            
                    
        if(PlayerInfo[i][pWantedLevel] >= 1 && WantedTime[i] == 10) {
               WantedTime[i] = 0;
            PlayerInfo[i][pWantedLevel] --;
            SetPlayerWantedLevel(i, PlayerInfo[i][pWantedLevel]);
            Update(i, pWantedLevelx);
            if(PlayerInfo[i][pWantedLevel] == 0) {
                SCM(i, COLOR_YELLOW, "Acum nu mai ai wanted deoarece politia ti-a pierdut urma!");
                PlayerTextDrawHide(i, WantedTD[i]);
                ClearCrime(i);
                finishAchievement(i, 15);
            }
            else {
                format(string, sizeof(string), "Politia iti pierde urma! Wanted Actual: %d", PlayerInfo[i][pWantedLevel]);
                SCM(i, COLOR_YELLOW, string);
            }
            format(string, sizeof(string), "%s [%d] lost 1 wanted level. W: %d", GetName(i), i, PlayerInfo[i][pWantedLevel]);
            SendTeamMessage(14, 0x2e64feFF, string);
            SendTeamMessage(3, COLOR_DBLUE, string);
            SendTeamMessage(2, COLOR_DBLUE, string);
            SendTeamMessage(1, COLOR_DBLUE, string);            
        }
        
        if(IsPlayerInRangeOfPoint(i, 30.0, 184.3529,-1825.4983,8.7530)) {    
            if(GetPVarInt(i, "Listening") == 0) {
                PlayAudioStreamForPlayer(i, beachlink, 184.3529,-1825.4983,8.7530, 30.0, 1);
                SetPVarInt(i, "Listening", 1);
            }    
        }
        else {
            if(GetPVarInt(i, "Listening") == 1) SetPVarInt(i, "Listening", 0);
        }
        
        // -- Variables
        for(new t = 0; t < 18; t++) {
            if(DeelayCommand[i][t] != 0) {
                DeelayCommand[i][t] -= 5;    
                if(DeelayCommand[i][t] < 0) DeelayCommand[i][t] = 0;
            }                
        }
        for(new t = 0; t < 13; t++) {
            if(JobDeelay[i][t] != 0) {
                JobDeelay[i][t] -= 5;    
                if(JobDeelay[i][t] < 0) JobDeelay[i][t] = 0;
            }                
        }            

        if(PlayerTime[i][0] != 0) PlayerTime[i][0] -= 5;
        if(PlayerTime[i][0] < 0) PlayerTime[i][0] = 0;
        
        if(PlayerInfo[i][pReportTime] >= 1) {
            PlayerInfo[i][pReportTime] -= 5;    
            if(PlayerInfo[i][pReportTime] < 0) PlayerInfo[i][pReportTime] = 0;
        }
        if(PlayerInfo[i][pNewbieMute] >= 1) {
            PlayerInfo[i][pNewbieMute] -= 5;
            if(PlayerInfo[i][pNewbieMute] < 0) PlayerInfo[i][pNewbieMute] = 0;
        }
        if(FreezeTime[i] != 0) {
            FreezeTime[i] -= 5;
            if(FreezeTime[i] < 0) FreezeTime[i] = 0;
            if(FreezeTime[i] == 0) {
                SCM(i, COLOR_LIGHTBLUE, "Acum nu mai ai freeze!");
                TogglePlayerControllable(i, 1);
            }
        }                        

        if(PlayerToPoint(50, i, -2317.8091,-1637.5575,483.7031)) {
            for(new m; m < 2; m++) {
                if(PlayerInfo[i][pDailyMission][m] == 7) CheckMission(i, m);
            }        
        }
        if(PlayerToPoint(50, i, 1962.4126,-2193.3279,13.5469)) {
            for(new m; m < 2; m++) {
                if(PlayerInfo[i][pDailyMission][m] == 😎 CheckMission(i, m);
            }        
        }
        if(PlayerToPoint(100, i, 1338.6273,2153.1045,11.0578)) {
            for(new m; m < 2; m++) {
                if(PlayerInfo[i][pDailyMission][m] == 9) CheckMission(i, m);
            }        
        }        
    }    
    return true;
}

Link to comment
Share on other sites

25 answers to this question

Recommended Posts

  • 0

Pentru ca ai gamemode non-mysql acesa nu poate sa capaciteze o anumita suna de masini asa ca aceasta trebuie modificata , iar timerul respectiv task DecreaseTimer[5000]() este folosit prea des inceara sa faci 2 timer

 

Link to comment
Share on other sites

  • 0
Acum 2 ore, TheGodfather a spus:

Am scris asta in primele randuri:

Tin sa mentionez ca limita unde da eroarea a fost marita de la 2k la 10k si tot asa face.

Nu am nici macar 2k de masini pe sv in total deci...

Nu trebuie sa ai peste limita, tu acolo ai in foreach acel idd, idd ul daca depaseste limita impusa in array iti da eroare

Link to comment
Share on other sites

  • 0
La 16.03.2021 la 21:45, iSkull a spus:

Nu trebuie sa ai peste limita, tu acolo ai in foreach acel idd, idd ul daca depaseste limita impusa in array iti da eroare

Daca pun o verificare, sa faca if-ul ala doar daca e idd e mai mic decat o valoare x ar fi o solutie?

Link to comment
Share on other sites

  • 0

Du te la ongamemodeinit imediat dupa ce incarci masinile personale: printf("Total vehicule: %d", Iter_Count(PersonalVSpawned)); si vezi cate vehicule iti da, daca e mai mic decat ai definit pe array e bine, insa dupa te duci la functia de incarcare a vehiculelor, si imediat inainte de inchidere a acoladei pune printf("ID DB: %d", CarInfo[idd][cID]); sau cum ai stocat tu id-ul din db pentru ultimul printf

Link to comment
Share on other sites

  • 0

Am pus pe ultima linie la ongamemodeinit printf("Total vehicule: %d", Iter_Count(PersonalVSpawned)); si imi arata 0, am spawnat 3 masini personale iar id-ul acestora e 37, 32 si 76 la ID DB:

Edited by TheGodfather
Link to comment
Share on other sites

  • 0

function LoadPlayerCars(playerid) {
    gQuery[0] = EOS;
    mysql_format(SQL, gQuery, sizeof(gQuery), "SELECT * FROM `cars` WHERE `Userid`='%d' LIMIT %d", PlayerInfo[playerid][pSQLID], MAX_PLAYER_VEHICLE);
    mysql_tquery(SQL, gQuery, "SQL_LoadVehicles", "i", playerid);
    return true;
}
function SQL_LoadVehicles(playerid) {
    new componenets[20], coordonate[50], Mods[50];
    if(cache_num_rows() == 0) 
        return true;

    for(new i = 0; i < cache_num_rows(); i++) {
        new id = Iter_Free(PersonalVehicles);

        new ORM:ormid = orm_create("cars");
        
        orm_addvar_string(ormid, CarInfo[id][cOwner], 32, "Owner");                                                                       
        orm_addvar_string(ormid, CarInfo[id][cText], 32, "Text");                                                                       
        orm_addvar_string(ormid, CarInfo[id][cLicense], 32, "License");

        orm_addvar_int(ormid, CarInfo[id][cID], "ID");
        orm_addvar_int(ormid, CarInfo[id][cModel], "Model");     
        orm_addvar_int(ormid, CarInfo[id][cNeon], "Neon");                                                                               
        orm_addvar_float(ormid, CarInfo[id][cLocationx], "Locationx");                                                                              
        orm_addvar_float(ormid, CarInfo[id][cLocationy], "Locationy");                                                                              
        orm_addvar_float(ormid, CarInfo[id][cLocationz], "Locationz");                                                                              
        orm_addvar_float(ormid, CarInfo[id][cAngle], "Angle");         
        orm_addvar_float(ormid, CarInfo[id][KM], "KM");                                                                          
        orm_addvar_int(ormid, CarInfo[id][cTemporarTime], "TemporarTime");                                                                        
        orm_addvar_int(ormid, CarInfo[id][cTemporar], "Temporar");                                                                                    
        orm_addvar_int(ormid, CarInfo[id][cVirtual], "Virtual");                                                                                    
        orm_addvar_int(ormid, CarInfo[id][cColorOne], "ColorOne");                                                                                    
        orm_addvar_int(ormid, CarInfo[id][cColorTwo], "ColorTwo");                                                                                 
        orm_addvar_int(ormid, CarInfo[id][cTextColor], "ColorText");                                                                                
        orm_addvar_int(ormid, CarInfo[id][cValue], "Value");                                                                                    
        orm_addvar_int(ormid, CarInfo[id][cAlarm], "Alarm");                                                                                    
        orm_addvar_int(ormid, CarInfo[id][cLock], "Lockk");                                                                                                                                                                              
        orm_addvar_int(ormid, CarInfo[id][paintjob], "paintjob");                                                                                                                                                                     
        orm_addvar_int(ormid, CarInfo[id][Userid], "Userid");
        orm_addvar_int(ormid, CarInfo[id][cTimeGoto], "TimeGoto");                                                                                   
        orm_addvar_int(ormid, CarInfo[id][Confiscated], "Confiscated");                                                                           
        orm_addvar_int(ormid, CarInfo[id][cSpecial], "Special");                                                                                    
        orm_addvar_int(ormid, CarInfo[id][cTax], "Tax");                                                                                        
        orm_addvar_int(ormid, CarInfo[id][cPoints], "Points");                                                                                    
        orm_addvar_int(ormid, CarInfo[id][cFuel], "Fuel");                                                                                        
        orm_addvar_int(ormid, CarInfo[id][cVip], "VIP");                                                                                        
        orm_addvar_int(ormid, CarInfo[id][cRainBow], "RainBow");                                                                                    
        orm_addvar_int(ormid, CarInfo[id][cLegendary], "Legendary");                                                                                
        orm_addvar_int(ormid, CarInfo[id][cStage], "Stage");                                                                                                                                                                     
        orm_addvar_int(ormid, CarInfo[id][Dayss], "Days");                                                                                        
        orm_addvar_string(ormid, componenets, 20, "Components");
        orm_addvar_string(ormid, Mods, 50, "Mods");
        orm_addvar_string(ormid, coordonate, 50, "Cordonate");

        orm_apply_cache(ormid, i);

        CarInfo[id][cMaxSpeed] = GetVehicleMaxSpeed(CarInfo[id][cModel]);
        CarInfo[id][cTime] = -1;
        CarInfo[id][cOnline] = playerid;

        sscanf(Mods, "p<|>iiiiiiiiiiiiii", CarInfo[id][cMod][0], CarInfo[id][cMod][1], CarInfo[id][cMod][2], CarInfo[id][cMod][3], CarInfo[id][cMod][4], CarInfo[id][cMod][5], CarInfo[id][cMod][6],
            CarInfo[id][cMod][7], CarInfo[id][cMod][8], CarInfo[id][cMod][9], CarInfo[id][cMod][10], CarInfo[id][cMod][11], CarInfo[id][cMod][12], CarInfo[id][cMod][13]);
        sscanf(coordonate, "p<|>ffffff", CarInfo[id][cVipPos][0], CarInfo[id][cVipPos][1], CarInfo[id][cVipPos][2], CarInfo[id][cVipPos][3], CarInfo[id][cVipPos][4], CarInfo[id][cVipPos][5]);

        Iter_Add(MyVehicle[playerid], id);
        Iter_Add(PersonalVehicles, id);
    }
    return true;
}

Link to comment
Share on other sites

  • 0

Am spawnat 3 masini personale, au id in ordinea asta la DB ID: cum mi-ai zis tu sa pun: 37, 32 si 67, ultima valoare e 67. Cand se despawneaza primesc asta:

[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at index 10001 in array of size 10000
[debug] AMX backtrace:
[debug] #0 003ecf3c in public DecreaseTimer () at C:\Users\x\Desktop\y\gamemodes\B-HOOD.pwn:35674
[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at index 10001 in array of size 10000
[debug] AMX backtrace:
[debug] #0 003ecf3c in public DecreaseTimer () at C:\Users\x\Desktop\y\gamemodes\B-HOOD.pwn:35674
[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at index 10001 in array of size 10000
[debug] AMX backtrace:
[debug] #0 003ecf3c in public DecreaseTimer () at C:\Users\x\Desktop\y\gamemodes\B-HOOD.pwn:35674

Link to comment
Share on other sites

  • 0

stock DestroyPlayerCar(dbid) {
    if(CarInfo[dbid][Spawned] == 0) return true;
    
    VehicleOwned[CarInfo[dbid][Spawned]] = 0;
    VehicleSQL[CarInfo[dbid][Spawned]] = 0;
    CarInfo[dbid][cTime] = -1;
        
    new Float: Pos[3];
    GetVehiclePos(CarInfo[dbid][Spawned], Pos[0], Pos[1], Pos[2]);
    if(strlen(CarInfo[dbid][cText]) >= 3) DestroyDynamicObject(nameobject[CarInfo[dbid][Spawned]]);
    if(CarInfo[dbid][cNeon]) {
        DestroyDynamicObject(NeonObj[0][CarInfo[dbid][Spawned]]);
        DestroyDynamicObject(NeonObj[1][CarInfo[dbid][Spawned]]);
    }
    Iter_Remove(PersonalVSpawned, dbid);
    MyVehicleSpawn[CarInfo[dbid][cOnline]] --;
    CarInfo[dbid][cFuel] = Gas[CarInfo[dbid][Spawned]];
    new query[256];
    mysql_format(SQL, query, sizeof(query), "UPDATE `cars` SET `Fuel`='%d' WHERE `ID`='%d'", CarInfo[dbid][cFuel], CarInfo[dbid][cID]);
    mysql_tquery(SQL, query, "", "");

    CarInfo[dbid][cLastPos][0] = Pos[0];
    CarInfo[dbid][cLastPos][1] = Pos[1];
    CarInfo[dbid][cLastPos][2] = Pos[2];    
        
    DestroyVehicle(CarInfo[dbid][Spawned]);
    CarInfo[dbid][Spawned] = 0;
    return true;
}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.