SA-MP Forums Archive
Getting every vehicle price with a function or... - 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: Getting every vehicle price with a function or... (/showthread.php?tid=550761)



Getting every vehicle price with a function or... - Ox1gEN - 14.12.2014

So I bassicly have a dealership where I can buy vehicles from.
I already have each vehicle category sorted and the vehicles inside that category.

Now I have a question, I know I can bassicly do a dialog response for each vehicle to take the price but that'll just take too LONG and just flood the script itself, which would make it quite ugly.

I am wondering if it possible to create a function that'd do the work for me in acouple of lines instead of doing like at-least 200+ lines for everything with responses, defines, etc.


Re: Getting every vehicle price with a function or... - mirou123 - 14.12.2014

Make an array with prices saved in it. And to access the price you could do like VehPrice[listitem] or something similar.


Re: Getting every vehicle price with a function or... - Ox1gEN - 14.12.2014

Quote:
Originally Posted by mirou123
Посмотреть сообщение
Make an array with prices saved in it. And to access the price you could do like VehPrice[listitem] or something similar.
I think I understand what you mean, could you give me an example of how to create such array (I have never tried to do any of that stuff, therefore I am not experienced with it) with like one vehicle price inside, and maybe you could try to use it inside something? If you could just make something very simple so I would be able to understand it.
Thanks.


Re: Getting every vehicle price with a function or... - Mic_H - 14.12.2014

PHP код:
enum vDealerInfo
{
    
DVehName[25],
    
DVehPrice,
    
DVehModel
}

new 
VehDetails_Sports[xxx][vDealerInfo]=
{
//     Name     Price  ModelID
    
{"Infernus"100000,  411}, //0
    
.. // 1
    
..// 2
    
..// etc
    
};

new 
VehDetails_Bikes[xxx][vDealerInfo]=
{
//     Name     Price  ModelID
    
{"NRG-500",  50000,   511}, //0
    
.. //1
    
.. //2
    
..//etc
};


CMD:buy(playeridparams[])
{
    
//ifPlayerHasn'tReachedMax_OwnedVehicleLimit                        0      1     2....
    
ShowPlayerDialog(playerid0DIALOG_STYLE_LIST"Dealership!!""Sports\nBikes\netc""Select""");
    return 
1;
}


public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 0)
    {
        if(!
response// If they clicked 'Cancel' or pressed esc
        
{
            
SendClientMessage(playerid, -1"BitchPlease you too poor.");
        }
        else 
// Pressed ENTER
        
{
            switch(
listitem)
            {
                case 
0:
                {
                    for(new 
0i<sizeof(VehDeatails_Sports); i++)
                    {
                        
format(MSGsizeof(MSG), "%s%s - %i\n"MSG,VehDetails_Sports[i][VehName], VehDetails_Sports[i][VehPrice]);
                    }
                    
ShowPlayerDialog(playerid1DIALOG_STYLE_LIST"Sports"MSG);
                }
                case 
1:
                {
                    for(new 
0i<sizeof(VehDeatails_Bikes); i++)
                    {
                        
format(MSGsizeof(MSG), "%s%s - %i\n"MSG,VehDetails_Bikes[i][VehName], VehDetails_Bikes[i][VehPrice]);
                    }
                    
ShowPlayerDialog(playerid2DIALOG_STYLE_LIST"Bikes"MSG);
                }
            }
        }
        return 
1// We handled dialog, so return 1.
    
}
    else if(
dialogid == 1)//Sports
    
{
        if(!
response)
        {
            
SendClientMessage(playerid, -1"You aint even rich enough to read their names!");
        }
        else
        {
            
//Store the Values and Show him the rest of the infos.
            /*
                For Example:
                PlayerChosenVehicle[playerid]==VehDetails_Sports[listitem][DVehModel];
                ShowPlayerDialog(SeleteColorForVehicle);
                ...
            */
        
}
    }
    else if(
dialogid == 2)//Bikes
    
{
         if(!
response)
        {
            
SendClientMessage(playerid, -1"Can you even hold a stick bro?");
        }
        else
        {
            
//Store the Values and Show him the rest of the infos.
        
}
    }
    return 
0// You MUST return 0 here




Re: Getting every vehicle price with a function or... - Clad - 14.12.2014

Define the name/price or whatever you are using and put it in a dialog, It will not make you that much of lines.


Re: Getting every vehicle price with a function or... - Ox1gEN - 15.12.2014

Quote:
Originally Posted by Mic_H
Посмотреть сообщение
PHP код:
enum vDealerInfo
{
    
DVehName[25],
    
DVehPrice,
    
DVehModel
}
new 
VehDetails_Sports[xxx][vDealerInfo]=
{
//     Name     Price  ModelID
    
{"Infernus"100000,  411}, //0
    
.. // 1
    
..// 2
    
..// etc
    
};
new 
VehDetails_Bikes[xxx][vDealerInfo]=
{
//     Name     Price  ModelID
    
{"NRG-500",  50000,   511}, //0
    
.. //1
    
.. //2
    
..//etc
};
CMD:buy(playeridparams[])
{
    
//ifPlayerHasn'tReachedMax_OwnedVehicleLimit                        0      1     2....
    
ShowPlayerDialog(playerid0DIALOG_STYLE_LIST"Dealership!!""Sports\nBikes\netc""Select""");
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 0)
    {
        if(!
response// If they clicked 'Cancel' or pressed esc
        
{
            
SendClientMessage(playerid, -1"BitchPlease you too poor.");
        }
        else 
// Pressed ENTER
        
{
            switch(
listitem)
            {
                case 
0:
                {
                    for(new 
0i<sizeof(VehDeatails_Sports); i++)
                    {
                        
format(MSGsizeof(MSG), "%s%s - %i\n"MSG,VehDetails_Sports[i][VehName], VehDetails_Sports[i][VehPrice]);
                    }
                    
ShowPlayerDialog(playerid1DIALOG_STYLE_LIST"Sports"MSG);
                }
                case 
1:
                {
                    for(new 
0i<sizeof(VehDeatails_Bikes); i++)
                    {
                        
format(MSGsizeof(MSG), "%s%s - %i\n"MSG,VehDetails_Bikes[i][VehName], VehDetails_Bikes[i][VehPrice]);
                    }
                    
ShowPlayerDialog(playerid2DIALOG_STYLE_LIST"Bikes"MSG);
                }
            }
        }
        return 
1// We handled dialog, so return 1.
    
}
    else if(
dialogid == 1)//Sports
    
{
        if(!
response)
        {
            
SendClientMessage(playerid, -1"You aint even rich enough to read their names!");
        }
        else
        {
            
//Store the Values and Show him the rest of the infos.
            /*
                For Example:
                PlayerChosenVehicle[playerid]==VehDetails_Sports[listitem][DVehModel];
                ShowPlayerDialog(SeleteColorForVehicle);
                ...
            */
        
}
    }
    else if(
dialogid == 2)//Bikes
    
{
         if(!
response)
        {
            
SendClientMessage(playerid, -1"Can you even hold a stick bro?");
        }
        else
        {
            
//Store the Values and Show him the rest of the infos.
        
}
    }
    return 
0// You MUST return 0 here

Thank you so much.