Jump to content
  • 0

Bug opencrates gamemode HPQ123


TheGodfather

Question

Salut, am gasit un bug legat de deschiderea de crates pe gm b-hood de HPQ123, las mai jos eroarea gasita in logurile serverului.

[12:20:54] [debug] Run time error 4: "Array index out of bounds"
[12:20:54] [debug]  Accessing element at negative index -2
[12:20:54] [debug] AMX backtrace:
[12:20:54] [debug] #0 003f3b1c in public opencrates (i=0) at C:\Users\crist\Desktop\HPQ123 samp gamemode actual cu tot ce trebuie\gamemodes\B-HOOD.pwn:36322

Linia 36322 este aceasta: format(gString, 70, "skin %d (%s)~n~~w~~h~you have %d crates.", amount, CrateName[x], totalcrates(i));

Las mai jos functiile unde apare acel public opencrates:

function startcrates(playerid) {
    for(new l = 0; l < 6; l++) TextDrawShowForPlayer(playerid, CrateTD[l]);
    opencrates(playerid);
    PlayerTextDrawShow(playerid, CratePTD[1]);
    TimerCratesEx[playerid] = SetTimerEx("opencrates", 500, true, "d", playerid);
    return true;
}
function opencrates(i) {
    gString[0] = EOS;
    CrateTime[i] --;
    new amount, rand = random(100), x = !CrateModel[i] ? 0 : CrateModel[i]-1;
    if(CrateModel[i] != 5) {
        switch(rand) {
            case 0..10: {
                LoadSkins(x, amount);
                format(gString, 70, "skin %d (%s)~n~~w~~h~you have %d crates.", amount, CrateName[x], totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], amount);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] == 0) {
                    if(CrateModel[i] <= 0) { 
                        format(gString, 100,"%s, ai deschis o cutie de test si puteai castiga skinul %d (%s).", GetName(i), amount, CrateName[x]);
                        SCM(i, COLOR_WHITE, gString);
                    } else {
                        if(total_skins(i) == 10) {
                            PlayerInfo[i][pCrates][x] ++;
                            save_crates(i);
                            SCM(i, COLOR_LGREEN, "You won the skin, because you already have 10 skins you got the craft back!");
                        } else {
                            format(gString, 120,"(( {%s}%s Crate {A9C4E4}- %s opened a box and won skin %d [%s]. ))", CrateColors[x], CrateName[x], GetName(i), amount, CrateName[x]);
                            SCMTA(COLOR_CLIENT, gString);  
                            give_skin(i, amount);
                        }    
                    }
                    KillTimer(TimerCratesEx[i]);
                    CrateModel[i] = -1;
                }
            }
            case 11..30: {
                amount = random(5) + x * 4;
                format(gString, 75, "~y~%s Respect points~n~~w~~h~you have %d crates.", FormatNumber(amount), totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 1275);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] == 0) {
                    if(CrateModel[i] <= 0) {
                        format(gString, 120,"%s, a deschis o cutie de test si puteai castiga %d Respect points.", GetName(i),amount);
                        SCM(i, COLOR_WHITE, gString);
                    } else {
                        format(gString, 120,"(( {%s}%s Crate {A9C4E4}- %s opened a box and won %d Respect points. ))", CrateColors[x], CrateName[x], GetName(i),amount, CrateName[x]);
                        SCMTA(COLOR_CLIENT, gString); 
                        PlayerInfo[i][pExp] += amount;
                        Update(i, pRP);
                    }
                    KillTimer(TimerCratesEx[i]);
                    CrateModel[i] = -1;
                }
            }
               case 31..40: {
                amount = random(10) + x * 10;
                format(gString, 75, "~y~%s Premium points~n~~w~~h~you have %d crates.", FormatNumber(amount), totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 1275);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] == 0) {
                    if(CrateModel[i] <= 0) {
                        format(gString, 120,"%s, a deschis o cutie de test si puteai castiga %d Premium points.", GetName(i),amount);
                        SCM(i, COLOR_WHITE, gString);
                    } else {
                        format(gString, 120,"(( {%s}%s Crate {A9C4E4}- %s opened a box and won %d Premium points. ))", CrateColors[x], CrateName[x], GetName(i),amount);
                        SCMTA(COLOR_CLIENT, gString); 
                        PlayerInfo[i][pPremiumPoints] += amount;
                        Update(i, pPremiumPointsx);
                    }
                    KillTimer(TimerCratesEx[i]);
                    CrateModel[i] = -1;
                }
            }
            default: {
                amount = random(2000000) + x * 2000000;
                format(gString, 65, "~g~%s~n~~w~~h~you have %d crates.", FormatNumber(amount), totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 1274);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] == 0) {
                    if(CrateModel[i] <= 0) {
                        format(gString, 120,"%s, a deschis o cutie de test si puteai castiga $%s.", GetName(i), FormatNumber(amount));
                        SCM(i, COLOR_WHITE, gString);
                    } else {
                        format(gString, 120,"(( {%s}%s Crate {A9C4E4}- %s opened a box and won {50DB6F}$%s{A9C4E4}. ))", CrateColors[x], CrateName[x], GetName(i), FormatNumber(amount));
                        SCMTA(COLOR_CLIENT, gString); 
                        GivePlayerCash(i, 1, amount);
                    }
                    KillTimer(TimerCratesEx[i]);
                    CrateModel[i] = -1;
                }
            }
        }
    } else {
        switch(rand) {
               case 0..5: {
                amount = RandomEx(30, 250);
                format(gString, 65, "Infernus (PREMIUM)~n~~w~~h~you have %d crates.", totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 411);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] <= 0) {
                    if(Iter_Count(MyVehicle[i]) >= GetSlots(i)) { PlayerInfo[i][pCrates][4] ++; save_crates(i); SCM(i, COLOR_LIGHTGREEN, "Nu ai un slot liber.");  CrateModel[i] = -1; KillTimer(TimerCratesEx[i]); return true; }
                    else {
                        KillTimer(TimerCratesEx[i]);
                        CrateModel[i] = -1;
                        GiveVehicle(i, 411, 0, 0, 1, 0, 0);
                        format(gString, 120, "(( {7556ff}Vehicle Crate {A9C4E4}- %s opened a box and won Infernus PREMIUM. ))", GetName(i));
                        SCMTA(COLOR_CLIENT, gString);
                    }
                }
            }
            case 6..33: {
                amount = random(20) + 20;
                format(gString, 64, "Picador~n~~w~~h~you have %d crates.", totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 600);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] == 0) {
                    if(Iter_Count(MyVehicle[i]) >= GetSlots(i)) { PlayerInfo[i][pCrates][4] ++; save_crates(i); SCM(i, COLOR_LIGHTGREEN, "Nu ai un slot liber.");  CrateModel[i] = -1; KillTimer(TimerCratesEx[i]); return true; }
                    else {
                        KillTimer(TimerCratesEx[i]);
                        CrateModel[i] = -1;
                        GiveVehicle(i, 600, 0, 0, 0, 0, 0);
                        format(gString, 120,"(( {7556ff}Vehicle Crate {A9C4E4}- %s opened a box and won Picador. ))", GetName(i));
                        SCMTA(COLOR_CLIENT,gString);
                    }
                }
            }
            case 34..40: {
                format(gString, 65, "hpv1000~n~~w~~h~you have %d crates.", totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 523);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] <= 0) {
                    if(Iter_Count(MyVehicle[i]) >= GetSlots(i)) { PlayerInfo[i][pCrates][4] ++; save_crates(i); SCM(i, COLOR_LIGHTGREEN, "Nu ai un slot liber.");  CrateModel[i] = -1; KillTimer(TimerCratesEx[i]); return true; }
                    else {
                        KillTimer(TimerCratesEx[i]);
                        CrateModel[i] = -1;
                        GiveVehicle(i, 523, 0, 0, 0, 0, 0);
                        format(gString, 120,"(( {7556ff}Vehicle Crate {A9C4E4}- %s opened a box and won hpv1000. ))", GetName(i));
                        SCMTA(COLOR_CLIENT, gString);
                    }
                }
            }
               case 41..46: {
                format(gString, 65, "NRG-500 (PREMIUM)~n~~w~~h~you have %d crates.", totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 522);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] <= 0) {
                    if(Iter_Count(MyVehicle[i]) >= GetSlots(i)) { PlayerInfo[i][pCrates][4] ++; save_crates(i); SCM(i, COLOR_LIGHTGREEN, "Nu ai un slot liber.");  CrateModel[i] = -1; KillTimer(TimerCratesEx[i]); return true; }
                    else {
                        KillTimer(TimerCratesEx[i]);
                        CrateModel[i] = -1;
                        GiveVehicle(i, 522, 0, 0, 1, 0, 0);
                        format(gString, 120,"(( {7556ff}Vehicle Crate {A9C4E4}- %s opened a box and won NRG-500 PREMIUM. ))", GetName(i));
                        SCMTA(COLOR_CLIENT,gString);
                    }
                }
            }
               case 47..53: {
                format(gString, 65, "ticket (RAINBOW)~n~~w~~h~you have %d crates.", totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 1581);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] <= 0) {
                    KillTimer(TimerCratesEx[i]);
                    CrateModel[i] = -1;
                    PlayerInfo[i][pTickete][0] ++;
                    save_tickete(i);
                    format(gString, 120,"(( {7556ff}Vehicle Crate {A9C4E4}- %s opened a box and won Rainbow Ticket. ))", GetName(i));
                    SCMTA(COLOR_CLIENT, gString);
                }
            }
               case 54..66: {
                format(gString, 65, "ticket (VIP)~n~~w~~h~you have %d crates.", totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 1581);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] <= 0) {
                    KillTimer(TimerCratesEx[i]);
                    CrateModel[i] = -1;
                    PlayerInfo[i][pTickete][1] ++;
                    save_tickete(i);
                    format(gString, 120,"(( {7556ff}Vehicle Crate {A9C4E4}- %s opened a box and won Vip Ticket. ))", GetName(i));
                    SCMTA(COLOR_CLIENT,gString);
                }
            }
            default: {
                format(gString, 65, "Savanna~n~~w~~h~you have %d crates.", totalcrates(i));
                PlayerTextDrawSetPreviewModel(i, CratePTD[0], 567);
                PlayerTextDrawSetString(i, CratePTD[1], gString);
                PlayerTextDrawShow(i, CratePTD[0]);
                if(CrateTime[i] <= 0) {
                    if(Iter_Count(MyVehicle[i]) >= GetSlots(i)) { PlayerInfo[i][pCrates][4] ++; save_crates(i); SCM(i, COLOR_LIGHTGREEN, "Nu ai un slot liber.");  CrateModel[i] = -1; KillTimer(TimerCratesEx[i]); return true; }
                    else {
                        KillTimer(TimerCratesEx[i]);
                        CrateModel[i] = -1;
                        GiveVehicle(i, 567, 0, 0, 0, 0, 0);
                        format(gString, 120,"(( {7556ff}Vehicle Crate {A9C4E4}- %s opened a box and won Savanna. ))", GetName(i));
                        SCMTA(COLOR_CLIENT, gString);
                    }
                }
            }
        }
    }
    return true;
}

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 0
Acum 1 minut, TheGodfather a spus:

