Vehicle ownership - foreach iterator
#1

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;
PHP Code:
for (new 0MAX_PLAYER_VEHICLESji++)
{
    
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);
    }

Output would be;
Code:
Sultan
Bullet
Sanchez
Empty
Empty
Empty
Empty ...
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,
Code:
new vehicleid = g_House[houseid][h_pVehs][listitem];
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;
PHP Code:
new 
    
houseid
    
vehicleid;
houseid g_Player[playerid][p_HouseID];
vehicleid g_House[houseid][h_pVehs][listitem];
if (
vehicleid != 0)
{
    new 
idxquery[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_Handlequery"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(playeridCOL_LIGHT_YELLOWsprintf("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(playeridD_CARDEALERDIALOG_STYLE_LIST"Vehicle dealer""Purchase\nRent\nSell\nFetch unparked vehicle - Cost: $15,000""Select""Close");

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.
Reply
#2

Sure, I would like to see how it can be done. I spent good hours yesterday trying to figure it out but no luck.
Reply
#3

Great! That just worked perfectly even tho it took a while for me to get it working. Thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)