Помогите подправить баг с бесконечными патронами. В интернете где-то есть данный плагин с исправлением данного бага, но я так и не смог его найти...
/*
Realution created | Original code: iNeedHelp
CS Shop - магазинчик =)
Credits:
* neygomon. За стоки и прочие позаимствованные участки кода
Единственный офф.топик по плагину: https://www.neugomon.ru/threads/245/
*/
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define MENU_PREFIX "Магазин" // Префикс названия меню
#define CHAT_PREFIX "^3[^4Информация^3]^1" // Префикс чат сообщений
#define ADMIN_ACCESS ADMIN_BAN // Флаг доступа для скидки админу
#define VIP_ACCESS ADMIN_LEVEL_H // Флаг доступа для скидки випу
#define BUYHP_MAX 900 // Максимальное кол-во здоровья которое можно купить (по-умолчанию: 255)
#define BUYAP_MAX 900 // Максимальное кол-во брони которое можно купить (по-умолчанию: 255)
#if cellbits == 32
#define OFFSET_CSMONEY 115
#else
#define OFFSET_CSMONEY 140
#endif
new Float:g_lvlSpeed[33], bool:g_SpeedUse[33];
new g_Discount[33], g_DiscountAdmin, g_DiscountVIP, g_DiscountSteam;
new g_pMenuEnableCvars[6], g_pInvisibilityMenuCvars[3], g_pGravityMenuCvars[4], g_pHealthMenuCvars[6], g_pArmorMenuCvars[6], g_pSpeedMenuCvars[5];
new g_szMainShopMenu[][] = { "Меню оружия", "Меню невидимости", "Меню гравитации", "Меню здоровья", "Меню брони", "Меню скорости" };
new g_szInvisibilityMenu[][] = { "Слабая", "Средняя", "Высокая" };
new g_szGravityMenu[][] = { "Гравитация 700", "Гравитация 600", "Гравитация 500", "Гравитация 400" };
new g_szHealthMenu[][] = { "Здоровье +15", "Здоровье +35", "Здоровье +65", "Здоровье +95", "Здоровье +200" };
new g_szArmorMenu[][] = { "Броня +15", "Броня +35", "Броня +65", "Броня +95", "Броня +200" };
new g_szSpeedMenu[][] = { "Скорость 260", "Скорость 300", "Скорость 340", "Скорость 380", "Скорость 420" };
new g_iInvisibilityLevel[] = { 60, 40, 10 };
new g_iHealthLevel[] = { 15, 35, 65, 95, 200 };
new g_iArmorLevel[] = { 15, 35, 65, 95, 200 };
new Float:g_iGravityLevel[] = { 0.7, 0.6, 0.5, 0.4 };
new Float:g_iSpeedLevel[] = { 260.0, 300.0, 340.0, 380.0, 420.0 };
new g_Selected_Fwd, Item_Counter;
new Array:Item_Name, Array:Item_Cost;
public plugin_init()
{
#define PLUGIN "Shop Menu"
#define VERSION "1.1"
register_plugin(PLUGIN, VERSION, "Realution");
register_cvar("rl_shop", VERSION, FCVAR_SERVER | FCVAR_SPONLY);
// Commands
register_clcmd("shopmenu", "OpenShopMenu");
register_clcmd("say /shop", "OpenShopMenu");
register_clcmd("say_team /shop", "OpenShopMenu");
g_DiscountAdmin = register_cvar("amx_discount_admin", "30");
g_DiscountVIP = register_cvar("amx_discount_vip", "20");
g_DiscountSteam = register_cvar("amx_discount_steam", "5");
g_pMenuEnableCvars[0] = register_cvar("amx_shop_weapon", "1");
g_pMenuEnableCvars[1] = register_cvar("amx_shop_invis", "1");
g_pInvisibilityMenuCvars[0] = register_cvar("amx_shop_low", "6000");
g_pInvisibilityMenuCvars[1] = register_cvar("amx_shop_medium", "10000");
g_pInvisibilityMenuCvars[2] = register_cvar("amx_shop_high", "13000");
g_pMenuEnableCvars[2] = register_cvar("amx_shop_grav", "1");
g_pGravityMenuCvars[0] = register_cvar("amx_shop_g700", "1500");
g_pGravityMenuCvars[1] = register_cvar("amx_shop_g600", "2500");
g_pGravityMenuCvars[2] = register_cvar("amx_shop_g500", "3500");
g_pGravityMenuCvars[3] = register_cvar("amx_shop_g400", "4500");
g_pMenuEnableCvars[3] = register_cvar("amx_shop_hp", "1");
g_pHealthMenuCvars[0] = register_cvar("amx_shop_15hp", "400");
g_pHealthMenuCvars[1] = register_cvar("amx_shop_35hp", "700");
g_pHealthMenuCvars[2] = register_cvar("amx_shop_65hp", "1000");
g_pHealthMenuCvars[3] = register_cvar("amx_shop_95hp", "1500");
g_pHealthMenuCvars[4] = register_cvar("amx_shop_200hp", "2800");
g_pMenuEnableCvars[4] = register_cvar("amx_shop_ap", "1");
g_pArmorMenuCvars[0] = register_cvar("amx_shop_15ap", "400");
g_pArmorMenuCvars[1] = register_cvar("amx_shop_35ap", "700");
g_pArmorMenuCvars[2] = register_cvar("amx_shop_65ap", "1000");
g_pArmorMenuCvars[3] = register_cvar("amx_shop_95ap", "1500");
g_pArmorMenuCvars[4] = register_cvar("amx_shop_200ap", "2800");
g_pMenuEnableCvars[5] = register_cvar("amx_shop_speed", "1");
g_pSpeedMenuCvars[0] = register_cvar("amx_shop_260speed", "4000");
g_pSpeedMenuCvars[1] = register_cvar("amx_shop_300speed", "6000");
g_pSpeedMenuCvars[2] = register_cvar("amx_shop_340speed", "8000");
g_pSpeedMenuCvars[3] = register_cvar("amx_shop_380speed", "10000");
g_pSpeedMenuCvars[4] = register_cvar("amx_shop_420speed", "12000");
// RegisterFunc
RegisterHam(Ham_Spawn, "player", "fwdHamPlayerSpawn", true);
RegisterHam(Ham_Item_PreFrame, "player", "fwdHamPreFrame", true);
g_Selected_Fwd = CreateMultiForward("shop_item_selected", ET_IGNORE, FP_CELL, FP_CELL);
}
public plugin_cfg()
{
new const FOLDER[] = "addons/amxmodx/configs";
new FileMain[128]; format(FileMain, charsmax(FileMain), "%s/ShopMenu.cfg", FOLDER);
if(file_exists(FileMain)) server_cmd("exec %s", FileMain);
new iMap[33]; get_mapname(iMap, 33);
new FileMap[128]; format(FileMap, charsmax(FileMap), "%s/ShopMenu/%s.cfg", FOLDER, iMap);
if(file_exists(FileMap)) server_cmd("exec %s", FileMap);
}
public plugin_natives()
{
register_native("shop_register_item", "native_register_item", 1);
register_native("shop_buy_item", "native_buy_item", 1);
}
public plugin_precache()
{
Item_Name = ArrayCreate(64, 1);
Item_Cost = ArrayCreate(1, 1);
}
public native_register_item(const Name[], const Cost)
{
param_convert(1);
param_convert(3);
ArrayPushString(Item_Name, Name);
ArrayPushCell(Item_Cost, Cost);
Item_Counter++;
return Item_Counter-1;
}
public fwdHamPlayerSpawn(id) g_SpeedUse[id] = false;
public fwdHamPreFrame(id) if(g_SpeedUse[id]) fm_set_user_maxspeed(id, g_lvlSpeed[id]);
public client_putinserver(id)
{
if(get_user_flags(id) & ADMIN_ACCESS) g_Discount[id] = get_pcvar_num(g_DiscountAdmin);
else if(get_user_flags(id) & VIP_ACCESS) g_Discount[id] = get_pcvar_num(g_DiscountVIP);
else if(is_user_steam(id)) g_Discount[id] = get_pcvar_num(g_DiscountSteam);
else g_Discount[id] = 0;
}
public OpenShopMenu(id)
{
if(!is_user_alive(id)) return ChatColor(id, "%s Вы должны быть живы, чтобы использовать меню!", CHAT_PREFIX);
new szData[256], Items[64], Position[3];
if(g_Discount[id] > 0) formatex(szData, charsmax(szData), "\r%s^n\dНаличные: \r%d$ \w| \dСкидка: \r%d%%\R", MENU_PREFIX, fm_get_user_money(id), g_Discount[id]);
else formatex(szData, charsmax(szData), "\r%s^n\dНаличные: \r%d$ \w| \dСкидка: \rОтсутствует\R", MENU_PREFIX, fm_get_user_money(id));
new Menu = menu_create(szData, "MainMenu_Handler");
for(new i = 0; i < sizeof(g_szMainShopMenu); i++)
{
formatex(Items, charsmax(Items), "%s%s", get_pcvar_num(g_pMenuEnableCvars) ? "\w" : "\d", g_szMainShopMenu);
num_to_str(i, Position, charsmax(Position));
menu_additem(Menu, Items, Position);
}
menu_setprop(Menu, MPROP_EXITNAME, "Выход");
return menu_display(id, Menu);
}
public MainMenu_Handler(id, Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Menu);
switch(item)
{
case 0:
{
new Wpn_Menu = menu_create("\rМеню оружия\R", "GunsMenu_Handler");
static Items[64], Position[3], Buffer[192];
for(new i = 0; i < Item_Counter; i++)
{
ArrayGetString(Item_Name, i, Items, charsmax(Items));
formatex(Buffer, charsmax(Buffer), "%s \d- \y%i$", Items, GetItemCost(id, ArrayGetCell(Item_Cost, i)));
num_to_str(i, Position, charsmax(Position));
menu_additem(Wpn_Menu, Buffer, Position);
}
menu_setprop(Wpn_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Wpn_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Wpn_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[0])) menu_display(id, Wpn_Menu);
else ChatColor(id, "%s Меню оружия выключено.", CHAT_PREFIX);
}
case 1:
{
new Inv_Menu = menu_create("\rМеню невидимости\R", "InvisibilityMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szInvisibilityMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pInvisibilityMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szInvisibilityMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Inv_Menu, Items, Position);
}
menu_setprop(Inv_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Inv_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Inv_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[1])) menu_display(id, Inv_Menu);
else ChatColor(id, "%s Меню невидимости выключено.", CHAT_PREFIX);
}
case 2:
{
new Grav_Menu = menu_create("\rМеню гравитации\R", "GravityMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szGravityMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pGravityMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szGravityMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Grav_Menu, Items, Position);
}
menu_setprop(Grav_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Grav_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Grav_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[2])) menu_display(id, Grav_Menu);
else ChatColor(id, "%s Меню гравитации выключено.", CHAT_PREFIX);
}
case 3:
{
new Hp_Menu = menu_create("\rМеню здоровья\R", "HealthMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szHealthMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pHealthMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szHealthMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Hp_Menu, Items, Position);
}
menu_setprop(Hp_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Hp_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Hp_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[3])) menu_display(id, Hp_Menu);
else ChatColor(id, "%s Меню здоровья выключено.", CHAT_PREFIX);
}
case 4:
{
new Ap_Menu = menu_create("\rМеню брони\R", "ArmorMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szArmorMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pArmorMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szArmorMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Ap_Menu, Items, Position);
}
menu_setprop(Ap_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Ap_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Ap_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[4])) menu_display(id, Ap_Menu);
else ChatColor(id, "%s Меню брони выключено.", CHAT_PREFIX);
}
case 5:
{
new Speed_Menu = menu_create("\rМеню скорости\R", "SpeedMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szSpeedMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pSpeedMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szSpeedMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Speed_Menu, Items, Position);
}
menu_setprop(Speed_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Speed_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Speed_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[5])) menu_display(id, Speed_Menu);
else ChatColor(id, "%s Меню скорости выключено.", CHAT_PREFIX);
}
}
return menu_destroy(Menu);
}
public GunsMenu_Handler(id, Guns_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Guns_Menu);
native_buy_item(id, item);
return menu_destroy(Guns_Menu);
}
public native_buy_item(id, item)
{
new Money = fm_get_user_money(id);
static Discount, DummyItem, NameItem[64];
Discount = GetItemCost(id, ArrayGetCell(Item_Cost, item));
ArrayGetString(Item_Name, item, NameItem, sizeof(NameItem));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %i$^1)", CHAT_PREFIX, Discount);
ExecuteForward(g_Selected_Fwd, DummyItem, id, item);
fm_set_user_money(id, Money-Discount);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%i$", CHAT_PREFIX, NameItem, Discount);
return PLUGIN_HANDLED;
}
public InvisibilityMenu_Handler(id, Inv_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Inv_Menu);
new Money = fm_get_user_money(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pInvisibilityMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
fm_set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, g_iInvisibilityLevel[item]);
ChatColor(id, "%s Вы приобрели '^3Невидимость: %s^1' за ^4%d$", CHAT_PREFIX, g_szInvisibilityMenu[item], Discount);
return menu_destroy(Inv_Menu);
}
public GravityMenu_Handler(id, Grav_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Grav_Menu);
new Money = fm_get_user_money(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pGravityMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
fm_set_user_gravity(id, g_iGravityLevel[item]);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%d$", CHAT_PREFIX, g_szGravityMenu[item], Discount);
return menu_destroy(Grav_Menu);
}
public HealthMenu_Handler(id, Hp_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Hp_Menu);
new Money = fm_get_user_money(id);
new Health = get_user_health(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pHealthMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
if(Health + g_iHealthLevel[item] > BUYHP_MAX) fm_set_user_health(id, BUYHP_MAX);
else fm_set_user_health(id, Health + g_iHealthLevel[item]);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%d$", CHAT_PREFIX, g_szHealthMenu[item], Discount);
return menu_destroy(Hp_Menu);
}
public ArmorMenu_Handler(id, Ap_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Ap_Menu);
new Money = fm_get_user_money(id);
new Armor = get_user_armor(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pArmorMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
if(Armor + g_iArmorLevel[item] > BUYAP_MAX) fm_set_user_armor(id, BUYAP_MAX);
else fm_set_user_armor(id, Armor + g_iArmorLevel[item]);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%d$", CHAT_PREFIX, g_szArmorMenu[item], Discount);
return menu_destroy(Ap_Menu);
}
public SpeedMenu_Handler(id, Speed_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Speed_Menu);
new Money = fm_get_user_money(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pSpeedMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
g_lvlSpeed[id] = g_iSpeedLevel[item];
g_SpeedUse[id] = true; fwdHamPreFrame(id);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%d$", CHAT_PREFIX, g_szSpeedMenu[item], Discount);
return menu_destroy(Speed_Menu);
}
stock bool:is_user_steam(id)
{
static dp_pointer;
if(dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
{
server_cmd("dp_clientinfo %d", id);
server_exec();
return (get_pcvar_num(dp_pointer) == 2) ? true : false;
}
return false;
}
stock GetItemCost(id, iCost)
{
iCost -= floatround(iCost / 100.0 * g_Discount[id]);
return iCost;
}
stock fm_set_user_maxspeed(id, Float:speed = -1.0)
{
engfunc(EngFunc_SetClientMaxspeed, id, speed);
set_pev(id, pev_maxspeed, speed);
return 1;
}
stock fm_set_user_gravity(id, Float:gravity = 1.0)
{
set_pev(id, pev_gravity, gravity);
return 1;
}
stock fm_set_user_rendering(id, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
{
new CountAmount = amount * 255 / 100;
new Float:RenderColor[3];
RenderColor[0] = float®;
RenderColor[1] = float(g);
RenderColor[2] = float(b);
set_pev(id, pev_renderfx, fx);
set_pev(id, pev_rendercolor, RenderColor);
set_pev(id, pev_rendermode, render);
set_pev(id, pev_renderamt, float(CountAmount));
return 1;
}
stock fm_set_user_armor(id, armor)
{
set_pev(id, pev_armorvalue, float(armor));
return 1;
}
stock fm_set_user_health(id, health)
{
health > 0 ? set_pev(id, pev_health, float(health)) : dllfunc(DLLFunc_ClientKill, id);
return 1;
}
stock fm_set_user_money(id, money, flash = 0)
{
set_pdata_int(id, OFFSET_CSMONEY, money, 5);
message_begin(MSG_ONE, get_user_msgid("Money"), {0,0,0}, id);
write_long(money);
write_byte(flash);
message_end();
}
stock fm_get_user_money(id)
return get_pdata_int(id, OFFSET_CSMONEY, 5);
stock ChatColor(const id, const szMessage[], any:...)
{
static pnum, players[32], szMsg[190], IdMsg;
vformat(szMsg, charsmax(szMsg), szMessage, 3);
if(!IdMsg) IdMsg = get_user_msgid("SayText");
if(id)
{
players[0] = id;
pnum = 1;
}
else get_players(players, pnum, "ch");
for(new i; i < pnum; i++)
{
message_begin(MSG_ONE, IdMsg, .player = players);
write_byte(players);
write_string(szMsg);
message_end();
}
return 1;
}
Realution created | Original code: iNeedHelp
CS Shop - магазинчик =)
Credits:
* neygomon. За стоки и прочие позаимствованные участки кода
Единственный офф.топик по плагину: https://www.neugomon.ru/threads/245/
*/
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define MENU_PREFIX "Магазин" // Префикс названия меню
#define CHAT_PREFIX "^3[^4Информация^3]^1" // Префикс чат сообщений
#define ADMIN_ACCESS ADMIN_BAN // Флаг доступа для скидки админу
#define VIP_ACCESS ADMIN_LEVEL_H // Флаг доступа для скидки випу
#define BUYHP_MAX 900 // Максимальное кол-во здоровья которое можно купить (по-умолчанию: 255)
#define BUYAP_MAX 900 // Максимальное кол-во брони которое можно купить (по-умолчанию: 255)
#if cellbits == 32
#define OFFSET_CSMONEY 115
#else
#define OFFSET_CSMONEY 140
#endif
new Float:g_lvlSpeed[33], bool:g_SpeedUse[33];
new g_Discount[33], g_DiscountAdmin, g_DiscountVIP, g_DiscountSteam;
new g_pMenuEnableCvars[6], g_pInvisibilityMenuCvars[3], g_pGravityMenuCvars[4], g_pHealthMenuCvars[6], g_pArmorMenuCvars[6], g_pSpeedMenuCvars[5];
new g_szMainShopMenu[][] = { "Меню оружия", "Меню невидимости", "Меню гравитации", "Меню здоровья", "Меню брони", "Меню скорости" };
new g_szInvisibilityMenu[][] = { "Слабая", "Средняя", "Высокая" };
new g_szGravityMenu[][] = { "Гравитация 700", "Гравитация 600", "Гравитация 500", "Гравитация 400" };
new g_szHealthMenu[][] = { "Здоровье +15", "Здоровье +35", "Здоровье +65", "Здоровье +95", "Здоровье +200" };
new g_szArmorMenu[][] = { "Броня +15", "Броня +35", "Броня +65", "Броня +95", "Броня +200" };
new g_szSpeedMenu[][] = { "Скорость 260", "Скорость 300", "Скорость 340", "Скорость 380", "Скорость 420" };
new g_iInvisibilityLevel[] = { 60, 40, 10 };
new g_iHealthLevel[] = { 15, 35, 65, 95, 200 };
new g_iArmorLevel[] = { 15, 35, 65, 95, 200 };
new Float:g_iGravityLevel[] = { 0.7, 0.6, 0.5, 0.4 };
new Float:g_iSpeedLevel[] = { 260.0, 300.0, 340.0, 380.0, 420.0 };
new g_Selected_Fwd, Item_Counter;
new Array:Item_Name, Array:Item_Cost;
public plugin_init()
{
#define PLUGIN "Shop Menu"
#define VERSION "1.1"
register_plugin(PLUGIN, VERSION, "Realution");
register_cvar("rl_shop", VERSION, FCVAR_SERVER | FCVAR_SPONLY);
// Commands
register_clcmd("shopmenu", "OpenShopMenu");
register_clcmd("say /shop", "OpenShopMenu");
register_clcmd("say_team /shop", "OpenShopMenu");
g_DiscountAdmin = register_cvar("amx_discount_admin", "30");
g_DiscountVIP = register_cvar("amx_discount_vip", "20");
g_DiscountSteam = register_cvar("amx_discount_steam", "5");
g_pMenuEnableCvars[0] = register_cvar("amx_shop_weapon", "1");
g_pMenuEnableCvars[1] = register_cvar("amx_shop_invis", "1");
g_pInvisibilityMenuCvars[0] = register_cvar("amx_shop_low", "6000");
g_pInvisibilityMenuCvars[1] = register_cvar("amx_shop_medium", "10000");
g_pInvisibilityMenuCvars[2] = register_cvar("amx_shop_high", "13000");
g_pMenuEnableCvars[2] = register_cvar("amx_shop_grav", "1");
g_pGravityMenuCvars[0] = register_cvar("amx_shop_g700", "1500");
g_pGravityMenuCvars[1] = register_cvar("amx_shop_g600", "2500");
g_pGravityMenuCvars[2] = register_cvar("amx_shop_g500", "3500");
g_pGravityMenuCvars[3] = register_cvar("amx_shop_g400", "4500");
g_pMenuEnableCvars[3] = register_cvar("amx_shop_hp", "1");
g_pHealthMenuCvars[0] = register_cvar("amx_shop_15hp", "400");
g_pHealthMenuCvars[1] = register_cvar("amx_shop_35hp", "700");
g_pHealthMenuCvars[2] = register_cvar("amx_shop_65hp", "1000");
g_pHealthMenuCvars[3] = register_cvar("amx_shop_95hp", "1500");
g_pHealthMenuCvars[4] = register_cvar("amx_shop_200hp", "2800");
g_pMenuEnableCvars[4] = register_cvar("amx_shop_ap", "1");
g_pArmorMenuCvars[0] = register_cvar("amx_shop_15ap", "400");
g_pArmorMenuCvars[1] = register_cvar("amx_shop_35ap", "700");
g_pArmorMenuCvars[2] = register_cvar("amx_shop_65ap", "1000");
g_pArmorMenuCvars[3] = register_cvar("amx_shop_95ap", "1500");
g_pArmorMenuCvars[4] = register_cvar("amx_shop_200ap", "2800");
g_pMenuEnableCvars[5] = register_cvar("amx_shop_speed", "1");
g_pSpeedMenuCvars[0] = register_cvar("amx_shop_260speed", "4000");
g_pSpeedMenuCvars[1] = register_cvar("amx_shop_300speed", "6000");
g_pSpeedMenuCvars[2] = register_cvar("amx_shop_340speed", "8000");
g_pSpeedMenuCvars[3] = register_cvar("amx_shop_380speed", "10000");
g_pSpeedMenuCvars[4] = register_cvar("amx_shop_420speed", "12000");
// RegisterFunc
RegisterHam(Ham_Spawn, "player", "fwdHamPlayerSpawn", true);
RegisterHam(Ham_Item_PreFrame, "player", "fwdHamPreFrame", true);
g_Selected_Fwd = CreateMultiForward("shop_item_selected", ET_IGNORE, FP_CELL, FP_CELL);
}
public plugin_cfg()
{
new const FOLDER[] = "addons/amxmodx/configs";
new FileMain[128]; format(FileMain, charsmax(FileMain), "%s/ShopMenu.cfg", FOLDER);
if(file_exists(FileMain)) server_cmd("exec %s", FileMain);
new iMap[33]; get_mapname(iMap, 33);
new FileMap[128]; format(FileMap, charsmax(FileMap), "%s/ShopMenu/%s.cfg", FOLDER, iMap);
if(file_exists(FileMap)) server_cmd("exec %s", FileMap);
}
public plugin_natives()
{
register_native("shop_register_item", "native_register_item", 1);
register_native("shop_buy_item", "native_buy_item", 1);
}
public plugin_precache()
{
Item_Name = ArrayCreate(64, 1);
Item_Cost = ArrayCreate(1, 1);
}
public native_register_item(const Name[], const Cost)
{
param_convert(1);
param_convert(3);
ArrayPushString(Item_Name, Name);
ArrayPushCell(Item_Cost, Cost);
Item_Counter++;
return Item_Counter-1;
}
public fwdHamPlayerSpawn(id) g_SpeedUse[id] = false;
public fwdHamPreFrame(id) if(g_SpeedUse[id]) fm_set_user_maxspeed(id, g_lvlSpeed[id]);
public client_putinserver(id)
{
if(get_user_flags(id) & ADMIN_ACCESS) g_Discount[id] = get_pcvar_num(g_DiscountAdmin);
else if(get_user_flags(id) & VIP_ACCESS) g_Discount[id] = get_pcvar_num(g_DiscountVIP);
else if(is_user_steam(id)) g_Discount[id] = get_pcvar_num(g_DiscountSteam);
else g_Discount[id] = 0;
}
public OpenShopMenu(id)
{
if(!is_user_alive(id)) return ChatColor(id, "%s Вы должны быть живы, чтобы использовать меню!", CHAT_PREFIX);
new szData[256], Items[64], Position[3];
if(g_Discount[id] > 0) formatex(szData, charsmax(szData), "\r%s^n\dНаличные: \r%d$ \w| \dСкидка: \r%d%%\R", MENU_PREFIX, fm_get_user_money(id), g_Discount[id]);
else formatex(szData, charsmax(szData), "\r%s^n\dНаличные: \r%d$ \w| \dСкидка: \rОтсутствует\R", MENU_PREFIX, fm_get_user_money(id));
new Menu = menu_create(szData, "MainMenu_Handler");
for(new i = 0; i < sizeof(g_szMainShopMenu); i++)
{
formatex(Items, charsmax(Items), "%s%s", get_pcvar_num(g_pMenuEnableCvars) ? "\w" : "\d", g_szMainShopMenu);
num_to_str(i, Position, charsmax(Position));
menu_additem(Menu, Items, Position);
}
menu_setprop(Menu, MPROP_EXITNAME, "Выход");
return menu_display(id, Menu);
}
public MainMenu_Handler(id, Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Menu);
switch(item)
{
case 0:
{
new Wpn_Menu = menu_create("\rМеню оружия\R", "GunsMenu_Handler");
static Items[64], Position[3], Buffer[192];
for(new i = 0; i < Item_Counter; i++)
{
ArrayGetString(Item_Name, i, Items, charsmax(Items));
formatex(Buffer, charsmax(Buffer), "%s \d- \y%i$", Items, GetItemCost(id, ArrayGetCell(Item_Cost, i)));
num_to_str(i, Position, charsmax(Position));
menu_additem(Wpn_Menu, Buffer, Position);
}
menu_setprop(Wpn_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Wpn_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Wpn_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[0])) menu_display(id, Wpn_Menu);
else ChatColor(id, "%s Меню оружия выключено.", CHAT_PREFIX);
}
case 1:
{
new Inv_Menu = menu_create("\rМеню невидимости\R", "InvisibilityMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szInvisibilityMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pInvisibilityMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szInvisibilityMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Inv_Menu, Items, Position);
}
menu_setprop(Inv_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Inv_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Inv_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[1])) menu_display(id, Inv_Menu);
else ChatColor(id, "%s Меню невидимости выключено.", CHAT_PREFIX);
}
case 2:
{
new Grav_Menu = menu_create("\rМеню гравитации\R", "GravityMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szGravityMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pGravityMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szGravityMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Grav_Menu, Items, Position);
}
menu_setprop(Grav_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Grav_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Grav_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[2])) menu_display(id, Grav_Menu);
else ChatColor(id, "%s Меню гравитации выключено.", CHAT_PREFIX);
}
case 3:
{
new Hp_Menu = menu_create("\rМеню здоровья\R", "HealthMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szHealthMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pHealthMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szHealthMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Hp_Menu, Items, Position);
}
menu_setprop(Hp_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Hp_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Hp_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[3])) menu_display(id, Hp_Menu);
else ChatColor(id, "%s Меню здоровья выключено.", CHAT_PREFIX);
}
case 4:
{
new Ap_Menu = menu_create("\rМеню брони\R", "ArmorMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szArmorMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pArmorMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szArmorMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Ap_Menu, Items, Position);
}
menu_setprop(Ap_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Ap_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Ap_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[4])) menu_display(id, Ap_Menu);
else ChatColor(id, "%s Меню брони выключено.", CHAT_PREFIX);
}
case 5:
{
new Speed_Menu = menu_create("\rМеню скорости\R", "SpeedMenu_Handler");
new Items[64], Position[3];
for(new i = 0; i < sizeof(g_szSpeedMenu); i++)
{
new Discount = GetItemCost(id, get_pcvar_num(g_pSpeedMenuCvars));
formatex(Items, charsmax(Items), "%s \d- \y%d$", g_szSpeedMenu, Discount);
num_to_str(i, Position, charsmax(Position));
menu_additem(Speed_Menu, Items, Position);
}
menu_setprop(Speed_Menu, MPROP_BACKNAME, "Назад");
menu_setprop(Speed_Menu, MPROP_NEXTNAME, "Вперед");
menu_setprop(Speed_Menu, MPROP_EXITNAME, "Выход");
if(get_pcvar_num(g_pMenuEnableCvars[5])) menu_display(id, Speed_Menu);
else ChatColor(id, "%s Меню скорости выключено.", CHAT_PREFIX);
}
}
return menu_destroy(Menu);
}
public GunsMenu_Handler(id, Guns_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Guns_Menu);
native_buy_item(id, item);
return menu_destroy(Guns_Menu);
}
public native_buy_item(id, item)
{
new Money = fm_get_user_money(id);
static Discount, DummyItem, NameItem[64];
Discount = GetItemCost(id, ArrayGetCell(Item_Cost, item));
ArrayGetString(Item_Name, item, NameItem, sizeof(NameItem));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %i$^1)", CHAT_PREFIX, Discount);
ExecuteForward(g_Selected_Fwd, DummyItem, id, item);
fm_set_user_money(id, Money-Discount);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%i$", CHAT_PREFIX, NameItem, Discount);
return PLUGIN_HANDLED;
}
public InvisibilityMenu_Handler(id, Inv_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Inv_Menu);
new Money = fm_get_user_money(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pInvisibilityMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
fm_set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, g_iInvisibilityLevel[item]);
ChatColor(id, "%s Вы приобрели '^3Невидимость: %s^1' за ^4%d$", CHAT_PREFIX, g_szInvisibilityMenu[item], Discount);
return menu_destroy(Inv_Menu);
}
public GravityMenu_Handler(id, Grav_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Grav_Menu);
new Money = fm_get_user_money(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pGravityMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
fm_set_user_gravity(id, g_iGravityLevel[item]);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%d$", CHAT_PREFIX, g_szGravityMenu[item], Discount);
return menu_destroy(Grav_Menu);
}
public HealthMenu_Handler(id, Hp_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Hp_Menu);
new Money = fm_get_user_money(id);
new Health = get_user_health(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pHealthMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
if(Health + g_iHealthLevel[item] > BUYHP_MAX) fm_set_user_health(id, BUYHP_MAX);
else fm_set_user_health(id, Health + g_iHealthLevel[item]);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%d$", CHAT_PREFIX, g_szHealthMenu[item], Discount);
return menu_destroy(Hp_Menu);
}
public ArmorMenu_Handler(id, Ap_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Ap_Menu);
new Money = fm_get_user_money(id);
new Armor = get_user_armor(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pArmorMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
if(Armor + g_iArmorLevel[item] > BUYAP_MAX) fm_set_user_armor(id, BUYAP_MAX);
else fm_set_user_armor(id, Armor + g_iArmorLevel[item]);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%d$", CHAT_PREFIX, g_szArmorMenu[item], Discount);
return menu_destroy(Ap_Menu);
}
public SpeedMenu_Handler(id, Speed_Menu, item)
{
if(item == MENU_EXIT) return menu_destroy(Speed_Menu);
new Money = fm_get_user_money(id);
new Discount = GetItemCost(id, get_pcvar_num(g_pSpeedMenuCvars[item]));
if(!Discount) return ChatColor(id, "%s Этот пункт заблокирован!", CHAT_PREFIX);
if(Money < Discount) return ChatColor(id, "%s Недостаточно денег для покупки! (^4нужно %d$^1)", CHAT_PREFIX, Discount);
fm_set_user_money(id, Money-Discount);
g_lvlSpeed[id] = g_iSpeedLevel[item];
g_SpeedUse[id] = true; fwdHamPreFrame(id);
ChatColor(id, "%s Вы приобрели '^3%s^1' за ^4%d$", CHAT_PREFIX, g_szSpeedMenu[item], Discount);
return menu_destroy(Speed_Menu);
}
stock bool:is_user_steam(id)
{
static dp_pointer;
if(dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
{
server_cmd("dp_clientinfo %d", id);
server_exec();
return (get_pcvar_num(dp_pointer) == 2) ? true : false;
}
return false;
}
stock GetItemCost(id, iCost)
{
iCost -= floatround(iCost / 100.0 * g_Discount[id]);
return iCost;
}
stock fm_set_user_maxspeed(id, Float:speed = -1.0)
{
engfunc(EngFunc_SetClientMaxspeed, id, speed);
set_pev(id, pev_maxspeed, speed);
return 1;
}
stock fm_set_user_gravity(id, Float:gravity = 1.0)
{
set_pev(id, pev_gravity, gravity);
return 1;
}
stock fm_set_user_rendering(id, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
{
new CountAmount = amount * 255 / 100;
new Float:RenderColor[3];
RenderColor[0] = float®;
RenderColor[1] = float(g);
RenderColor[2] = float(b);
set_pev(id, pev_renderfx, fx);
set_pev(id, pev_rendercolor, RenderColor);
set_pev(id, pev_rendermode, render);
set_pev(id, pev_renderamt, float(CountAmount));
return 1;
}
stock fm_set_user_armor(id, armor)
{
set_pev(id, pev_armorvalue, float(armor));
return 1;
}
stock fm_set_user_health(id, health)
{
health > 0 ? set_pev(id, pev_health, float(health)) : dllfunc(DLLFunc_ClientKill, id);
return 1;
}
stock fm_set_user_money(id, money, flash = 0)
{
set_pdata_int(id, OFFSET_CSMONEY, money, 5);
message_begin(MSG_ONE, get_user_msgid("Money"), {0,0,0}, id);
write_long(money);
write_byte(flash);
message_end();
}
stock fm_get_user_money(id)
return get_pdata_int(id, OFFSET_CSMONEY, 5);
stock ChatColor(const id, const szMessage[], any:...)
{
static pnum, players[32], szMsg[190], IdMsg;
vformat(szMsg, charsmax(szMsg), szMessage, 3);
if(!IdMsg) IdMsg = get_user_msgid("SayText");
if(id)
{
players[0] = id;
pnum = 1;
}
else get_players(players, pnum, "ch");
for(new i; i < pnum; i++)
{
message_begin(MSG_ONE, IdMsg, .player = players);
write_byte(players);
write_string(szMsg);
message_end();
}
return 1;
}