17.07.2011, 03:54
Hey guys, this is my first tutorial and its going to be pretty simple. The main purpose of this is to get someone use to using dialogs and getting them use to checking if a player already has the amount of which there trying to add. So im going to be going off of one of the Food shacks On The Beach. Heres a picture of the Pizza shack were working on.

So lets get started.
Well first thing first we are going to want to get the coordinates of where you want the player to be standing to type /pizza and where the Red checkpoint is. So, get the cordinates and at the top were gonna add
This makes the CheckPoint usable in this case.
Next were going to create the legit checkpoint. So heres what my checkpoint looks like.
remember to have the checkpoint be named as the
What this does is:
It creates the checkpoint
Adds the coordinates = 379.6416,-1921.9618,7.8301
Creates the size of the checkpoint = 4.01
worldid = -1
interiorid = -1
playerid = -1
How close you have to be to see the checkpoint = 10.0
Next somewhere on your script add
And add
to the very top of the script. We will need this for our next script and i will tell you what it does.
Now, My command is going to be /Pizza. So under
We are going to add
Now, Remember when we added the Public PlayerToPoint, this is where it comes in. If we didnt have that, we would be able to use
So let me tell you what this code does.
Means, if we are in the range of the given cordinates, we will be able to use the command. If not, we wont be able to use the command.
Next, ShowPlayerDialog, is the menu for the pizza shack.
This is what a Dialog looks like.

For people who didnt know.
This will give the option of selecting a
Small Pizza
Medium Pizza
Large Pizza
And a Extra Large Pizza, With its given price.
This, you do not need, but what it does is when the dialog opens, it plays the sound id of 1057.
Now, we must go down to Dialog Response.
This is what our Dialog Response is going to look like. When Finished. Im going to just do 1 response, you should be able to do the rest on your own.
So, im going to break this all down to you again.
This allows us to use the %s feature. The %s feature shows the players name in the way we will be using it.
This,Gets the players health. But,
If you have less than 25, you will be given 25 health.
This checks if you have the money to buy this item. <4 ( if you have less than 4 dollars, you will get a message saying
This is an Addon To
[/CODE]
Remember, With the beginning part of the code i explained that you need those codings to have the %s. Now, we are using %s.
Will send a Message to all players saying "[player] has just bought a small pizza from Nandos Pizza Shack!"
This will take away 4 dollars, if you have that amount (add on from a code above)
Again this will play the noise 1054.
This, will send a message on the screen in big letters saying "NOM...NOM...NOM"
Now were still not done. Finishing up the Checkpoint, we will need to add this to the script.
What this will do is when we enter the checkpoint pizza, it will say
5000 is how long it will stay on the screen, and 5 is the style.
And that is pretty much the tutorial. If i forgot anything, i might of this took for ever to do. Please tell me below.
Thanks.

So lets get started.
Well first thing first we are going to want to get the coordinates of where you want the player to be standing to type /pizza and where the Red checkpoint is. So, get the cordinates and at the top were gonna add
Код:
new pizza;
Next were going to create the legit checkpoint. So heres what my checkpoint looks like.
Код:
pizza = CreateDynamicCP(379.6416,-1921.9618,7.8301,4.0,-1, -1, -1, 10.0);
Код:
new pizza;
It creates the checkpoint
Adds the coordinates = 379.6416,-1921.9618,7.8301
Creates the size of the checkpoint = 4.01
worldid = -1
interiorid = -1
playerid = -1
How close you have to be to see the checkpoint = 10.0
Next somewhere on your script add
Код:
public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z) { if(IsPlayerConnected(playerid)) { new Float:oldposx, Float:oldposy, Float:oldposz; new Float:tempposx, Float:tempposy, Float:tempposz; GetPlayerPos(playerid, oldposx, oldposy, oldposz); tempposx = (oldposx -x); tempposy = (oldposy -y); tempposz = (oldposz -z); if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) { return 1; } } return 0; }
Код:
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
Now, My command is going to be /Pizza. So under
Код:
public OnPlayerCommandText(playerid, cmdtext[])
Код:
if (strcmp("/pizza", cmdtext, true, 10) == 0) { if(PlayerToPoint(25, playerid, 379.6416, -1921.9618, 7.8301)) { ShowPlayerDialog(playerid,197,DIALOG_STYLE_LIST,"Nandos Pizza Shack","Small Pizza {$4.00)\nMedium Pizza ($8.00)\nLarge Pizza ($10.00)\nExtra Large Pizza ($14.99)\n","Buy!", "Exit"); new Float:pX, Float:pY, Float:pZ; PlayerPlaySound(playerid,1057,pX,pY,pZ); } return 1; }
Код:
if(PlayerToPoint(25, playerid, 379.6416, -1921.9618, 7.8301))
Код:
if(PlayerToPoint(25, playerid, 379.6416, -1921.9618, 7.8301))
Next, ShowPlayerDialog, is the menu for the pizza shack.
This is what a Dialog looks like.

