SA-MP Forums Archive
[HELP] Continuously vehicle spawning - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Continuously vehicle spawning (/showthread.php?tid=181978)



[HELP] Continuously vehicle spawning - Pooh7 - 08.10.2010

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?


Re: [HELP] Continuously vehicle spawning - Mauzen - 08.10.2010

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


Re: [HELP] Continuously vehicle spawning - Pooh7 - 08.10.2010

It works, thank you