[HELP]Count Vehicles[HELP]!!!
#1

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;
}
Reply
#2

Try using an integer %i instead of %d.. Just a wild guess
Reply
#3

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?
Reply
#4

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;
}
Reply
#5

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();
Reply
#6

OK,thank you guys,rep + for you 2(Husen&Ron)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)