Jump to content
  • 0

Eroare in consola Task DecreaseTimer SA-MP SERVER


mrrares19

Question

[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at index 101 in array of size 101
[debug] AMX backtrace:
[debug] #0 00344398 in public DecreaseTimer () at mrx.pwn:30372

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

stock-ul in caz ca e nevoie:

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]];
    mysql_format(SQL, gQuery, sizeof(gQuery), "UPDATE `cars` SET `Fuel`='%d' WHERE `ID`='%d'", CarInfo[dbid][cFuel], CarInfo[dbid][cID]);
    mysql_tquery(SQL, gQuery, "", "");

    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;
}

Va rog ajutati-ma ,nu scap de eroarea asta de 1 luna !

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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

Poftiti domnu’. 
Verificăm mai întâi dacă idd este mai mic decât dimensiunea array-ului CarInfo și accesam elementul numai dacă este valid.

 

sau

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

Aici verificăm dacă indicele idd este între 0 și 100 (101 elemente în total), iar dacă este, verificăm și dacă poziția respectivă a matricei CarInfo a fost alocată. 
Greu cu indentarea pentru că-s pe telefon. 
Problema actuala are multe fețe, atât de percepere cât si de rezolvare.

Nu am mai scriptat de peste 5 ani așadar sper că ce spun e corect si valid pentru soluția ta. 
Încearcă ce ți am dat, o ducem la capăt oricum. 

Edited by R X S
Link to comment
Share on other sites

  • 0

pentru ce-i ce nu au rezolvat

stock-ul

stock DestroyPlayerCar(dbid, bool:useinloop = false) {
    if(CarInfo[dbid][Spawned] == 0) return true;
   
    VehicleOwned[CarInfo[dbid][Spawned]] = 0;
    VehicleSQL[CarInfo[dbid][Spawned]] = 0;
    CarInfo[dbid][cTime] = -1;
    gQuery[0] = EOS;
       
    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]) for(new i = 0; i < 2; i++) DestroyDynamicObject(NeonObj[i][CarInfo[dbid][Spawned]]);
    if(!useinloop) Iter_Remove(PersonalVSpawned, dbid);
 
    MyVehicleSpawn[CarInfo[dbid][cOnline]] --;
    CarInfo[dbid][cFuel] = Gas[CarInfo[dbid][Spawned]];
    mysql_format(SQL, gQuery, sizeof(gQuery), "UPDATE `cars` SET `Fuel`='%d' WHERE `ID`='%d'", CarInfo[dbid][cFuel], CarInfo[dbid][cID]);
    mysql_tquery(SQL, gQuery, "", "");
 
    for(new i = 0; i < 3; i++) CarInfo[dbid][cLastPos][i] = Pos[i];
    DestroyVehicle(CarInfo[dbid][Spawned]);
    CarInfo[dbid][Spawned] = 0;
    saveCar(dbid);
 
    mysql_format(SQL, gQuery, sizeof gQuery , "UPDATE cars SET Spawned='%d' WHERE ID=%d", CarInfo[dbid][Spawned], CarInfo[dbid][cID]);
    mysql_tquery(SQL, gQuery, "", "");
    return true;
}
 
linia din decreasetimer: 
 
 foreach(new idd: PersonalVSpawned) {
        if(CarInfo[idd][cTime] < gettime() && CarInfo[idd][cTime] != -1) {
            DestroyPlayerCar(idd, true);
            Iter_Remove(PersonalVSpawned, idd);
        }
    }
 
Link to comment
Share on other sites

  • 0
2 hours ago, Sancky said:

Iter_SafeRemove e solutia frt pt versiuni mai vechi de YSI

lucrez pe ultima versiune nu mai este recomandat sa folosesti iter_SafeRemove, + cand eram pe ysi 3 , tot nu a mers cu saferemove, mna burned ce sa ceri bug-uri peste bug-uri

 

Edited by mrrares19
Link to comment
Share on other sites

  • 0
1 hour ago, mrrares19 said:

lucrez pe ultima versiune nu mai este recomandat sa folosesti iter_SafeRemove, + cand eram pe ysi 3 , tot nu a mers cu saferemove, mna burned ce sa ceri bug-uri peste bug-uri

 

n ai stiut sa l folosesti cum trb.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.