Help with complicated dialog
#1

Ok so I have a dialog that shows all vehicles that have a driver along with some stats on the cars. The problem I have is that I can't add anymore without the command not working (even when I do a \n).

Here is what works:
pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)  // MY WIP Police Vehicle Info system. Includes Health, driver, passengers, Location?, and Veh ID
            {
                if(IsACopCar(i))//All Cop Cars
                {
                    for(new q = 0; q < MAX_PLAYERS; q++)                    {
                        if(IsPlayerInVehicle(q, i))//All Cop Cars with People in the vehicle
                        {
                            if(GetPlayerVehicleSeat(q) == 0)//All cop cars with a driver
                            {
                                new vehicle[24];
                                new player[268];
                                new Float:engine;
                                GetVehicleHealth(i, engine);
                                new Float:currenthealth;
                                currenthealth = engine / 10;
                                GetVehicleName(i, vehicle, sizeof(vehicle));
                                new zone[MAX_ZONE_NAME];
                                GetVehicle2DZone(i, zone, MAX_ZONE_NAME);
                                //new atext[20];
                                //if(gEngine[i] == 1) { atext = "ON"; }
                                //else if(gEngine[i] == 0) { atext = "OFF"; }
                                format(player, sizeof(player), "Vehicle: %s (%d)  |  Gov ID: %d  |  Driver: %s (%d)  |  Health: %.1f %  |  Location: %s\n", vehicle, GetVehicleModel(i), i, Nick(q), q, currenthealth, zone);// Want to add more stuff here...
                                //format(player, sizeof(player), "Vehicle: %s (%d) | Gov ID: %s | Driver: %s (%d) | Health:  %d | Location: %s\n", vehicle, GetVehicleModel(i), i, Nick(q), q, currenthealth, zone);
                                strins(string, player, strlen(string), sizeof(string));
                            }
                        }
                    }
                }
            }
            ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Current Occupied Vehicles", string, "Close", "");
            strdel(string, 0, strlen(string));
        }
I want to add more info (such as Engine status) to the the line, but I can't without getting "Server: Unknown Command," my server's scripts stock error message.
Reply
#2

-bump-

Anyone know why it won't let me add more stuff?
Reply
#3

Use this: https://sampforum.blast.hk/showthread.php?tid=338873
Reply
#4

I don't realy understand that stuff well. Can I get an explanation please?
Reply
#5

Try to cut your dialog text into pieces and then format a single one. Otherwise the dialog crashes, as in your case. For example I have this command in my gm:
pawn Код:
if(strcmp(cmdtext, "/commands", true) == 0)
    {
        new dialog[1024];
     strcat(dialog,"{36CDFF}Admin:\n{FFFFFF}/Acommands, /Admins\n\n{36CDFF}Account: \n{FFFFFF}/Register [Password], /Login [Password], /stats -- or [ID]\n\n{36CDFF}Teleports:\n{FFFFFF}/Teleports(=menu), /StuntZones, /DMZones, /OtherZones, /ExitDM,\n/LosSantos, /SanFierro, /LasVenturas\n\n");
     strcat(dialog,"{36CDFF}Player:\n{FFFFFF}/goto [ID], /Afk, /Back, /Kill, /Suicide, /BuyHealth, /BuyArmour, /PM [ID] [Text], \n/Stoned, /Happy, /Angry, /Jetpack, /Weapons\n\n");
     strcat(dialog,"{36CDFF}Vehicle:\n{FFFFFF}/Detach, /Fix(=RepairVehicle), /Nitro, /Flip, /Lock, /Unlock, /Nrg, /infernus\n\n");
     strcat(dialog,"{36CDFF}Other:\n{FFFFFF}/InfoOff, /InfoOn, /Spec [ID], /Plant, /Parachute, /Flowers, /CountDown,\n/Animlist, SaveP (=SavePosition), /LoadP, /NametagsOn  /NametagsOff\n\n");
     strcat(dialog,"{36CDFF}Vehicle:\n{FFFFFF}/Detach, /Fix(=RepairVehicle), /Nitro, /Flip  /Lock, /Unlock, /Nrg, /infernus\n\n");
     strcat(dialog,"{00FF26}Press - 2 - for instant vehicle fix.");
     ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "{00FF26}Full List of Commands:", dialog, "OK", "");
        return 1;
    }
Apply the same in your dialog. In your case 2-3 strcat will do the job. But for each strcat you will need format(string.....) cause you want to apply not specific variables.
Reply
#6

