22.07.2013, 21:44
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.
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.
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.
The same goes for the rest of the code, I will show one more:
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:
Alright guys, end of the tutorial, I hope I helped you with this!
Cheers! Feel free to leave a comment or feedback!
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>
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;
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 let's switch to see what they chose from the list.
We will do that with this:
pawn Код:
switch(listitem)
{
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
}
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.
}
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;
}
Cheers! Feel free to leave a comment or feedback!