Show All Of MAX_VEHICLES in Dialog
#1

Ok so I have a CMD which is supposed to show a Dialog to the player with a list of occupied police vehicles and different stats of each car.

The only problem is that it doesn't display all of them in the Dialog, only the first police vehicle it finds. How can I make it list them all? What did I do wrong?

Here's the code:
pawn Код:
new string[800 char];
    new CurrentCars;
    CurrentCars = 0;
    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[800];
                        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 = "{76EE00}ON{FFFFFF}"; }
                        else if(gEngine[i] == 0) { atext = "{EE0000}OFF{FFFFFF}"; }
                        new kmh = GetPlayerSpeed(q, true);
                        format(player, sizeof(player), "{FFFFFF}Vehicle: %s (%d)  |  Gov ID: %d  |  Driver: %s (%d) \n", vehicle, GetVehicleModel(i), i, Nick(q), q);// Want to add more stuff here...
                        strcat(string, player)
                        format(player, sizeof(player), "  {FFFFFF}Engine Status: %s  |  Health: %.1f %%  |  Speed: %d |  Location: %s \n", atext, currenthealth, kmh, zone);// Want to add more stuff here...
                        strcat(string, player)
                        ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Dispatch Vehicles Display System (DVDS)", string, "Close", "");
                        strdel(string, 0, strlen(string));
                        CurrentCars = 1;
                        return 1;
                    }
                }
            }
        }
Thanks in advance guys!
Reply
#2

*Bump*

Anyone know how to display the list and not just the first one found?
Reply
#3

You have return 1; so function ends right there switch it to break; to continue MAX_VEHICLE loop iterations. Also you'll want to show the dialog after it's all done looping.
Reply
#4

Get rid of return 1; all together. Don't replace it with break, you will have the same problem. Also, move ShowPlayerDialog outside both loops.
Reply
#5

Quote:
Originally Posted by Chenko
Посмотреть сообщение
Get rid of return 1; all together. Don't replace it with break, you will have the same problem. Also, move ShowPlayerDialog outside both loops.
No he won't there is two loops here, once he finds the driver he can break out of that loop then continue checking the other cars if he doesn't then it's going to check the rest of players uselessly read the code.
Reply
#6

Ah right. My bad, do what he told you with break and move ShowPlayerDialog outside both loops. It should work fine then
Reply
#7

This seems too much of a struggle to achieve your goal. Why not just loop through players once and check if they're in a police vehicle?
Reply
#8

Ok, I now have this:
But it still doesn't show all the vehicles, only the first one... Anyone see what I'm still doing wrong?

pawn Код:
new string[800 char];
    new CurrentCars;
    CurrentCars = 0;
    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[800];
                        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 = "{76EE00}ON{FFFFFF}"; }
                        else if(gEngine[i] == 0) { atext = "{EE0000}OFF{FFFFFF}"; }
                        new kmh = GetPlayerSpeed(q, true);
                        format(player, sizeof(player), "{FFFFFF}Vehicle: %s (%d)  |  Gov ID: %d  |  Driver: %s (%d) \n", vehicle, GetVehicleModel(i), i, Nick(q), q);// Info Line #1
                        strcat(string, player)
                        format(player, sizeof(player), "  {FFFFFF}Engine Status: %s  |  Health: %.1f %%  |  Speed: %d |  Location: %s \n", atext, currenthealth, kmh, zone);// Info Line #2                                    
                        strcat(string, player)
                    }
                }
            }
        }
        ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Dispatch Vehicles Display System (DVDS)", string, "Close", "");
        strdel(string, 0, strlen(string));
        CurrentCars = 1;
Reply
#9

*Bump* Anyone know?
Reply
#10

I believe you are showing the dialog inside the vehicle loop when you should be showing the dialog outside that loop. Also, I'd take Vince's suggestion and simply loop through players and check if they are in the driver seat of a cop car instead of looping through vehicles and players.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)