[HELP] Continuously vehicle spawning
#1

Hi

I'm making a Vehicle ownership, and I have a big problem. When I select vehicle what I want to buy, this vehicle is spawning, and spawning, and spawning without end... After several seconds of continuously vehicle spawning, my game is crashed and in file of vehicles I found 49 created vehicles.

Here is part of code from OnDialogResponse:

Код:
if(dialogid == 3)
    {
        if(response == 1)
        {
            if(listitem == 0)
            {
                if(GetPlayerMoney(playerid) >= 10000)
                {
                    for(new i = 1; i < sizeof(Vozila); i++ )
                    {
                        new ime[64];
                        GetPlayerName(playerid, ime, sizeof(ime));
                        Vozila[i][mKoristen] = 1;
                        Vozila[i][mModel] = 400; // Vehicle model
                        Vozila[i][mX] = 563.8199; // X Coordinates
                        Vozila[i][mY] = -1281.3009; // Y Coordinates
                        Vozila[i][mZ] = 16.8139; // Z Coordinates
                        Vozila[i][mA] = 17.0637; / Angle
                        Vozila[i][mpBoja] = 0; // Color 1
                        Vozila[i][mdBoja] = 0; // Color 2
                        Vozila[i][mZakljucan] = 0; // Locked
                        Vozila[i][mBroj] = 1;
                           Vozila[i][mOsobno] = CreateVehicle(Vozila[i][mModel], Vozila[i][mX], Vozila[i][mY], Vozila[i][mZ], Vozila[i][mA], Vozila[i][mpBoja], Vozila[i][mdBoja], 60000);
                        GivePlayerMoney(playerid, -10000);
                        strmid(Vozila[i][mVlasnik], ime, 0, strlen(ime), 999);
                           PlayerInfo[playerid][pAuto] = i;
                        UpdateVozilo(i); // File update
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GRAD2, "Nemate dovoljno novca.");
                }
            }

            if(listitem == 1)
            {
                if(GetPlayerMoney(playerid) >= 17000)
                {
                       for(new i = 1; i < sizeof(Vozila); i++ )
                    {
                        new ime[64];
                        GetPlayerName(playerid, ime, sizeof(ime));
                        Vozila[i][mKoristen] = 1;
                        Vozila[i][mModel] = 402; // Vehicle model
                        Vozila[i][mX] = 563.8199; // X Coordinates
                        Vozila[i][mY] = -1281.3009; // Y Coordinates
                        Vozila[i][mZ] = 16.8139; // Z Coordinates
                        Vozila[i][mA] = 17.0637; / Angle
                        Vozila[i][mpBoja] = 0; // Color 1
                        Vozila[i][mdBoja] = 0; // Color 2
                        Vozila[i][mZakljucan] = 0; // Locked
                        Vozila[i][mBroj] = 1;
                           Vozila[i][mOsobno] = CreateVehicle(Vozila[i][mModel], Vozila[i][mX], Vozila[i][mY], Vozila[i][mZ], Vozila[i][mA], Vozila[i][mpBoja], Vozila[i][mdBoja], 60000);
                        GivePlayerMoney(playerid, -17000);
                        strmid(Vozila[i][mVlasnik], ime, 0, strlen(ime), 999);
                           PlayerInfo[playerid][pAuto] = i;
                        UpdateVozilo(i); // File update
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GRAD2, "Nemate dovoljno novca.");
                }
            }
        }
    }
So, why is my vehicles not stop creating?
Reply
#2

You have to break the for loop, because it runs again and again, as long as i < sizeof(Vozila)

So just add
break;
at the end of both of your for loops and it should only spawn one vehicle
Reply
#3

It works, thank you
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)