SA-MP Forums Archive
Help with converting this (?) - 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: Help with converting this (?) (/showthread.php?tid=610486)



Help with converting this (?) - Sjn - 24.06.2016

Can someone tell me how can I use ternary operators for this code? I tried but ended up with errors lol.

PHP код:
if (_house_HasVehicles(houseid))
{
    for (new 
0MAX_PLAYER_VEHICLESji++)
    {
        if (
g_HouseData[houseid][h_pVehs][i])
        {
            
idx vehicle_ReturnIndex(GetVehicleModel(g_HouseData[houseid][h_pVehs][i]));
            if (
g_VehicleData[g_HouseData[houseid][h_pVehs][i]][v_Parked])
                
format(list, sizeof(list), "%s%s\tParked\n", list, g_DealerCars[idx][car_Name]);
            else
                
format(list, sizeof(list), "%s%s\tUnparked\n", list, g_DealerCars[idx][car_Name]);
        }
        else
            
format(list, sizeof(list), "%sEmpty\n", list);
    }
    
format(list, sizeof(list), "Vehicle\tStatus\n%s", list);
    
ShowPlayerDialog(playeridD_UNPARKEDVEHICLESDIALOG_STYLE_TABLIST_HEADERS"Your vehicles", list, "Select""Back");

Or if it's not possible, then are there any better ways to format this list? This right now just works fine but I am just looking for other ways if there's any. Which is probably better than this.


Re: Help with converting this (?) - Stinged - 24.06.2016

I think you can also do the middle one, but then again I'm not great with ternary operators.
Код:
format(list, sizeof(list), "%s%s\t%s\n", list, g_DealerCars[idx][car_Name], (g_VehicleData[g_HouseData[houseid][h_pVehs][i]][v_Parked] > 0) ? ("Parked") : ("Unparked"));



Re: Help with converting this (?) - Sjn - 24.06.2016

Alright, that just gave me a new idea, thanks.

But apart from ternary operator, is there any other way I can format huge lists like this for dialogs? Cause I saw a post someone writing before that this method is inefficient.


Re: Help with converting this (?) - Stinged - 24.06.2016

car_Name is probably a string.
If it is, I guess you can use strcat.

Код:
strcat(list, g_DealerCars[idx][car_Name]);
strcat(list, "\tParked\n");