How to make a dealership! -
JimmyCh - 22.07.2013
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.
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:
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!
Re: How to make a dealership! -
Blademaster680 - 22.07.2013
Welldone Jimmy!
Once again another amazing job
Re: How to make a dealership! -
JimmyCh - 22.07.2013
Thank you for your comment Blademaster680
If you guys need more tutorials, feel free to ask me!
Re: How to make a dealership! -
Mckarlis - 22.07.2013
Great tutorial again
+REP
Re: How to make a dealership! -
JimmyCh - 22.07.2013
Thank you!
Re: How to make a dealership! -
RALL0 - 22.07.2013
You only create the vehicle, why buy it if it's not going to be yours. I would expect that you would assign the vehicle to his owner or something..
Re: How to make a dealership! -
JimmyCh - 22.07.2013
You should do that yourself, I said I'm making a dealership not a whole vehicle ownership.
You should take this and add it to your script and make the player the owner of the vehicle, and the rest of the code.
Re: How to make a dealership! -
RALL0 - 22.07.2013
Well, I didn't mention using it, it's very easy. However you could make it advanced, there are probably tons of other dealership tutorials.
Re: How to make a dealership! -
JimmyCh - 22.07.2013
Feel free to exit this tutorial RALL0.
This tutorial is for people who wonder how to make dealerships.
Any questions?
Re: How to make a dealership! -
RALL0 - 22.07.2013
Quote:
Feel free to leave a comment or feedback!
|
Anything else?
Re: How to make a dealership! -
JimmyCh - 23.07.2013
No, thanks for rating my thread to 1, pfff..
Re: How to make a dealership! -
RajatPawar - 23.07.2013
A pretty good job. But, this is quite manual. I mean to say, to add a new car, you'd have to add a new case, edit the dialog, etc. It could be done using an array, couldn't it?
pawn Код:
new array[][][]=
{
411, "Infernus", 12500, // model, name, cost
522, "NRG", 50000
};
Then you could do this easily too! Just for loops and checking.
Re: How to make a dealership! -
JimmyCh - 23.07.2013
Well yea, that's another way to do it.
But adding a case isn't really hard.
Anyway, thanks for your comment
Re: How to make a dealership! -
kjek98 - 23.07.2013
Nice job i would give +REP i i could
Re : How to make a dealership! -
Garwan50 - 23.07.2013
There is just something i don't understand.
The program take the pos and the angle of the player, but why it add 90 to his angle ?
Sorry if i express badly
Re: How to make a dealership! -
iAnonymous - 23.07.2013
jimmy !!!
MAn , Your releases are helping me alot ! thanks alot for the help !
I HOPE TO SEE MORE RELEASES BY YOU !
+REP
Re: How to make a dealership! -
JimmyCh - 23.07.2013
The +90 is to get the car straight at the angle you're facing while you were on foot, before spawning the vehicle.
And thank you Anonymous!
Re : How to make a dealership! -
Garwan50 - 23.07.2013
Thanks for the answer, +REP
Re: How to make a dealership! -
DanishHaq - 26.07.2013
Thanks a lot Jimmy, I advanced mine so it sets the owner of the car too.. added park and all that. Well done.
Re: How to make a dealership! -
qazwsx - 23.08.2013
Nice one again!
Welldone Jim
I was just asking about this stuff too, and found it now :P