Wrong loop result.
#1

Hello, I'm trying to implement vehicle price to dialog title and I'm trying to use loop to get correct price from model id.

I got this codes;

Code:
new VehiclePrices[47][47] =
{
   // {model, price}
   {400, 40000}, //Landstalker
   {600, 44000}, //Picador
   {602, 60500} //Alpha
};
So when a player in vehicle model 400 I want it to show "40000" on dialog title but instead of this it shows "60500" which is for veh model 602.

Here is my looping codes;

Code:
stock ShowVehicleDialog(playerid)
{
	for ( new i = 0; i < sizeof(VehiclePrices); i++ )
    {
	new vid = GetPlayerVehicleID(playerid), model = GetVehicleModel(vid);
	new price = VehiclePrices[i][1];
	new str[256];
	format(str, sizeof(str), "%s %d "COL_DGREEN"$%d", VehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid))-400], model, FormatNumber(price);
	Dialog_Show(playerid, BUYVEHICLE, DIALOG_STYLE_LIST, str,"Test", "Seз", "İptal");
	}
	return 1;
}
So, it gets the vehicle name from the vehiclenames correctly but it doesn't loop vehicle price correctly, it starts from the end.

So, how can I fix this code or do you guys have any other suggestions for this.
Reply
#2

First of all change your VehiclePrices declaration to this :
Quote:

new VehiclePrices[47][2]

Then use this code:
PHP Code:
stock ShowVehicleDialog(playerid)
{
    new 
model GetVehicleModel(GetPlayerVehicleID(playerid)), found = -1;
    for ( new 
0sizeof(VehiclePrices); i++ )
    {
        if(
model == VehiclePrices[i][0])
        {
            
found i;
            break;
        }
    }    
    new 
str[100];
    if(
found == -1)str "Model not found";
    
//note the difference in format parameters in next line
    
else format(strsizeof(str), "%s %d "COL_DGREEN"$%d"VehicleNames[model-400], modelFormatNumber(VehiclePrices[found][1]));
    
Dialog_Show(playeridBUYVEHICLEDIALOG_STYLE_LISTstr,"Test""Seз""İptal");    
    return 
1;

Reply
#3

I did as you said but unfortunately it didn't work, now it shows $52 for the price


as you can see here: http://i.imgur.com/uh6Pk7n.jpg


but there is no 52 in my prices, my exact declaration for prices is like this :

Code:
new VehiclePrices[47][2] =
{
   // {model, price}
   {400, 40000}, //Landstalker
   {401, 36000}, //Bravura
   {402, 125000}, //Buffalo
   {404, 18000}, //Perenial
   {410, 14500}, //Manana
   {412, 40000}, //VooDoo
   {418, 20000}, //Moonbeam
   {419, 54000}, //Esperanto
   {422, 48000}, //Bobcat
   {436, 35000}, //Previon
   {445, 60000}, //Admiral
   {458, 60000}, //Solair
   {466, 38000}, //Glendale
   {467, 50500}, //Oceanic
   {474, 48000}, //Hermes
   {475, 56000}, //Sabre
   {478, 20000}, //Walton
   {479, 40000}, //Regina
   {482, 54000}, //Burrito
   {489, 52000}, //Rancher
   {491, 46500}, //Virgo
   {492, 46000}, //Greenwood
   {496, 42000}, //BlistaC
   {500, 54000}, //Mesa
   {516, 38000}, //Nebula
   {517, 40500}, //Majestic
   {518, 42000}, //Buccaneer
   {526, 39500}, //Fortune
   {527, 28500}, //Cadrona
   {529, 50000}, //Willard
   {534, 66000}, //Remington
   {536, 54000}, //Blade
   {542, 19000}, //Clover
   {543, 30000}, //Sadler
   {546, 45500}, //Intruder
   {547, 44500}, //Primo
   {549, 19500}, //Tampa
   {551, 44000}, //Merit
   {554, 58000}, //Yosemite
   {566, 48000}, //Tahoma
   {567, 50000}, //Savanna
   {576, 36000}, //Tornado
   {579, 70000}, //Huntley
   {585, 80000}, //Emperor
   {589, 63000}, //Club
   {600, 44000}, //Picador
   {602, 60500} //Alpha
};
Reply
#4

Okay, when I deleted the "formatnumber" it did work and now showing correct but I would like to use my formatnumber stock too it puts "," to numbers like "$40,000"

Anything I could do to fix this?

here is my format number stock

Code:
stock FormatNumber(Float:amount)
{
	new str[16];
	format(str, sizeof(str), "%d", floatround(amount));
	new l = strlen(str);
	if (amount < 0) // -
	{
  		if (l > 4) strins(str, ",", l-3);
		if (l > 7) strins(str, ",", l-6);
		if (l > 10) strins(str, ",", l-9);
	}
	else
	{
		if (l > 3) strins(str, ",", l-3);
		if (l > 6) strins(str, ",", l-6);
		if (l > 9) strins(str, ",", l-9);
	}
	return str;
}
Reply
#5

Oh, okay I managed to fix it, thank you so much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)