For people who didnt know.
This will give the option of selecting a
Small Pizza
Medium Pizza
Large Pizza
And a Extra Large Pizza, With its given price.
Код:
new Float:pX, Float:pY, Float:pZ; PlayerPlaySound(playerid,1057,pX,pY,pZ);
Now, we must go down to Dialog Response.
This is what our Dialog Response is going to look like. When Finished. Im going to just do 1 response, you should be able to do the rest on your own.
Код:
if(dialogid == 197) { if(response) { if(listitem == 0) { new string[256]; new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); SetPlayerHealth(playerid,25); new Float:HP; GetPlayerHealth(playerid, HP); SetPlayerHealth(playerid, HP+25); if(GetPlayerMoney(playerid) < 4) return SendClientMessage(playerid,0x008000AA, "You don't have enough money! You Need $4.00!"); format(string, sizeof(string), "%s has just bought a small pizza from Nandos Pizza Shack!", pname); SendClientMessageToAll(0x008000AA, string); GivePlayerMoney(playerid,-4); new Float:pX, Float:pY, Float:pZ; PlayerPlaySound(playerid,1054,pX,pY,pZ); GameTextForPlayer(playerid, "NOM...NOM...NOM", 2000, 1); } if(listitem == 1) { new string[256]; new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); SetPlayerHealth(playerid,50); new Float:HP; GetPlayerHealth(playerid, HP); SetPlayerHealth(playerid, HP+50); if(GetPlayerMoney(playerid) < 8) return SendClientMessage(playerid,0x008000AA, "You don't have enough money! You Need $8.00!"); format(string, sizeof(string), "%s has just bought a medium pizza from Nandos Pizza Shack!", pname); SendClientMessageToAll(0x008000AA, string); GivePlayerMoney(playerid,-8); new Float:pX, Float:pY, Float:pZ; PlayerPlaySound(playerid,1054,pX,pY,pZ); GameTextForPlayer(playerid, "NOM...NOM...NOM", 2000, 1); } if(listitem == 2) { new string[256]; new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); SetPlayerHealth(playerid,75); new Float:HP; GetPlayerHealth(playerid, HP); SetPlayerHealth(playerid, HP+75); if(GetPlayerMoney(playerid) < 10) return SendClientMessage(playerid,0x008000AA, "You don't have enough money! You Need $10.00!"); format(string, sizeof(string), "%s has just bought a large pizza from Nandos Pizza Shack!", pname); SendClientMessageToAll(0x008000AA, string); GivePlayerMoney(playerid,-10); new Float:pX, Float:pY, Float:pZ; PlayerPlaySound(playerid,1054,pX,pY,pZ); GameTextForPlayer(playerid, "NOM...NOM...NOM", 2000, 1); } if(listitem == 3) { new string[256]; new pname[MAX_PLAYER_NAME]; SetPlayerHealth(playerid,100); GetPlayerName(playerid, pname, sizeof(pname)); if(GetPlayerMoney(playerid) < 15) return SendClientMessage(playerid,0x008000AA, "You don't have enough money!You Need $15.00!"); format(string, sizeof(string), "%s has just bought a extra large pizza from Nandos Pizza Shack!", pname); SendClientMessageToAll(0x008000AA, string); GivePlayerMoney(playerid,-15); new Float:pX, Float:pY, Float:pZ; PlayerPlaySound(playerid,1054,pX,pY,pZ); GameTextForPlayer(playerid, "NOM...NOM...NOM", 2000, 1); } } }
Код:
new string[256]; new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); SetPlayerHealth(playerid,25); new Float:HP; GetPlayerHealth(playerid, HP); SetPlayerHealth(playerid, HP+25); if(GetPlayerMoney(playerid) < 4) return SendClientMessage(playerid,0x008000AA, "You don't have enough money! You Need $4.00!"); format(string, sizeof(string), "%s has just bought a small pizza from Nandos Pizza Shack!", pname); SendClientMessageToAll(0x008000AA, string); GivePlayerMoney(playerid,-4); new Float:pX, Float:pY, Float:pZ; PlayerPlaySound(playerid,1054,pX,pY,pZ); GameTextForPlayer(playerid, "NOM...NOM...NOM", 2000, 1); }
Код:
new string[256]; new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname));
Код:
SetPlayerHealth(playerid,25); new Float:HP; GetPlayerHealth(playerid, HP); SetPlayerHealth(playerid, HP+25);
Код:
GetPlayerHealth(playerid, HP);
Код:
SetPlayerHealth(playerid, HP+25);
Код:
if(GetPlayerMoney(playerid) < 4) return SendClientMessage(playerid,0x008000AA, "You don't have enough money! You Need $4.00!");
Quote:
You don't have enough money! You Need $4.00! |
Код:
format(string, sizeof(string), "%s has just bought a small pizza from Nandos Pizza Shack!", pname); SendClientMessageToAll(0x008000AA, string);
Код:
new string[256]; new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname));
Remember, With the beginning part of the code i explained that you need those codings to have the %s. Now, we are using %s.
Код:
format(string, sizeof(string), "%s has just bought a small pizza from Nandos Pizza Shack!", pname); SendClientMessageToAll(0x008000AA, string);
Код:
GivePlayerMoney(playerid,-4);
Код:
new Float:pX, Float:pY, Float:pZ; PlayerPlaySound(playerid,1054,pX,pY,pZ);
Код:
GameTextForPlayer(playerid, "NOM...NOM...NOM", 2000, 1);
Now were still not done. Finishing up the Checkpoint, we will need to add this to the script.
Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid) { if(checkpointid == pizza)//----Nandos Pizza Shop { GameTextForPlayer(playerid, "Benvenuto! Welcome to the Pizza Shop! type /pizza to buy a pizza! Mamma Mia!", 5000, 5); } return 1; }
Quote:
Benvenuto! Welcome to the Pizza Shop! type /pizza to buy a pizza! Mamma Mia! |
And that is pretty much the tutorial. If i forgot anything, i might of this took for ever to do. Please tell me below.
Thanks.