How to count script cars? - 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)
+--- Thread: How to count script cars? (
/showthread.php?tid=308727)
How to count script cars? -
vent - 04.01.2012
So, how to count script cars? Im using AddStaticVehicle and AddStaticVehicleEx.
Re: How to count script cars? -
coole210 - 04.01.2012
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);
Re: How to count script cars? -
Vince - 04.01.2012
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++;
}
Re: How to count script cars? -
vent - 04.01.2012
Vince, it worked. ;>