Getting vehicle price according to modelid
#1

Hello there,

I need to make a stock to get the vehicle's price according to the modelid that I HAVE, and I tried several times and I failed, can anyone help me and give me examples of creating one!?, I would appreciate it

like: if the modelid is 560 the price will be $150,000.

Thanks in advance.
Reply
#2

pawn Код:
public GetVehiclePrice(vehicleid)
{
    new model = GetVehicleModel(vehicleid);
    if(model == 400) return price;
    else if(model == 401) return price;
    else if(model == 402) return price;
    else if(model == 403) return price;
    else if(model == 404) return price;
    else if(model == 405) return price;
    else if(model == 406) return price;
    else if(model == 408) return price;
    else if(model == 409) return price;
    else if(model == 410) return price;
    else return 0;
}
That is basic, define more models if you want
Reply
#3

That would be extremely inefficient. In any case use a switch statement. Or better yet, create an array. If you want to include all 212 models you may want to use a 1-dimensional array. Otherwise you may want to use a 2-dimensional array (model => price).

1-Dimensional example
pawn Код:
new vPrices[212] = {
    40000, // model 400
    50000, // model 401
    ...
    10000 // model 611
}
2-dimensional example:
pawn Код:
new vPrices[][] = {
    {402, 100000},
    {411, 150000},
    {415,  90000},
    {451,  75000}
}
Reply
#4

thanks a lot but, how do I call the array using the two diminstional thing like
VPrice[modelid][price]
Thanks in advance
Just please tell me how to call it
Reply
#5

If you use 2D array, then you'll need to loop through it.

pawn Код:
for (new i; i != sizeof (vPrices); ++i)
{
    if (vPrices[i][0] == modelid)
    {
        // modelid was found. Use: vPrices[i][1] as price.
        break;
    }
}
Reply
#6

Quote:
Originally Posted by Natric
Посмотреть сообщение
thanks a lot but, how do I call the array using the two diminstional thing like
VPrice[modelid][price]
Thanks in advance
Just please tell me how to call it
If i were you really, i would jump into some MySQL coding. Won't be just as efficient, but it allows you to have dynamic prices. So if you want to change the prices while the server is running, nothing is stopping you from doing so. You can do that with arrays as well, but it's alot easier doing so with MySQL.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)