[Tutorial] How to make a food shack
#1

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

Код:
new pizza;
This makes the CheckPoint usable in this case.

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);
remember to have the checkpoint be named as the
Код:
new pizza;
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

Код:
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;
}
And add

Код:
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
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

Код:
public OnPlayerCommandText(playerid, cmdtext[])
We are going to add

Код:
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;
}
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
Код:
if(PlayerToPoint(25, playerid, 379.6416, -1921.9618, 7.8301))
So let me tell you what this code does.

Код:
if(PlayerToPoint(25, playerid, 379.6416, -1921.9618, 7.8301))
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.

Код:
   		new Float:pX, Float:pY, Float:pZ;
		PlayerPlaySound(playerid,1057,pX,pY,pZ);
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.

Код:
	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);
               	}
			}
		}
So, im going to break this all down to you again.

Код:
   			    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));
This allows us to use the %s feature. The %s feature shows the players name in the way we will be using it.

Код:
SetPlayerHealth(playerid,25);
					new Float:HP;
					GetPlayerHealth(playerid, HP);
					SetPlayerHealth(playerid, HP+25);
This,Gets the players health. But,
Код:
GetPlayerHealth(playerid, HP);
If you have less than 25, you will be given 25 health.

Код:
SetPlayerHealth(playerid, HP+25);
Код:
if(GetPlayerMoney(playerid) < 4) return SendClientMessage(playerid,0x008000AA, "You don't have enough money! You Need $4.00!");
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

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);
This is an Addon To
Код:
new string[256];
					new pname[MAX_PLAYER_NAME];
					GetPlayerName(playerid, pname, sizeof(pname));
[/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.

Код:
format(string, sizeof(string), "%s has just bought a small pizza from Nandos Pizza Shack!", pname);
					SendClientMessageToAll(0x008000AA, string);
Will send a Message to all players saying "[player] has just bought a small pizza from Nandos Pizza Shack!"

Код:
GivePlayerMoney(playerid,-4);
This will take away 4 dollars, if you have that amount (add on from a code above)

Код:
					new Float:pX, Float:pY, Float:pZ;
					PlayerPlaySound(playerid,1054,pX,pY,pZ);
Again this will play the noise 1054.

Код:
GameTextForPlayer(playerid, "NOM...NOM...NOM", 2000, 1);
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.

Код:
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;
}
What this will do is when we enter the checkpoint pizza, it will say
Quote:

Benvenuto! Welcome to the Pizza Shop! type /pizza to buy a pizza! Mamma Mia!

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.
Reply
#2

IsPlayerInRangeOfPoint is much faster and better than PlayerToPoint.
Reply
#3

^ what he says.

Anyway, nice tutorial! But you should use [pawn ] [/pawn ] instead of [code ] [/code ]
Reply
#4

Four big problems with this:
1: You assume that the user watching this tutorial is using Incognito's Streamer, which is certainly not always the case.
2: Throw your PlayerToPoint in the garbage and use IsPlayerInRangeOfPoint.
3: You actually don't even need that function or command, as you can just show that menu when the player enters the checkpoint.
4: Your string sizes are way too large. The maximum length for a client message is 128 and you won't be even reaching that length.
Reply
#5

Hi...I just want to say great work for this...but i have one problem when i end my script i conpile and there no any errors but this script doesnt work for me....it wont show chekcpoint...pls help me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)