buying a car
#1

Hello guys, I making a cars buying systemand I made a command
/buy [modelid] [color1] [color2]
And I want to make the list of buyable cars.
Such as:
Infernus - 5000$

But I'don't know how to make that every model id would have its price. I mean when you type /buy [modelid] [color1] [color2] the code takes that much money as it would be set
Reply
#2

Make a value for modelid and make it the price..you need to make this for all models.
Reply
#3

Код:
if(modelid == id) {
    GivePlayerMoney(playerid, -price);
}
and if you have few vehicles with the same price
Код:
if(modelid == id || modelid == id) {
    GivePlayerMoney(playerid, -price);
}
thats the only way I guess.
Reply
#4

Quote:
Originally Posted by Skillet`
Посмотреть сообщение
Код:
if(modelid == id) {
    GivePlayerMoney(playerid, -price);
}
and if you have few vehicles with the same price
Код:
if(modelid == id || modelid == id) {
    GivePlayerMoney(playerid, -price);
}
thats the only way I guess.
Actually, no...

You should create an array to store all the vehicle prices, it should probably look something like this:
pawn Код:
new gVehiclePrices[] = {
    50000, // Landstalker (400)
    45000, // Bravura (401)
    ...
};
Notice how this is a very rough idea out of the box and will require finetuning. In case you only want to have a predefined list of vehicles that can be bought (notice how the list above will automatically somewhat assume that you're able to buy vehicles like the utility trailer, trailers, combains and so on), it should look like this:
pawn Код:
new gVehiclesList[][] = {
    {400, 50000}, // Landstalker to cost 50k
    ...
    {609, 70000} // Boxville to cost 70k
}
And yes, this is also a somewhat rough idea that can be improved upon, for example ****** has written about a similar issue in his Code optimisations topic (search it up!).

But to formulate a list of buyable vehicles into a dialog, you could come up with something like this:
pawn Код:
new dialog_content[1024],
    temp[64];

for(new i = 0; i != sizeof(gVehiclesList); i++)
{
    // Format the line (for example "Boxville - $70000" with a newline ending)
    format(temp, sizeof(temp), "%s - $%d\n", gVehiclesList[i][0], gVehiclesList[i][1]);
    // And append the newly-formatted line to the whole dialog content
    strcat(dialog_content, temp);
}

// Now display the content. Also consider adding pages or categories to this.
Good luck scripting!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)