A question about "new" and dialogs
#1

I got this atm in my gamemode, is a basic vehicle selling system, i ordered the vehicles with their name and price:

pawn Код:
new VehicleInfo[212][v_info] =
{
        {"Landstalker",10000},
        {"Bravura",10000},
        {"Buffalo",10000},
        {"Linerunner",10000},
        {"Perrenial",10000},
        {"Sentinel",10000},
        {"Dumper",10000},
        {"Firetruck",10000},
        {"Trashmaster",10000},
        {"Stretch",10000},
        {"Manana",10000}

//And so on
};
My question is, is possible to create a dialog that will list all the vehicles listed in that "new" with the price?

Something like /vehiclesthatcanbesold, and a dialog will popup with that list (Vehicle Name - Price).

In short, a dynamic dialog loaded by that array. Is it possible? If yes, how?
Reply
#2

pawn Код:
// Set your defines, this helps to reference certain values later on as we can't use sizeof() to determine the size
#define MAX_VEHICLE_MODELS 11
// Again, set an ID for the dialog. You will want to set a unique number here, so OnDialogResponse doesn't make mistakes handling your dialog code.
#define DIALOG_VEHICLES 2

// Create an enum with the two variables
enum v_info {
    v_szName[32],
    v_iPrice
}

// Populate the data in the enum with the MAX_VEHICLE_MODELS dimension
new VehicleInfo[MAX_VEHICLE_MODELS][v_info] =
{
        {"Landstalker",10000},
        {"Bravura",10000},
        {"Buffalo",10000},
        {"Linerunner",10000},
        {"Perrenial",10000},
        {"Sentinel",10000},
        {"Dumper",10000},
        {"Firetruck",10000},
        {"Trashmaster",10000},
        {"Stretch",10000},
        {"Manana",10000}
};

// Here's a function to show a player the vehicle list, along with prices.
stock ShowPlayerVehicleList(playerid) {
    new
        szDialogMessage[32 * MAX_VEHICLE_MODELS]; // Set a large size for this variable, as we will overflow smaller sized variables. We need to populate the list with model information.
       
    // Create the first message in the dialog
    format(szDialogMessage, sizeof(szDialogMessage), "Vehicles:\n");
   
    // Now begin formatting the information to show in the dialog, repeating the previous information for the final display in the dialog
    for(new i = 0; i < MAX_VEHICLE_MODELS; i++) {
        format(szDialogMessage, sizeof(szDialogMessage), "%s- %s (price: $%d)\n", szDialogMessage, VehicleInfo[i][v_szName], VehicleInfo[i][v_iPrice]);
    }
   
    // Whenever it loops through a vehicle model, it will add to the string at the end of it with the vehicle model information, helping us form the information all in to one string
    ShowPlayerDialog(playerid, DIALOG_VEHICLES, DIALOG_STYLE_MSGBOX, "Vehicles", szDialogMessage, "OK", "Cancel");
    return 1;
}
I have only been able to test that this code compiles, rather than test it in-game, but this should help you with your problem.

Comments provided to explain it.
Reply
#3

That would work, but list-dialogs only show up to 50 lines.

You can't fit all 212 vehicles in one single dialog, even if you use a size for "szDialogMessage" of 100.000 cells (like "new szDialogMessage[100000];").


As for msgbox dialogs, I don't think you can fit 212 lines on your screen as well.
Reply
#4

What about if i show 5 vehicles per line then i use \n and strcat?
Reply
#5

That would work. 212/5 is 43 lines.
Just be sure your variable "szDialogMessage" is large enough to hold all the data.
Reply
#6

But this probably will increase as fuck the .amx file...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)