#include <amxmodx>
#include <reapi>
#define VERSION "1.0"
#define is_user_vip(%0) (get_user_flags(%0) & VIP_FLAG)
#define get_player_money(%1) get_member(%1, m_iAccount)
/* Настройки */
#define VIP_FLAG (ADMIN_IMMUNITY|ADMIN_LEVEL_H)
new const prefix[] = "^1[^4SHOP^1]"
const iTime = 5
const iCostRoll = 80
const iRoundLimitPlayer = 1
const iRoundLimitVip = 2
const iMapLimitPlayer = 10
const iMapLimitVip = 20
const g_Discount = 20
enum _:ItemData { ItemCase[10], ItemName[64], ItemGive[20], ItemAmmo, ItemCost, ItemTeam }
new const g_ItemList[][ItemData] = {
{ "weapon", "AWP", "weapon_awp", 1, 300, 2 },
{ "nade", "HE", "weapon_hegrenade", 1, 50, 0 },
{ "nade", "Flash", "weapon_flashbang", 1, 90, 1 },
{ "nade", "Frost", "weapon_smokegrenade", 1, 120, 1 }
};
new g_RoundCounter[MAX_PLAYERS+1], g_MapCounter[MAX_PLAYERS+1], g_NowUsed[MAX_PLAYERS+1], g_LastTry;
public plugin_init() {
register_plugin("Nade Shop", VERSION, "MIRDOBRO");
register_clcmd("say /shop", "OpenMenu");
register_clcmd("say /mt", "OpenMenu");
RegisterHookChain(RG_CSGameRules_RestartRound, "@refwd_NewRound_Post", true);
}
@refwd_NewRound_Post() {
for (new i = 1; i <= MAX_PLAYERS; i++) {
g_RoundCounter[i] = 0;
}
}
public OpenMenu(id) {
new sysTime = get_systime();
g_LastTry = g_NowUsed[id];
new TimeRemaining = iTime - (sysTime - g_LastTry);
new authid[32], name[32];
get_user_authid(id,authid,31);
get_user_name(id,name,31);
if(!is_user_alive(id)) {
client_print_color(id, print_team_red, "%s ^3Доступно только ^4живым ^3игрокам", prefix);
return PLUGIN_HANDLED;
}
if(g_RoundCounter[id] == iRoundLimitPlayer && !is_user_vip(id)) {
log_to_file("addons\amxmodx\logs\round_player.txt" , "^nНик: %s, %s^nБаланс: $%d, Лимит: %d/%d^n", name, authid, get_player_money(id), g_RoundCounter[id], iRoundLimitPlayer);
client_print_color(id, print_team_red, "%s ^3Достигнут лимит открытия магазина в этом раунде", prefix);
return PLUGIN_HANDLED;
}
else
if(g_RoundCounter[id] == iRoundLimitVip) {
log_to_file("addons\amxmodx\logs\round_vip.txt" , "^nНик: %s, %s^nБаланс: $%d, Лимит: %d/%d^n", name, authid, get_player_money(id), g_RoundCounter[id], iRoundLimitVip);
client_print_color(id, print_team_red, "%s ^3Достигнут лимит открытия магазина в этом раунде", prefix);
return PLUGIN_HANDLED;
}
if(g_MapCounter[id] == iMapLimitPlayer && !is_user_vip(id)) {
client_print_color(id, print_team_red, "%s ^3Достигнут лимит открытия магазина на этой карте", prefix);
return PLUGIN_HANDLED;
}
else
if(g_MapCounter[id] == iMapLimitVip) {
log_to_file("addons\amxmodx\logs\map_vip.txt" , "^nНик: %s, %s^nБаланс: $%d, Лимит: %d/%d^n", name, authid, get_player_money(id), g_MapCounter[id], iMapLimitVip);
client_print_color(id, print_team_red, "%s ^3Достигнут лимит открытия магазина на этой карте", prefix);
return PLUGIN_HANDLED;
}
if(iTime > (sysTime - g_LastTry)) {
log_to_file("addons\amxmodx\logs\time.txt" , "^nНик: %s, %s^nБаланс: $%d, Время: %d, Осталось: %d^n", name, authid, get_player_money(id), iTime, TimeRemaining);
client_print_color(id, print_team_red, "%s ^3Следующую покупку можно совершить через ^4%d^3 сек., осталось подождать ^4%d^3 сек.", prefix, iTime, TimeRemaining);
return PLUGIN_HANDLED;
}
GoMenu(id);
return PLUGIN_HANDLED;
}
GoMenu(id) {
new iPlayerMoney = get_player_money(id);
new NumLimit, szTitle[128], szItem[128], iDiscount, CurrentTime[32];
new NowTime = get_time("%H",CurrentTime,31);
if(is_user_vip(id) || (NowTime >= 15 && NowTime < 17)) {
NumLimit = iMapLimitVip;
iDiscount = g_Discount;
} else {
NumLimit = iMapLimitPlayer;
iDiscount = 0;
}
new authid[32], name[32];
get_user_authid(id,authid,31);
get_user_name(id,name,31);
formatex(szTitle, charsmax(szTitle), "\wБаланс: \r$%d \w| Скидка: \r%d%%^n\wПокупок за карту: \r%d/%d^n", iPlayerMoney, iDiscount, g_MapCounter[id], NumLimit);
new iMenu = menu_create(szTitle, "MenuHandler");
if(menu_pages(iMenu) > 1) {
formatex(szItem, charsmax(szItem), "%s^n\yСтраница: \r", szTitle);
menu_setprop(iMenu, MPROP_TITLE, szItem);
}
for(new i = 0; i < sizeof(g_ItemList); i++) {
new iCost = g_ItemList[i][ItemCost] - g_ItemList[i][ItemCost] * iDiscount / 100;
new iTeam = g_ItemList[i][ItemTeam];
new szNum[3];
num_to_str(i, szNum, charsmax(szNum));
formatex(szItem, charsmax(szItem), "^n\w%s [ \y$%d \w]", g_ItemList[i][ItemName], iCost);
if(iTeam == 0 && iPlayerMoney >= iCost)
menu_additem(iMenu, szItem, szNum);
else if(iTeam == 1 && get_member(id, m_iTeam) == CS_TEAM_T && iPlayerMoney >= iCost)
menu_additem(iMenu, szItem, szNum);
else if(iTeam == 0 || iTeam == 2 && get_member(id, m_iTeam) == CS_TEAM_CT && iPlayerMoney >= iCost)
menu_additem(iMenu, szItem, szNum);
}
menu_setprop(iMenu, MPROP_BACKNAME, "\yНазад");
menu_setprop(iMenu, MPROP_NEXTNAME, "\yДалее");
menu_setprop(iMenu, MPROP_EXITNAME, "\rЗакрыть");
menu_display(id, iMenu);
return PLUGIN_HANDLED
}
public MenuHandler(id, iMenu, iItem) {
if(!is_user_alive(id) || iItem == MENU_EXIT) {
menu_destroy(iMenu);
return PLUGIN_HANDLED;
}
new iDiscount, CurrentTime[32];
new iPlayerMoney = get_player_money(id);
new NowTime = get_time("%H",CurrentTime,31);
if(is_user_vip(id) || (NowTime >= 15 && NowTime < 17)) iDiscount = g_Discount;
else iDiscount = 0;
new iCost = g_ItemList[iItem][ItemCost] - g_ItemList[iItem][ItemCost] * iDiscount / 100;
new iTeam = g_ItemList[iItem][ItemTeam];
if(iItem != MENU_EXIT) {
if(iTeam == 0 && iPlayerMoney >= iCost)
GiveItem(id, iItem);
else if(iTeam == 1 && get_member(id, m_iTeam) == CS_TEAM_T && iPlayerMoney >= iCost)
GiveItem(id, iItem);
else if(iTeam == 0 || iTeam == 2 && get_member(id, m_iTeam) == CS_TEAM_CT && iPlayerMoney >= iCost)
GiveItem(id, iItem);
else menu_destroy(iMenu);
}
return PLUGIN_HANDLED;
}
GiveItem(id, i) {
new iAmmo = g_ItemList[i][ItemAmmo];
new iDiscount, CurrentTime[32], sysTime = get_systime();
new NowTime = get_time("%H",CurrentTime,31);
if(is_user_vip(id) || (NowTime >= 15 && NowTime < 17)) iDiscount = g_Discount;
else iDiscount = 0;
new iCost = g_ItemList[i][ItemCost] - g_ItemList[i][ItemCost] * iDiscount / 100;
switch(g_ItemList[i][ItemCase]) {
case 'n': {
rg_give_item(id, g_ItemList[i][ItemGive]);
rg_set_user_bpammo(id, rg_get_weapon_info(g_ItemList[i][ItemGive], WI_ID), iAmmo);
rg_add_account(id, get_player_money(id) - iCost, AS_SET);
g_RoundCounter[id]++;
g_MapCounter[id]++;
g_NowUsed[id] = sysTime;
log_to_file("addons\amxmodx\logs\nade.txt", "^nCase: %s, Name: %s^nItem: %s, Ammo: %d, Cost: %d^nBalance: $%d^n", g_ItemList[i][ItemCase], g_ItemList[i][ItemName], g_ItemList[i][ItemGive], g_ItemList[i][ItemAmmo], iCost, get_player_money(id));
client_print_color(id, print_team_red, "%s ^3Вы успешно купили ^4%s", prefix, g_ItemList[i][ItemName]);
}
case 'w': {
rg_remove_item(id, g_ItemList[i][ItemGive], true);
new iWpn = rg_give_item(id, g_ItemList[i][ItemGive], GT_REPLACE);
if(is_nullent(iWpn)) return;
set_member(iWpn, m_Weapon_iClip, iAmmo);
rg_set_user_bpammo(id, rg_get_weapon_info(g_ItemList[i][ItemGive], WI_ID), 0);
rg_add_account(id, get_player_money(id) - iCost, AS_SET);
g_RoundCounter[id]++;
g_MapCounter[id]++;
g_NowUsed[id] = sysTime;
log_to_file("addons\amxmodx\logs\weapon.txt", "^nCase: %s, Name: %s^nItem: %s, Ammo: %d, Cost: %d^nBalance: $%d^n", g_ItemList[i][ItemCase], g_ItemList[i][ItemName], g_ItemList[i][ItemGive], g_ItemList[i][ItemAmmo], iCost, get_player_money(id));
client_print_color(id, print_team_red, "%s ^3Вы успешно купили ^4%s", prefix, g_ItemList[i][ItemName]);
}
}
}