Ok, o sa incerc. Totusi nu stiu cum pot reproduce eroarea, ca sa vad daca chestia asta o rezolva

Daca pui ce am scris in edit nu o sa-ti mai dea, pentru ca de fiecare data cand se va apela functia se va reverifica acel x, in ce aveai tu, daca CrateModel era -1 in multe cazuri cum ai de fata, cand se reapela functia iti mai scadea 1 si returna -2, in ce ti-am dat eu, daca CrateModel e -1, x va ramane -1, daca e 0 se va face x -1

new amount, rand = random(100), x = !CrateModel[i] ? 0 : CrateModel[i]-1;

 

Poti face: new amount, rand = random(100), x;

if(CrateModel[i] == -1) x = -1;

else x = CrateModel[i] - 1;

 

Link to comment
Share on other sites

  • 0

[12:20:54] [debug] Run time error 4: "Array index out of bounds"
[12:20:54] [debug]  Accessing element at negative index -2

 

Iti iese din array, poti pune niste printf-uri sa vezi care si cum iese, e mare functia, nu putem afla de unde e problema

 

Ex:

printf("Player ID: %d", playerid); // la on playerconnect ca si exemplu si iti va scrie in consola la fiecare conectare

Link to comment
Share on other sites

  • 0

Pai stiu unde e problema, aici e:
 

