[Tutorial] How to make a dealership!
#1

Hello guys, I decided to make this because I didn't find any good explanations for it, so I decided to make one myself!
Anyway, let's get started.
I will be making a luxurious dealership, now I will make a /buycar command to show a dialog, but you can make a pickup or check if he's in range of your dealership location, so edit it to suit you!

First, let's include ZCMD because we will make the command "/buycar" with ZCMD.
pawn Код:
#include <zcmd>
Alright, we're done with that.
Now let's make the command /buycar which will show the dialog that shows the available cars to buy.
I added some cars so you get a better explanation.
pawn Код:
CMD:buycar(playerid, params[])
{
    ShowPlayerDialog(playerid, 13, DIALOG_STYLE_LIST, "Luxurious Car Dealership", "Bullet\nInfernus\nHotring\nStretch\nSultan\nSuper GT", "Buy", "Close");
    return 1;
So I made a dialog to show to the player who did /buycar, and the dialog ID we got is 13(We are gonna use that later OnDialogResponse)
I added a Bullet, Infernus, Hotring, Stretch, Sultan and SuperGT.
Feel free to add more of course, I'm just giving an example now.
PS: This is a luxury dealership so you can put it at Grotti or something.

Ok, so.. Are we done? I guess not! We still have one thing to do!
The OnDialogResponse, of course!
Let's first start with checking the dialogid, which is in our case ID 13.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 13)
    {
        if(!response)
            return 1;
Now we checked if it's dialog ID 13, and we also checked that if they press the second button "Close", it does nothing(Which means it just closes it).
Now let's switch to see what they chose from the list.
We will do that with this:
pawn Код:
switch(listitem)
        {
Now as you can see, our first list item is Bullet, second is Infernus, third is Hotring, fourth is Stretch, fifth is Sultan and last of all is SuperGT.
First, we will check the first listitem(Which is case 0 == First list item).
I will give the whole code on this one, and then check everything in it.
pawn Код:
case 0: // list item Bullet
            {
                if(GetPlayerMoney(playerid) < 25000) // we are checking that if he has less than the car's price which is 25k, it will send him a message
                    return SendClientMessage(playerid, 0, "You don't have enough cash to buy this car!"); // message will tell him he doesnt have enough cash to buy it
                GivePlayerMoney(playerid, -25000); // if he has more than 25k, it will remove 25k and buy him the car
                new Float:p[4]; // this is for the position of the player.
                GetPlayerPos(playerid, p[0], p[1], p[2]); // we will get the player's position and spawn him the car at his location
                GetPlayerFacingAngle(playerid, p[3]); // we also checked what angle he is currently at.
                CreateVehicle(541, p[0], p[1], p[2], p[3]+90, -1, -1, 9999999);//created vehicle 541(Bullet) at his position and angle, and respawn time 9999999 so it doesnt respawn
            }
The same goes for the rest of the code, I will show one more:
pawn Код:
case 1: // list item Infernus
            {
                if(GetPlayerMoney(playerid) < 23000)// same again, checking his money and comparing it to the car's price
                    return SendClientMessage(playerid, 0, "You don't have enough cash to buy this car!"); // sending him a message that he cant buy it
                GivePlayerMoney(playerid, -23000);//if he has more than 23k, it will remove 23k and buy the car
                new Float:p[4];
                GetPlayerPos(playerid, p[0], p[1], p[2]); // again getting his position
                GetPlayerFacingAngle(playerid, p[3]);//and his angle
                CreateVehicle(411, p[0], p[1], p[2], p[3]+90, -1, -1, 9999999);// creating vehicle 411(Infernus) at his location and angle.
            }
Now let's put the whole code together and see what we got.
I will also put the remaining codes for the rest of the cars.
So we got this at the end:
pawn Код:
#include <zcmd>

CMD:buycar(playerid, params[])
{
    ShowPlayerDialog(playerid, 13, DIALOG_STYLE_LIST, "Luxurious Car Dealership", "Bullet\nInfernus\nHotring\nStretch\nSultan\nSuper GT", "Buy", "Close");
    return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 13)
    {
        if(!response)
            return 1;
        switch(listitem)
        {
            case 0:
            {
                if(GetPlayerMoney(playerid) < 25000)
                    return SendClientMessage(playerid, 0, "You don't have enough cash to buy this car!");
                GivePlayerMoney(playerid, -25000);
                new Float:p[4];
                GetPlayerPos(playerid, p[0], p[1], p[2]);
                GetPlayerFacingAngle(playerid, p[3]);
                CreateVehicle(541, p[0], p[1], p[2], p[3]+90, -1, -1, 9999999);
            }
            case 1:
            {
                if(GetPlayerMoney(playerid) < 23000)
                    return SendClientMessage(playerid, 0, "You don't have enough cash to buy this car!");
                GivePlayerMoney(playerid, -23000);
                new Float:p[4];
                GetPlayerPos(playerid, p[0], p[1], p[2]);
                GetPlayerFacingAngle(playerid, p[3]);
                CreateVehicle(411, p[0], p[1], p[2], p[3]+90, -1, -1, 9999999);
            }
            case 2:
            {
                if(GetPlayerMoney(playerid) < 20000)
                    return SendClientMessage(playerid, 0, "You don't have enough cash to buy this car!");
                GivePlayerMoney(playerid, -20000);
                new Float:p[4];
                GetPlayerPos(playerid, p[0], p[1], p[2]);
                GetPlayerFacingAngle(playerid, p[3]);
                CreateVehicle(494, p[0], p[1], p[2], p[3]+90, -1, -1, 9999999);
            }
            case 3:
            {
                if(GetPlayerMoney(playerid) < 22000)
                    return SendClientMessage(playerid, 0, "You don't have enough cash to buy this car!");
                GivePlayerMoney(playerid, -22000);
                new Float:p[4];
                GetPlayerPos(playerid, p[0], p[1], p[2]);
                GetPlayerFacingAngle(playerid, p[3]);
                CreateVehicle(409, p[0], p[1], p[2], p[3]+90, -1, -1, 9999999);
            }
            case 4:
            {
                if(GetPlayerMoney(playerid) < 17000)
                    return SendClientMessage(playerid, 0, "You don't have enough cash to buy this car!");
                GivePlayerMoney(playerid, -17000);
                new Float:p[4];
                GetPlayerPos(playerid, p[0], p[1], p[2]);
                GetPlayerFacingAngle(playerid, p[3]);
                CreateVehicle(560, p[0], p[1], p[2], p[3]+90, -1, -1, 9999999);
            }
            case 5:
            {
                if(GetPlayerMoney(playerid) < 20000)
                    return SendClientMessage(playerid, 0, "You don't have enough cash to buy this car!");
                GivePlayerMoney(playerid, -20000);
                new Float:p[4];
                GetPlayerPos(playerid, p[0], p[1], p[2]);
                GetPlayerFacingAngle(playerid, p[3]);
                CreateVehicle(506, p[0], p[1], p[2], p[3]+90, -1, -1, 9999999);
            }
        }
    }
    return 1;
}
Alright guys, end of the tutorial, I hope I helped you with this!
Cheers! Feel free to leave a comment or feedback!
Reply


Messages In This Thread
How to make a dealership! - by JimmyCh - 22.07.2013, 21:44
Re: How to make a dealership! - by Blademaster680 - 22.07.2013, 21:47
Re: How to make a dealership! - by JimmyCh - 22.07.2013, 21:48
Re: How to make a dealership! - by Mckarlis - 22.07.2013, 21:51
Re: How to make a dealership! - by JimmyCh - 22.07.2013, 21:55
Re: How to make a dealership! - by RALL0 - 22.07.2013, 22:13
Re: How to make a dealership! - by JimmyCh - 22.07.2013, 22:22
Re: How to make a dealership! - by RALL0 - 22.07.2013, 22:37
Re: How to make a dealership! - by JimmyCh - 22.07.2013, 22:44
Re: How to make a dealership! - by RALL0 - 22.07.2013, 22:47
Re: How to make a dealership! - by JimmyCh - 23.07.2013, 06:15
Re: How to make a dealership! - by RajatPawar - 23.07.2013, 06:23
Re: How to make a dealership! - by JimmyCh - 23.07.2013, 06:27
Re: How to make a dealership! - by kjek98 - 23.07.2013, 13:46
Re : How to make a dealership! - by Garwan50 - 23.07.2013, 19:10
Re: How to make a dealership! - by iAnonymous - 23.07.2013, 19:15
Re: How to make a dealership! - by JimmyCh - 23.07.2013, 19:16
Re : How to make a dealership! - by Garwan50 - 23.07.2013, 19:32
Re: How to make a dealership! - by DanishHaq - 26.07.2013, 10:10
Re: How to make a dealership! - by qazwsx - 23.08.2013, 09:48
Re: How to make a dealership! - by JimmyCh - 23.08.2013, 11:30
Re: How to make a dealership! - by Tuntun - 23.08.2013, 13:33
Re: How to make a dealership! - by JimmyCh - 23.08.2013, 14:10
Re: How to make a dealership! - by Tuntun - 23.08.2013, 14:28
Re: How to make a dealership! - by JimmyCh - 23.08.2013, 16:18
Re: How to make a dealership! - by Tuntun - 08.09.2013, 17:16
Re: How to make a dealership! - by JimmyCh - 08.09.2013, 18:04
Re: How to make a dealership! - by Tuntun - 08.09.2013, 18:14
Re: How to make a dealership! - by grizzley - 16.11.2013, 10:20
Re: How to make a dealership! - by TahaAsif12 - 16.11.2013, 15:01
Re: How to make a dealership! - by Nucky - 09.03.2014, 14:35
Re: How to make a dealership! - by iCurse - 03.06.2014, 03:25
Re: How to make a dealership! - by Sammi_Jackson - 24.07.2014, 22:27
Re: How to make a dealership! - by Sojo12 - 25.07.2014, 09:20
Re : How to make a dealership! - by Lexus95 - 25.07.2014, 10:37
Re: How to make a dealership! - by Sammi_Jackson - 27.07.2014, 20:53
Re: How to make a dealership! - by AndreiWow - 29.12.2016, 18:00
Re: How to make a dealership! - by Djean - 29.12.2016, 19:30
Re: How to make a dealership! - by JohnFlores - 24.07.2017, 14:34

Forum Jump:


Users browsing this thread: 4 Guest(s)