Vehicle Components
#1

Hello, i'm using the component include and I am having a problem with a command I am making,
pawn Код:
CMD:enter(playerid, params[]) {
    if(IsPlayerInRangeOfPoint(playerid, 1.5, 92.5586,-164.7990,2.3208)) {
        new component, count=1, String[1500];
        while(GetVehicleCompatibleUpgrades(GetVehicleModel(GetPlayerVehicleID(playerid)), count, component))
        {
            format(String, sizeof String, "%s%s [%d]\n", String, GetComponentName(component), component);
            ShowPlayerDialog(playerid, DIALOG_MODS, DIALOG_STYLE_LIST, "Car Mods", String, "Select", "Cancel");
            count++;
            ChosenComp[playerid] = component;
        }
    }
    return 1;
}
"ChosenComp[playerid]" always gets the last one in the dialog, I know why it's doing it but I don't know how to stop it. I want it to get whatever component I select and save it to "ChosenComp[playerid]" for use with another part of the command.

Thanks.
Reply
#2

pawn Код:
CMD:enter(playerid, params[]) {
    if(IsPlayerInRangeOfPoint(playerid, 1.5, 92.5586,-164.7990,2.3208)) {
        new component, count=1, String[1500];
        while(GetVehicleCompatibleUpgrades(GetVehicleModel(GetPlayerVehicleID(playerid)), count, component))
        {
            format(String, sizeof String, "%s%s [%d]\n", String, GetComponentName(component), component);
            ShowPlayerDialog(playerid, DIALOG_MODS, DIALOG_STYLE_LIST, "Car Mods", String, "Select", "Cancel");
            count++;
            ChosenComp[playerid] = component;
        }
    return 1;
}
}
Reply
#3

You haven't changed a thing. Come back when you learn not to copy my code and re-post it.
Reply
#4

pawn Код:
CMD:enter(playerid, params[]) {
    if(IsPlayerInRangeOfPoint(playerid, 1.5, 92.5586,-164.7990,2.3208)) {
        new component, count=1, String[1500];
        while(GetVehicleCompatibleUpgrades(GetVehicleModel(GetPlayerVehicleID(playerid)), count, component))
        {
            format(String, sizeof(String), "%s%s [%d]\n", String, GetComponentName(component), component);
            ShowPlayerDialog(playerid, DIALOG_MODS, DIALOG_STYLE_LIST, "Car Mods", String, "Select", "Cancel");
            count++;
            ChosenComp[playerid] = component;
        }
    }
    return 1;
I changed something in the format,not sure if
pawn Код:
sizeof String
works,never seen such a thing,only with brackets
pawn Код:
sizeof(String)
Reply
#5

It doesn't matter about that, they work either way.
Reply
#6

Bump.
Reply
#7

Try taking the ShowPlayerDialog call out of the while loop and put it below the while loop (After 'String' is totally formatted)

Ah and about ChosenComp I think you placed it in the wrong place. Shouldn't it be somewhere under OnDialogResponse and not inside the while loop?

Edit:

This works see the prints results:
pawn Код:
#define MAX_COMPS 194 // max components ids?
#define DIALOG_MODS 1 // you might change that

new c[MAX_PLAYERS]; // a variable to store the count of the components of a player's vehicle
new compID[MAX_PLAYERS][MAX_COMPS]; // a var to store a player's vehicle component id
new ChosenComp[MAX_PLAYERS];

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_MODS:
        {
            if(response)
            {
                new ct = c[playerid]; // is the count of playerid's vehicle's components (See the command /enter)
                for(new i = 0; i < ct; i ++) // looping through that count
                {
                    if(listitem == i) // if the selected item equals to the component count
                    {
                        // Here comes the use of compID. It will get the component id from the listitem/count
                        ChosenComp[playerid] = compID[playerid][i];
                        printf("listitem: %d", listitem); // some print to know which item playerid selected
                        printf("chosen comp id is: %d", ChosenComp[playerid]); // prints the component id of the selected item
                    }
                }
                return 1;
            }
            return 1;
        }
        default:
            return 1;
    }
    return 0;
}

CMD:enter(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 1.5, 92.5586,-164.7990,2.3208))
    {
        new component, count = 1, String[1500];
        c[playerid] = 0; // resetting it because a player can use this command multiple times
        while(GetVehicleCompatibleUpgrades(GetVehicleModel(GetPlayerVehicleID(playerid)), count, component))
        {
            format(String, sizeof String, "%s%s [%d]\n", String, GetComponentName(component), component);
            compID[playerid][c[playerid]] = component;
            c[playerid] ++;
            count ++;
        }
        ShowPlayerDialog(playerid, DIALOG_MODS, DIALOG_STYLE_LIST, "Car Mods", String, "Select", "Cancel");
    }
    return 1;
}
Not sure if this is the most efficient way of doing it, but it works anyway.
Reply
#8

Thanks for that mate, it's working
Reply
#9

You're welcome. Glad it worked.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)