buying a car - 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: buying a car (
/showthread.php?tid=384176)
buying a car -
Yako - 10.10.2012
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
Re: buying a car -
TzAkS. - 10.10.2012
Make a value for modelid and make it the price..you need to make this for all models.
Re: buying a car -
Skillet` - 10.10.2012
Код:
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.
Re: buying a car -
AndreT - 10.10.2012
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!