finding out how many cars you have
#1

Ok so in order to make a car ownership filterscript work i need to know how many cars i have in my gm ,does anybody know a SURE way to find out ? I was trying with /gotocar ,but is that a sure way?


thx in advance
Reply
#2

I got this in a script of mine, and it works like a charm: (Slightly edited)

pawn Код:
stock CountVehicles()
{
    new carcount;
    for(new v = 0; v < 2000; v++)
    {
        if(GetVehicleModel(v) != 0)
        {
            carcount++;
        }
    }
    return carcount;
}
Reply
#3

ok and the "number of vehicle models" i see in the console is the number of cars ?
Reply
#4

No, it is, as it says, the number of vehicles models you have created. Models are the type of the vehicle (like a hydra, rhino, infernus, etc)
Reply
#5

myea well i dont understand where do i see the carcount ?
Reply
#6

That's what the function I pasted earlier is for. After you created the vehicles you can use the function and store what it returns, it returns the amount of cars.
Reply
#7

what i meant was,i need to make a command to use that stock or how can i use it (after adding it to the gamemode ) ? im sorry for bothering you but i never used /added stock's before xD...
Reply
#8

An example on how to use it to print the amount of vehicles when the server starts:
pawn Код:
public OnGameModeInit()
{
    //Add your static vehicles here
    //And when they are created, we want to count them and print it into the console
    new carscounted;
    carscounted = CountVehicles();
    printf("[OnGameModeInit] Cars counted: %d", carscounted);

    //Can also be done shorter, but it was an example to show how to store what
    //CountVehicles() returns into the 'carscounted'
}
The example above only get to count the vehicles you have added in OnGameModeInit. If you want it in a command, it's the same princip:
pawn Код:
CMD:countcars(playerid, params[])//This example uses ZCMD
{
    printf("[Command countcars] Cars counted: %d", CountVehicles());
    return 1;
}//When you type /countcars in game, it'll print the amount of cars into the console.
Reply
#9

thanks a lot man ,i did the on game mode init part and it shows me perfectly ,i have 351 cars,the weird thing is that ingame i could /gotocar till...353 or doesnt the stock you gave me count the cars that are added like this ?
pawn Код:
mike = CreateVehicle(560,-258.0227,1517.3728,75.4593,29.6496,1,1, 20000);
Reply
#10

The stock will count all vehicles. Also the mike = CreateVehicle(.....).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)