Vehicle and Object spawn stock stopped working
#1

As the title says, my stock stopped working after I added a loop for creating objects. And I've already implemented a warning to prevent the amount of objects and the amount of cars to not exceed the amount of spawn coordinates.

pawn Код:
stock CreateDynCars()
{
    vcleanup();
    for(spawncar=0;spawncar<MAX_CARS;spawncar++)
    {
        new model, color1, color2, spawnid;
        model = random(11);
        color1 = random(11);
        color2 = random(11);
        spawnloop:
        spawnid = random(sizeof(vSpawns));
        if(SpawnUsed[spawnid] == true) goto spawnloop;
        SpawnUsed[spawnid] = true;
        switch(model)
        {
            case 0:{model = 404;}
            case 1:{model = 405;}
            case 2:{model = 410;}
            case 3:{model = 421;}
            case 4:{model = 422;}
            case 5:{model = 426;}
            case 6:{model = 436;}
            case 7:{model = 445;}
            case 8:{model = 458;}
            case 9:{model = 491;}
            case 10:{model = 492;}
        }
        switch(color1)
        {
            case 0:{color1 = 8;}
            case 1:{color1 = 9;}
            case 2:{color1 = 10;}
            case 3:{color1 = 11;}
            case 4:{color1 = 12;}
            case 5:{color1 = 13;}
            case 6:{color1 = 14;}
            case 7:{color1 = 15;}
            case 8:{color1 = 37;}
            case 9:{color1 = 38;}
            case 10:{color1 = 39;}
        }
        switch(color2)
        {
            case 0:{color2 = 8;}
            case 1:{color2 = 9;}
            case 2:{color2 = 10;}
            case 3:{color2 = 11;}
            case 4:{color2 = 12;}
            case 5:{color2 = 13;}
            case 6:{color2 = 14;}
            case 7:{color2 = 15;}
            case 8:{color2 = 37;}
            case 9:{color2 = 38;}
            case 10:{color2 = 39;}
        }
        DynVehicle[spawncar] = CreateVehicle(model,vSpawns[spawnid][0],vSpawns[spawnid][1],vSpawns[spawnid][2],vSpawns[spawnid][3],color1,color2,-1);
        engloop:
        vInfo[DynVehicle[spawncar]][engine] = random(875);
        if(vInfo[DynVehicle[spawncar]][engine] <= 250) goto engloop;
        SetVehicleHealth(DynVehicle[spawncar],vInfo[DynVehicle[spawncar]][engine]);
        vInfo[DynVehicle[spawncar]][tires] = random(4);
        vInfo[DynVehicle[spawncar]][gas] = random(50);
        new str[128];
        format(str,sizeof(str),"Engine: %.0f\nTires: %i\nGas: %i", vInfo[DynVehicle[spawncar]][engine],vInfo[DynVehicle[spawncar]][tires],vInfo[DynVehicle[spawncar]][gas]);
        CarInfo[spawncar] = Create3DTextLabel(str,COLOR_WHITE,0,0,0,3,-1,0);
        Attach3DTextLabelToVehicle(CarInfo[spawncar],DynVehicle[spawncar],0,0,1);
    }
    for(new i=0;i<MAX_DUMPS;i++)
    {
        new spawnid;
        spawnloop:
        spawnid = random(sizeof(vSpawns));
        if(SpawnUsed[spawnid] == true) goto spawnloop;
        SpawnUsed[spawnid] = true;
        Dump[i] = CreateObject(1415,vSpawns[spawnid][0],vSpawns[spawnid][1],vSpawns[spawnid][2] - 1,0,0,vSpawns[spawnid][3] + 180);
        DumpInfo[i] = Create3DTextLabel("Dumpster\n(/search)",COLOR_WHITE,vSpawns[spawnid][0],vSpawns[spawnid][1],vSpawns[spawnid][2],5,0,0);
    }
    return 1;
}
Reply
#2

If a run time error 4 is caused inside that function, then it will stop the code. Use crashdetect plugin to be sure.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
If a run time error 4 is caused inside that function, then it will stop the code. Use crashdetect plugin to be sure.
Thanks Konstantinos, it did show a run time error 4. My next question is where it occurs lol.

EDIT: After attempting to fix the error, I still get the error output.

Код:
[11:15:14] [debug] Run time error 4: "Array index out of bounds"
[11:15:14] [debug]  Accessing element at index 4 past array upper bound 3
[11:15:14] [debug] AMX backtrace:
[11:15:14] [debug] #0 00007994 in ?? () from dyn_cars.amx
[11:15:14] [debug] #1 000065b4 in ?? () from dyn_cars.amx
[11:15:14] [debug] #2 00008c24 in public SSCANF_OnGameModeInit () from dyn_cars.amx
[11:15:14] [debug] #3 native CallLocalFunction () [00472ad0] from samp-server.exe
[11:15:14] [debug] #4 00000878 in public OnGameModeInit () from dyn_cars.amx
Reply
#4

Use debug info: https://github.com/Zeex/samp-plugin-...ith-debug-info

Re-compile, start the server and post the results again (this time with the line caused it).

Just so you know, an array was declared with size of 4. That means that the valid (in-bound) indexes are 0-3 and it passed 4 as index.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Use debug info: https://github.com/Zeex/samp-plugin-...ith-debug-info

Re-compile, start the server and post the results again (this time with the line caused it).

Just so you know, an array was declared with size of 4. That means that the valid (in-bound) indexes are 0-3 and it passed 4 as index.
Good News: I get the same error.

Bad News: I narrowed it to 1 line after fixing the previous errors:

pawn Код:
//Delete3DTextLabel(DumpInfo[i]); << error line

//relevant
DumpInfo[i] = Create3DTextLabel("Dumpster\n(/search)",COLOR_WHITE,vSpawns[spawnid][0],vSpawns[spawnid][1],vSpawns[spawnid][2],5,0,0);
// (spawnid is a random number)

// spawn array example
{ 1715.647460, -1925.997436, 13.368518, 41.241798 },
I'd give you rep, but it seems I gave it to you already too recently. lol
Reply
#6

In the loop you use Delete3DTextLabel function, the loop shouldn't be called more than the size of DumpInfo array.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
In the loop you use Delete3DTextLabel function, the loop shouldn't be called more than the size of DumpInfo array.
Thanks buddy! I fixed it and its working fine now. Glad you're the Godfather of SAMP!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)