#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#pragma semicolon 1
#define PLAYERS_PER_PAGE 7
#define MAX_PLAYERS 32
#define MsgId_SayText 76
#define is_user_valid(%0) (%0 && %0 <= g_iMaxPlayers)
new g_iMaxPlayers;
new bool:g_iUserTeam[MAX_PLAYERS + 1];
new g_iMenuPlayers[MAX_PLAYERS + 1][MAX_PLAYERS], g_iMenuPosition[MAX_PLAYERS + 1], g_iMenuTarget[MAX_PLAYERS + 1];
public plugin_init()
{
register_plugin("Donate money", "0.1", "Sanlerus \ di.alyabev"); // надеюсь барен не против!
register_dictionary("donate_money.txt");
register_clcmd("money_transfer", "ClCmd_MoneyTransfer");
register_clcmd("say /donate", "Show_MoneyTransferMenu");
register_clcmd("say /moneytransfer", "Show_MoneyTransferMenu");
register_menucmd(register_menuid("Show_MoneyTransferMenu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_MoneyTransferMenu");
register_menucmd(register_menuid("Show_MoneyAmountMenu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<7|1<<8|1<<9), "Handle_MoneyAmountMenu");
g_iMaxPlayers = get_maxplayers();
}
public Show_MoneyTransferMenu(id, iPos)
{
if(iPos < 0) return PLUGIN_HANDLED;
new iPlayersNum;
for(new i = 1; i <= g_iMaxPlayers; i++)
{
if(!is_user_connected(i) || i == id) continue;
if(g_iUserTeam[id] && get_user_team(i) == 1)
g_iMenuPlayers[id][iPlayersNum++] = i;
else if(!g_iUserTeam[id] && get_user_team(i) == 2)
g_iMenuPlayers[id][iPlayersNum++] = i;
}
new iStart = iPos * PLAYERS_PER_PAGE;
if(iStart > iPlayersNum) iStart = iPlayersNum;
iStart = iStart - (iStart % 7);
g_iMenuPosition[id] = iStart / PLAYERS_PER_PAGE;
new iEnd = iStart + PLAYERS_PER_PAGE;
if(iEnd > iPlayersNum) iEnd = iPlayersNum;
new szMenu[512], iLen, iPagesNum = (iPlayersNum / PLAYERS_PER_PAGE + ((iPlayersNum % PLAYERS_PER_PAGE) ? 1 : 0));
switch(iPagesNum)
{
case 0:
{
UTIL_SayText(id, "!g[SERVER] %L", id, "CHAT_ID_PLAYERS_NOT_VALID");
return PLUGIN_HANDLED;
}
default: iLen = formatex(szMenu, charsmax(szMenu), "\y%L \w[%d|%d]^n\d%L^n", id, "MENU_MONEY_TRANSFER_TITLE", iPos + 1, iPagesNum, id, "MENU_MONEY_YOU_AMOUNT", cs_get_user_money(id));
}
new szName[32], i, iKeys = (1<<9), b;
for(new a = iStart; a < iEnd; a++)
{
i = g_iMenuPlayers[id][a];
get_user_name(i, szName, charsmax(szName));
iKeys |= (1<<b);
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[%d] \w%s \r[%d руб]^n", ++b, szName, cs_get_user_money(i));
}
if(g_iUserTeam[id])
{
iKeys |= (1<<7);
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\y[8] \wПередать \r[Т]");
}
else
{
iKeys |= (1<<7);
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\y[8] \wПередать \r[СТ]");
}
for(new i = b; i < PLAYERS_PER_PAGE; i++) iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n");
if(iEnd < iPlayersNum)
{
iKeys |= (1<<8);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\y[9] \w%L^n\y[0] \w%L", id, "MENU_NEXT", id, iPos ? "MENU_BACK" : "MENU_EXIT");
}
else formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\y[0] \w%L", id, iPos ? "MENU_BACK" : "MENU_EXIT");
return show_menu(id, iKeys, szMenu, -1, "Show_MoneyTransferMenu");
}
public Handle_MoneyTransferMenu(id, iKey)
{
switch(iKey)
{
case 7:
{
g_iUserTeam[id] = g_iUserTeam[id] ? false : true;
return Show_MoneyTransferMenu(id, g_iMenuPosition[id]);
}
case 8: return Show_MoneyTransferMenu(id, ++g_iMenuPosition[id]);
case 9: return Show_MoneyTransferMenu(id, --g_iMenuPosition[id]);
default:
{
g_iMenuTarget[id] = g_iMenuPlayers[id][g_iMenuPosition[id] * PLAYERS_PER_PAGE + iKey];
return Show_MoneyAmountMenu(id);
}
}
return PLUGIN_HANDLED;
}
Show_MoneyAmountMenu(id)
{
new szMenu[512], iKeys = (1<<8|1<<9), iLen = formatex(szMenu, charsmax(szMenu), "\y%L^n\d%L^n", id, "MENU_MONEY_AMOUNT_TITLE", id, "MENU_MONEY_YOU_AMOUNT", cs_get_user_money(id));
if(cs_get_user_money(id))
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[1] \w%d руб^n", floatround(cs_get_user_money(id) * 0.10, floatround_ceil));
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[2] \w%d руб^n", floatround(cs_get_user_money(id) * 0.25, floatround_ceil));
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[3] \w%d руб^n", floatround(cs_get_user_money(id) * 0.50, floatround_ceil));
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[4] \w%d руб^n", floatround(cs_get_user_money(id) * 0.75, floatround_ceil));
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[5] \w%d руб^n^n^n", cs_get_user_money(id));
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[8] \w%L^n", id, "MENU_MONEY_SPECIFY_AMOUNT");
iKeys |= (1<<0|1<<1|1<<2|1<<3|1<<4|1<<7);
}
else
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[1] \d0 руб^n\y[2] \d0 руб^n\y[3] \d0 руб^n\y[4] \d0 руб^n\y[5] \d0 руб^n^n^n");
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[8] \d%L^n", id, "MENU_MONEY_SPECIFY_AMOUNT");
}
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\y[9] \w%L", id, "MENU_BACK");
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\y[0] \w%L", id, "MENU_EXIT");
return show_menu(id, iKeys, szMenu, -1, "Show_MoneyAmountMenu");
}
public Handle_MoneyAmountMenu(id, iKey)
{
switch(iKey)
{
case 0: ClCmd_MoneyTransfer(id, g_iMenuTarget[id], floatround(cs_get_user_money(id) * 0.10, floatround_ceil));
case 1: ClCmd_MoneyTransfer(id, g_iMenuTarget[id], floatround(cs_get_user_money(id) * 0.25, floatround_ceil));
case 2: ClCmd_MoneyTransfer(id, g_iMenuTarget[id], floatround(cs_get_user_money(id) * 0.50, floatround_ceil));
case 3: ClCmd_MoneyTransfer(id, g_iMenuTarget[id], floatround(cs_get_user_money(id) * 0.75, floatround_ceil));
case 4: ClCmd_MoneyTransfer(id, g_iMenuTarget[id], cs_get_user_money(id));
case 7: client_cmd(id, "messagemode ^"money_transfer %d^"", g_iMenuTarget[id]);
case 8: return Show_MoneyTransferMenu(id, g_iMenuPosition[id]);
}
return PLUGIN_HANDLED;
}
public ClCmd_MoneyTransfer(id, iTarget, iMoney)
{
if(!iTarget)
{
new szArg1[3], szArg2[7];
read_argv(1, szArg1, charsmax(szArg1));
read_argv(2, szArg2, charsmax(szArg2));
if(!is_str_num(szArg1) || !is_str_num(szArg2))
{
UTIL_SayText(id, "!g[SERVER] %L", id, "CHAT_ID_ERROR_PARAMETERS");
return PLUGIN_HANDLED;
}
iTarget = str_to_num(szArg1);
iMoney = str_to_num(szArg2);
}
if(id == iTarget || !is_user_valid(iTarget) || !is_user_connected(iTarget)) UTIL_SayText(id, "!g[SERVER] %L", id, "CHAT_ID_UNKNOWN_PLAYER");
else if(cs_get_user_money(id) < iMoney) UTIL_SayText(id, "!g[SERVER] %L", id, "CHAT_ID_SUFFICIENT_FUNDS");
else if(iMoney <= 0) UTIL_SayText(id, "!g[SERVER] %L", id, "CHAT_ID_MIN_AMOUNT_TRANSFER");
else
{
cs_set_user_money(iTarget, cs_get_user_money(iTarget) + iMoney);
cs_set_user_money(id, cs_get_user_money(id) - iMoney);
new szName[32], szNameTarget[32];
get_user_name(id, szName, charsmax(szName));
get_user_name(iTarget, szNameTarget, charsmax(szNameTarget));
UTIL_SayText(0, "!g[SERVER] %L", id, "CHAT_ALL_MONEY_TRANSFER", szName, iMoney, szNameTarget);
}
return PLUGIN_HANDLED;
}
stock UTIL_SayText(pPlayer, const szMessage[], any:...)
{
new szBuffer[190];
if(numargs() > 2) vformat(szBuffer, charsmax(szBuffer), szMessage, 3);
else copy(szBuffer, charsmax(szBuffer), szMessage);
while(replace(szBuffer, charsmax(szBuffer), "!y", "^1")) {}
while(replace(szBuffer, charsmax(szBuffer), "!t", "^3")) {}
while(replace(szBuffer, charsmax(szBuffer), "!g", "^4")) {}
switch(pPlayer)
{
case 0:
{
for(new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++)
{
if(!is_user_connected(iPlayer)) continue;
engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, MsgId_SayText, {0.0, 0.0, 0.0}, iPlayer);
write_byte(iPlayer);
write_string(szBuffer);
message_end();
}
}
default:
{
engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, MsgId_SayText, {0.0, 0.0, 0.0}, pPlayer);
write_byte(pPlayer);
write_string(szBuffer);
message_end();
}
}
}