How to count script cars?
#1

So, how to count script cars? Im using AddStaticVehicle and AddStaticVehicleEx.
Reply
#2

pawn Код:
//Top of script:
new VehInfo[MAX_VEHICLES]=0;
//OnVehicleSpawn:
VehInfo[vehicleid] = 1;//Vehicle exists
//In a script to count vehicles:
new count=0;
for(new i = 0; i < MAX_VEHICLES; i++)
{
    if(VehInfo[i] == 1)
    {
        count++;
    }
}
printf("There are %d vehicles.",count);
Reply
#3

Assuming static cars only:
pawn Код:
new gStaticCars; // Global var

// GameModeInit
AddStaticVehicle(...);
AddStaticVehicle(...);
AddStaticVehicle(...);
gStaticCars = AddStaticVehicle(...); // This is to be the last vehicle that was created!

printf("There are %d cars.", gStaticCars);
Assuming dynamic cars:
pawn Код:
new DynCars;
for(new v = 1; v < MAX_VEHICLES; ++v)
{
    if(!GetVehicleModel(v)) continue;
    DynCars++;
}
Reply
#4

Vince, it worked. ;>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)