How do I count how many there are? - 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 do I count how many there are? (
/showthread.php?tid=351217)
How do I count how many there are? -
Stevee - 15.06.2012
Hi, I have this so far:
pawn Код:
enum TGarbageStops
{
RouteNumber,
TrashDepot,
Score,
Locations[10] // Maximum of 10 different trash pickups
}
new AGarbageCollectorRoutes[][TGarbageStops] =
{
{1, 140, 1, {138, 139, 138, 139}},
{2, 140, 2, {139, 138, 139, 138, 139, 138, 139}},
{3, 140, 3, {138, 139, 138, 139, 138, 139, 138, 139, 138, 139}}
};
I want to count how many locations there are in the Location part of the stops, for example in Route Number 3, there are
Код:
138, 139, 138, 139, 138, 139, 138, 139, 138, 139
which totals to 10 locations, I've tried using this:
pawn Код:
TotalToPickup = AGarbageCollectorRoutes[routeid][Locations];
to find out how many locations there are, but it comes back with the first value of the location (138 or 139)
edit: routeid is either 1, 2 or 3 (random)
Re: How do I count how many there are? - HuSs3n - 15.06.2012
pawn Код:
stock Count_Locations(ID)
{
new a;
for(new x=0; x<10; x++)
{
if(AGarbageCollectorRoutes[ID][Locations][x] > 0) a++;
}
return a;
}
useage
pawn Код:
printf("%d",Count_Locations(0));
printf("%d",Count_Locations(1));
printf("%d",Count_Locations(2));
will output
Re: How do I count how many there are? -
Stevee - 15.06.2012
Quote:
Originally Posted by HuSs3n
pawn Код:
stock Count_Locations(ID) { new a; for(new x=0; x<10; x++) { if(AGarbageCollectorRoutes[ID][Locations][x] > 0) a++; } return a; }
useage
pawn Код:
printf("%d",Count_Locations(0)); printf("%d",Count_Locations(1)); printf("%d",Count_Locations(2));
will output
|
Thanks, that worked like a charm! Highly appreciated!