[HELP]Count Vehicles[HELP]!!! - 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: [HELP]Count Vehicles[HELP]!!! (
/showthread.php?tid=371052)
[HELP]Count Vehicles[HELP]!!! -
Cjgogo - 22.08.2012
OK,so I wanted a command that would return the numbers of cars I have in my server,yet,the command I made always return 2000(MAX_VEHICLES),so I don't see what's worng,help me pls?
pawn Код:
COMMAND:countcars(playerid,params[])
{
new counter=0;
for(new i=0;i<MAX_VEHICLES;i++)
{
if(i!=INVALID_VEHICLE_ID)
{
counter++;
}
}
new string[128];
format(string,sizeof(string),"%d",counter);
SendClientMessage(playerid,COLOR_RED,string);
return 1;
}
Re: [HELP]Count Vehicles[HELP]!!! -
RedFusion - 22.08.2012
Try using an integer %i instead of %d.. Just a wild guess
Re: [HELP]Count Vehicles[HELP]!!! -
Cjgogo - 22.08.2012
It's the same thing,this is a real wild guess,plus it would return the same number even if the variable type was different,as %f wich means float value,would return 2000.0000,so anyone else?
Re: [HELP]Count Vehicles[HELP]!!! -
[MM]RoXoR[FS] - 22.08.2012
You may like to look
https://sampwiki.blast.hk/wiki/IsValidVehicle
pawn Код:
native IsValidVehicle(vehicleid);
// Count vehicles
public OnPlayerCommandText(playerid,cmdtext[])
{
if(!strcmp(cmdtext,"/countvehicles",true))
{
new
count,
msg[60];
for(new i; i < MAX_VEHICLES; i++)
{
if(IsValidVehicle(i)) count++;
}
format(msg, sizeof(msg), "* There are %d valid spawned vehicles on this server.", count);
SendClientMessage(playerid, 0x33CCCCFF, msg);
return 1;
}
return 0;
}
Re: [HELP]Count Vehicles[HELP]!!! - HuSs3n - 22.08.2012
pawn Код:
for(new i=0;i<MAX_VEHICLES;i++)
{
if(i!=INVALID_VEHICLE_ID)
{
counter++;
}
}
MAX_VEHICLES is defined as 2000 , and INVALID_VEHICLE_ID is 0xFFFF
in your loop you are actually counting the numbers from 1-2000 that are not equal to 0xFFFF , that why it will return 2000 always
to count the vehicles you need to use IsValidVehicle();
Re: [HELP]Count Vehicles[HELP]!!! -
Cjgogo - 22.08.2012
OK,thank you guys,rep + for you 2(Husen&Ron)