[12:20:54] [debug] #0 003f3b1c in public opencrates (i=0) at C:\Users\crist\Desktop\HPQ123 samp gamemode actual cu tot ce trebuie\gamemodes\B-HOOD.pwn:36322

Linia 36322 este aceasta: format(gString, 70, "skin %d (%s)~n~~w~~h~you have %d crates.", amount, CrateName[x], totalcrates(i));

La linia aia. Cand face CrateName[x], uneori x e -2 si atunci da eroarea.

Edited by TheGodfather
Link to comment
Share on other sites

  • 0

Nu m-am uitat la linie, atunci poti face o verificare in felul urmator:

 

if(x < -1) x = 1;

 

Edit: 

 

new amount, rand = random(100), x = !CrateModel[i] ? 0 : CrateModel[i]-1;

 

Poti face: new amount, rand = random(100), x;

if(CrateModel[i] == -1) x = -1;

else x = CrateModel[i] - 1;

Edited by iSkull
Link to comment
Share on other sites

  • 0
Acum 2 minute, iSkull a spus:

Daca pui ce am scris in edit nu o sa-ti mai dea, pentru ca de fiecare data cand se va apela functia se va reverifica acel x, in ce aveai tu, daca CrateModel era -1 in multe cazuri cum ai de fata, cand se reapela functia iti mai scadea 1 si returna -2, in ce ti-am dat eu, daca CrateModel e -1, x va ramane -1, daca e 0 se va face x -1

