this menu will show you how to add extra items easily instead of having to add them all in manually.
Include the modules you need.
Code: Select all
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>Code: Select all
Now we create the variables that will hold the shop and not enough moneyCode: Select all
new g_iBlinkAcct;for this example im using Grenade Names
Code: Select all
new g_szItems[][] =
{
"HE Grenade",
"Smoke Grenade",
"Flash Bang"
} Now we create the constant which holds the above items prices
Code: Select all
new g_iItemsPrices[] =
{
350, // price for HE nade
200, // price for SM nade
250, // price for FL nade
} to add extra items ex.
Code: Select all
new g_szItems[][] =
{
"HE Grenade",
"Smoke Grenade",
"Flash Bang",
"item 4",
"item 5",
"item 6" // make sure the last one does NOT have a comma
}
new g_iItemsPrices[] =
{
350, // price for HE nade
200, // price for SM nade
250, // price for FL nade
200, // price for item 4
300, // price for item 5
500, // price for item 6
} Code: Select all
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
g_iBlinkAcct = get_user_msgid("BlinkAcct")
// we register this variable to get the money blinking effect for insufficient funds
register_clcmd("say /shop", "cmdShop", 0);
// we only need to register a client command to call the shop menu
} Code: Select all
public cmdShop(id)
{
new Temp[101], money = cs_get_user_money(id);
// we create new variables to hold menu title and players current money
formatex(Temp,100, "\yShop Menu:^n^nYour Money:\r $%d", money);
new menu = menu_create(Temp, "handler_ShopMenu")
new szItemName[64]
for(new i; i<sizeof(g_szItems) && i<sizeof(g_iItemsPrices); i++)
{
if( money < g_iItemsPrices[i] ) // we check here if the player has enough money for the item
{
formatex(szItemName, charsmax(szItemName), "\d%s ($%d)", g_szItems[ i ], g_iItemsPrices[ i ])
// if the item cost more then players money we show the item as grey'd out color for disabled
}
else {
formatex(szItemName, charsmax(szItemName), "%s (\r$%d\w)", g_szItems[ i ], g_iItemsPrices[ i ])
// if the item cost less then players money we show the item as available
}
menu_additem(menu, szItemName)
// now we add the items into the menu auto adding all items from the above constants.
}
menu_setprop(menu, MPROP_NUMBER_COLOR, "\y")
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public handler_ShopMenu(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new money = cs_get_user_money(id);
new new_money = cs_get_user_money(id) - g_iItemsPrices[item];
// we create new variables to hold players current money
// and to set players new money after purchasing items
// g_iItemsPrices[item] gets the items price from which number you select from menu and checks that against
// the item number from the constant from above plugin_init
// now we check if players money is less then the item
// and if it is then we show a insuffisent message and make the players money hud flash
if( money < g_iItemsPrices[item] )
{
NotEnoughMoney( id );
menu_display(id, menu);
return PLUGIN_HANDLED;
}
switch(item)
{
case 0:
{
// if player already holds this item we show a cant carry anymore messge
if( user_has_weapon(id, CSW_HEGRENADE) )
{
Cannot_Carry_Anymore( id );
}
else {
// otherwise we give item to player
give_item(id, "weapon_hegrenade");
client_print(id, print_center, "You Bought (%s)", g_szItems[item]);
// and then reset players money to current money minus item price.
cs_set_user_money(id, new_money);
}
}
case 1:
{
// if player already holds this item we show a cant carry anymore messge
if( user_has_weapon(id, CSW_SMOKEGRENADE) )
{
Cannot_Carry_Anymore( id );
}
else {
// otherwise we give item to player
give_item(id, "weapon_smokegrenade");
client_print(id, print_center, "You Bought (%s)", g_szItems[item]);
// and then reset players money to current money minus item price.
cs_set_user_money(id, new_money);
}
}
case 2:
{
// if player already holds this item we show a cant carry anymore messge
if( user_has_weapon(id, CSW_FLASHBANG) )
{
Cannot_Carry_Anymore( id );
}
else {
// otherwise we give item to player
give_item(id, "weapon_flashbang");
client_print(id, print_center, "You Bought (%s)", g_szItems[item]);
// and then reset players money to current money minus item price.
cs_set_user_money(id, new_money);
}
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
} Code: Select all
NotEnoughMoney( id )
{
client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money");
// and if it is then we show a insuffisent message and make the players money hud flash
message_begin(MSG_ONE_UNRELIABLE, g_iBlinkAcct, .player=id);
{
write_byte(2);
}
message_end();
}
Cannot_Carry_Anymore( id )
{
client_print(id, print_center, "#Cstrike_TitlesTXT_Cannot_Carry_Anymore");
} i will show you the whole code without comments.
Code: Select all
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#define PLUGIN "Shop Tut For Newbies"
#define VERSION "1.0"
#define AUTHOR "Blizzard"
new g_iBlinkAcct;
// EDIT ITEMS BELOW
new g_szItems[][] =
{
"HE Grenade",
"Smoke Grenade",
"Flash Bang"
}
// END EDIT ITEMS
// EDIT ITEM PRICES BELOW
new g_iItemsPrices[] =
{
350, // Price Item 1
200, // Price Item 2
250, // Price Item 3
}
// END EDIT PRICES
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
g_iBlinkAcct = get_user_msgid("BlinkAcct")
register_clcmd("say /shop", "cmdShop", 0);
}
public cmdShop(id)
{
new Temp[101], money = cs_get_user_money(id);
formatex(Temp,100, "\yShop Menu:^n^nYour Money:\r $%d", money);
new menu = menu_create(Temp, "handler_ShopMenu")
new szItemName[64]
for(new i; i<sizeof(g_szItems) && i<sizeof(g_iItemsPrices); i++)
{
if( money < g_iItemsPrices[i] )
{
formatex(szItemName, charsmax(szItemName), "\d%s ($%d)", g_szItems[ i ], g_iItemsPrices[ i ])
}
else {
formatex(szItemName, charsmax(szItemName), "%s (\r$%d\w)", g_szItems[ i ], g_iItemsPrices[ i ])
}
menu_additem(menu, szItemName)
}
menu_setprop(menu, MPROP_NUMBER_COLOR, "\y")
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public handler_ShopMenu(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new money = cs_get_user_money(id);
new new_money = cs_get_user_money(id) - g_iItemsPrices[item];
if( money < g_iItemsPrices[item] )
{
NotEnoughMoney( id );
menu_display(id, menu);
return PLUGIN_HANDLED;
}
switch(item)
{
case 0:
{
if( user_has_weapon(id, CSW_HEGRENADE) )
{
Cannot_Carry_Anymore( id );
}
else {
give_item(id, "weapon_hegrenade");
client_print(id, print_center, "You Bought (%s)", g_szItems[item]);
cs_set_user_money(id, new_money);
}
}
case 1:
{
if( user_has_weapon(id, CSW_SMOKEGRENADE) )
{
Cannot_Carry_Anymore( id );
}
else {
give_item(id, "weapon_smokegrenade");
client_print(id, print_center, "You Bought (%s)", g_szItems[item]);
cs_set_user_money(id, new_money);
}
}
case 2:
{
if( user_has_weapon(id, CSW_FLASHBANG) )
{
Cannot_Carry_Anymore( id );
}
else {
give_item(id, "weapon_flashbang");
client_print(id, print_center, "You Bought (%s)", g_szItems[item]);
cs_set_user_money(id, new_money);
}
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
NotEnoughMoney( id )
{
client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money");
message_begin(MSG_ONE_UNRELIABLE, g_iBlinkAcct, .player=id);
{
write_byte(2);
}
message_end();
}
Cannot_Carry_Anymore( id )
{
client_print(id, print_center, "#Cstrike_TitlesTXT_Cannot_Carry_Anymore");
} 