[Tutorial] How to Make Shop menu
#1

Tutorial How to make Shop Menu


Hi guys, in this tutorial, im going to show you how to make shop menu to buy weapons, ammo, etc.
Lets getting started

First of all, we need define the variable to assign the menu shop
Write this
Code:
new Menu:shop;
We need this variable because this will assign the menu shop. Write the code under #include <a_samp>. If you write the code not in good location, that will make error message when you compile it. Like Unidefined symbol.

Ok, the next step write this code in OnGameModeInit
Code:
shop = CreateMenu("COD MW3 SHOP", 2, 200.0, 100.0, 150.0, 150.0);
AddMenuItem(shop, 0, "Combat Shotgun");
AddMenuItem(shop, 0, "M4");
Okay, let me give you a lil bit explanation here.

CreateMenu is the command to make menu.
COD MW3 SHOP (I like that game :P ) : Is the Menu name, that will be place on top of your menu. Youre free to change it to what name you wished.

2 is the number how much columns are used
200 is Float x
100 is Float Y
150 the width of 1st column
and the another 150 is the width of 2nd column



Add this code to OnPlayerSelectedMenu
Code:
public OnPlayerSelectedMenuRow(playerid, row)
{
	new Menu:currentmenu = GetPlayerMenu(playerid);
	if(currentmenu == shop)
	{
	    switch(row)
	    {
	        case 0:
	        {
	        GivePlayerWeapon(playerid, 27, 393);
	        }
	        
			case 1:
			{
			    GivePlayerWeapon(playerid, 31, 393);
			}
	    }
	}
	return 1;
}
Okay, the last step to do is add this code in OnPlayerCommandText

Code:
if (strcmp("/shop", cmdtext, true, 10) == 0)
	{

		ShowMenuForPlayer(shop, playerid);
    }
it means that when we type /shop, the menu will be shown to player

And, in the end, your script should be looks like this
Code:
new Menu:shop;


public OnGameModeInit()
{
shop = CreateMenu("COD MW3 SHOP", 2, 200.0, 100.0, 150.0, 150.0);
AddMenuItem(shop, 0, "Combat Shotgun");
AddMenuItem(shop, 0, "M4");
AddMenuItem(shop, 0, "Shotgun");
}

public OnPlayerSelectedMenuRow(playerid, row)
{
	new Menu:currentmenu = GetPlayerMenu(playerid);
	if(currentmenu == shop)
	{
	    switch(row)
	    {
	        case 0:
	        {
	        GivePlayerWeapon(playerid, 27, 393);
	        SendClientMessage(playerid, COLOR_ORANGE, "You Have Bought Combat Shotgun for 1500$"); //replace COLOR_ORANGE with color that have you defined by yourself
	        GivePlayerMoney(playerid, -1500);
	        }
	        
			case 1:
			{
			    GivePlayerWeapon(playerid, 31, 393);
			    SendClientMessage(playerid, COLOR_ORANGE, "You have bought M4 for 3500$");replace COLOR_ORANGE with color that have you defined by yourself
			    GivePlayerMoney(playerid, -3500);
			}
	    }
	}
	return 1;
}
You can check all ids weapon, here


Okay guys thats it, Wish it helped
And sorry for my bad english anyways :P
Reply
#2

Screenshots?
Reply
#3

Very stupid tutorial....I didnt understant.Say where is OnPlayerSelectedMenu.....
Reply
#4

good job thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)