new amount, rand = random(100), x = !CrateModel[i] ? 0 : CrateModel[i]-1;

 

Poti face: new amount, rand = random(100), x;

if(CrateModel[i] == -1) x = -1;

else x = CrateModel[i] - 1;

 

Ok, hai ca pun acum. Multumesc pentru idee. Daca mai apare eroarea o sa revin cu un comment

Link to comment
Share on other sites

  • 0
La 26.04.2021 la 13:33, iSkull a spus:

Nu m-am uitat la linie, atunci poti face o verificare in felul urmator:

 

if(x < -1) x = 1;

 

Edit: 

 

new amount, rand = random(100), x = !CrateModel[i] ? 0 : CrateModel[i]-1;

 

Poti face: new amount, rand = random(100), x;

if(CrateModel[i] == -1) x = -1;

else x = CrateModel[i] - 1;

Imi da aceeasi eroare in logurile serverului doar ca acum nu mai zice ca e index -2 ci e index -1

Link to comment
Share on other sites

  • 0
Acum 53 minute, TheGodfather a spus:

Imi da aceeasi eroare in logurile serverului doar ca acum nu mai zice ca e index -2 ci e index -1

Ok, atunci, modifica codul in felul urmator, acum o sa fie in array, array-ul incepe de la 0 pana la numarul maxim - 1

Nu am de unde sa stiu ce ai in acel gm si cum functioneaza

new amount, rand = random(100), x;

if(CrateModel[i] > 0) x = CrateModel[i] - 1;
else x = 0;

 

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.