I added this:
pawn Код:
if (strcmp("/sv", cmdtext, true, 10) == 0 || strcmp("/showvehicles", cmdtext, true, 10) == 0)
    {
        new string[512 char];
        for(new i = 0; i < MAX_VEHICLES; i++)  // MY WIP Police Vehicle Info system. Includes Health, driver, passengers, Location?, and Veh ID
        {
            if(IsACopCar(i))//All Cop Cars
            {
                for(new q = 0; q < MAX_PLAYERS; q++)
                {
                    if(IsPlayerInVehicle(q, i))//All Cop Cars with People in the vehicle
                    {
                        if(GetPlayerVehicleSeat(q) == 0)//All cop cars with a driver
                        {
                            new vehicle[24];
                            new player[268];
                            new Float:engine;
                            GetVehicleHealth(i, engine);
                            new Float:currenthealth;
                            currenthealth = engine / 10;
                            GetVehicleName(i, vehicle, sizeof(vehicle));
                            new zone[MAX_ZONE_NAME];
                            GetVehicle2DZone(i, zone, MAX_ZONE_NAME);
                            new atext[20];
                            if(gEngine[i] == 1) { atext = "ON"; }
                            else if(gEngine[i] == 0) { atext = "OFF"; }
                            new kmh = GetPlayerSpeed(q, true);
                            format(player, sizeof(player), "Vehicle: %s (%d)  |  Gov ID: %d  |  Driver: %s (%d) \n", vehicle, GetVehicleModel(i), i, Nick(q), q);// Want to add more stuff here...
                            format(player, sizeof(player), "Engine Status: %s  |  Health: %.1f %  |  Speed: %d |  Location: %s \n", atext, currenthealth, kmh, zone);// Want to add more stuff here...
                            //format(player, sizeof(player), "Vehicle: %s (%d)  |  Gov ID: %d  |  Driver: %s (%d)  |  Health: %.1f %  |  Location: %s \n", vehicle, GetVehicleModel(i), i, Nick(q), q, currenthealth, zone);// Want to add more stuff here...
                            strins(string, player, strlen(string), sizeof(string));
                            ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Current Occupied Vehicles", string, "Close", "");
                            strdel(string, 0, strlen(string));
                        }
                    }
                }
            }
        }
        return 1;
    }
But it doesn't show the first format line, only the second line.




-----------------------------------------------------------------------------------------------------------------


Also:

Since mine is using for(new i = 0; i < MAX_VEHICLES; i++) there will be multiple entries. Meaning if I did that it would do all cars info (line one of strcat) than the same cars (line two of strcat).

What I mean:

Код:
/showvehicles //I use command

Vehicle: LSPD Patrol Car (496)  |  Gov ID: 211 |  Driver: Jake (0)  |  Health: 100.0%  |  Location: Los Santos Airport //First vehicle Info
Vehicle: Unmarked Cruiser (499)  |  Gov ID: 216 |  Driver: John (1)  |  Health: 94.4%  |  Location: Market//Second vehicle Info
Vehicle: LSPD Patrol Car (497)  |  Gov ID: 207|  Driver: Billy (2)  |  Health: 88.2%  |  Location: Red County //Third vehicle Info
Speed: 15 KM/h //First vehicle Info
Speed: 55 KM/h //Second vehicle Info
Speed: 24 KM/h //Third vehicle Info
Reply
#7

You basically have to format a line and use strcat to add it to the main string. Then repeat the process as much as you need to. It works for me, so it should work for you, too!
Reply
#8

Yes, but I'm not sure exactly how to format it. I still don't understand this type of stuff very well (strings, strdel, strins, ect). Can you explain please?

pawn Код:
format(player, sizeof(player), "Vehicle: %s (%d)  |  Gov ID: %d  |  Driver: %s (%d) \n", vehicle, GetVehicleModel(i), i, Nick(q), q);// Format 1 stuff                      
format(player, sizeof(player), "Engine Status: %s  |  Health: %.1f %  |  Speed: %d |  Location: %s \n", atext, currenthealth, kmh, zone);//Format 2 stuff                        
strins(string, player, strlen(string), sizeof(string));                            
ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Current Occupied Vehicles", string, "Close", "");                            
strdel(string, 0, strlen(string));
The two formats I need are there, I don't know how to format it so it works...
Reply
#9

Okay, basically you're doing it correctly. However, you have to be careful because format basically overwrites whatever is in a string with what you (hence) format it with.

Therefore, you would have to do something like this:

pawn Код:
format(szString, sizeof(szString), "...", ...) // your first set of information
strcat(szMainString, szString); // add the formatted information to "szMainString" which is your MAIN string, the one you'll show with the dialog

format(szString, sizeof(szString), "...", ...) // your second set of information
strcat(szMainString, szString); // adding your second set of information to the string

format(szString, sizeof(szString), "...", ...) // your third set of information
strcat(...); // adding your third set

...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)