SA-MP Forums Archive
Vehicle Components - 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: Vehicle Components (/showthread.php?tid=364599)



Vehicle Components - Luis- - 31.07.2012

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.


Re: Vehicle Components - KappaCro - 31.07.2012

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;
}
}



Re: Vehicle Components - Luis- - 31.07.2012

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


Re: Vehicle Components - Cjgogo - 31.07.2012

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)



Re: Vehicle Components - Luis- - 31.07.2012

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


Re: Vehicle Components - Luis- - 31.07.2012

Bump.


Re: Vehicle Components - [KHK]Khalid - 31.07.2012

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.


Re: Vehicle Components - Luis- - 31.07.2012

Thanks for that mate, it's working


Re: Vehicle Components - [KHK]Khalid - 31.07.2012

You're welcome. Glad it worked.