07.07.2016, 08:35
So, I have successfully converted my vehicle ownership system from standard loop to foreach. But, I am having a problem with vehicle list (dialog).
Let me explain further:
With standard loop, I was able to format the vehicle list in the following way;
Output would be;
The MAX_PLAYER_VEHICLES is defined 12, so it shows 12 rows in the list.
In the sell vehicle dialog, I would grab the vehicle ID from the listitem as a slot like,
But now, after using foreach, I am not able to add an empty slot in the dialog (listitem) while formatting the list. Therefore, whenever a player selects one of their vehicle from the list to sell, it mess up all the vehicle slots. Like, if they select the first slot, it works. If they select the third slot, it says there's no vehicle in this slot but the vehicle name is still there.
Sell vehicle dialog;
I am totally out of idea how can I get the slot fixed when they sell their vehicle. Is there any possible ways I could sync the slots? I mean, like if they sell a vehicle from slot 3, vehicle from slot 4 would pass into slot 3 automatically.
Rest of the stuff works just fine, except for the slot getting messed up with the sell vehicle dialog. Any help will be appreciated a lot. Thanks.
Let me explain further:
With standard loop, I was able to format the vehicle list in the following way;
PHP Code:
for (new i = 0, j = MAX_PLAYER_VEHICLES; i < j; i++)
{
vehicleid = g_House[houseid][h_pVehs][i];
if (vehicleid != 0)
{
idx = vehicle_ReturnIndex(GetVehicleModel(vehicleid));
format(list, sizeof(list), "%s%s\n", list, g_DealerCars[idx][car_Name]);
}
else
{
format(list, sizeof(list), "%sEmpty\n", list);
}
}
Code:
Sultan Bullet Sanchez Empty Empty Empty Empty ...
In the sell vehicle dialog, I would grab the vehicle ID from the listitem as a slot like,
Code:
new vehicleid = g_House[houseid][h_pVehs][listitem];
Sell vehicle dialog;
PHP Code:
new
houseid,
vehicleid;
houseid = g_Player[playerid][p_HouseID];
vehicleid = g_House[houseid][h_pVehs][listitem];
if (vehicleid != 0)
{
new idx; query[100];
idx = vehicle_ReturnIndex(GetVehicleModel(vehicleid));
DestroyVehicle(vehicleid);
DestroyDynamic3DTextLabel(g_Vehicle[vehicleid][v_OwnerText]);
g_House[houseid][h_pVehs][listitem] = 0;
// I tried this but no luck.
//Iter_Remove(p_Veh[houseid], listitem);
//printf("Removed slot: %i", listitem);
Query("DELETE FROM `vehicles` WHERE `id`='%d'", g_Vehicle_DB_ID1[vehicleid]);
mysql_tquery(SQL_Handle, query, "ExecuteQuery", "i", RESULT_NONE);
new _x[e_VEHICLE_DATA];
g_Vehicle[vehicleid] = _x;
g_Player[playerid][p_Money] += (g_DealerCars[idx][car_Price] / 2);
return client_Msg(playerid, COL_LIGHT_YELLOW, sprintf("You have sold your %s for $%s", g_DealerCars[idx][car_Name], AddCommas(g_DealerCars[idx][car_Price] / 2)));
}
else
{
return Error("This slot is empty."),
ShowPlayerDialog(playerid, D_CARDEALER, DIALOG_STYLE_LIST, "Vehicle dealer", "Purchase\nRent\nSell\nFetch unparked vehicle - Cost: $15,000", "Select", "Close");
}
Rest of the stuff works just fine, except for the slot getting messed up with the sell vehicle dialog. Any help will be appreciated a lot. Thanks.