23.07.2013, 15:48
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;
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");
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; }
Code:
if (strcmp("/shop", cmdtext, true, 10) == 0) { ShowMenuForPlayer(shop, playerid); }
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; }
Okay guys thats it, Wish it helped
And sorry for my bad english anyways :P