plmenu: improve readability, more compliance to amxmodx style

This commit is contained in:
Freeman-AM 2015-03-21 13:54:39 +01:00
parent 32e1908859
commit 5413c59bc7

View File

@ -121,7 +121,9 @@ public plugin_init()
load_settings(clcmds_ini_file);
if (LibraryExists("cstrike", LibType_Library))
{
g_cstrike = 1;
}
if (LibraryExists("fakemeta", LibType_Library))
{
g_fakemeta = 1;
@ -208,7 +210,9 @@ public plmenu_setslapdmg()
public module_filter(const module[])
{
if (equali(module, "cstrike") || equali(module, "fakemeta"))
{
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
@ -216,7 +220,9 @@ public module_filter(const module[])
public native_filter(const name[], index, trap)
{
if (!trap)
{
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
@ -238,8 +244,14 @@ public actionBanMenu(id, key)
displayBanMenu(id, g_menuPosition[id]);
}
case 8: displayBanMenu(id, ++g_menuPosition[id]);
case 9: displayBanMenu(id, --g_menuPosition[id]);
case 8:
{
displayBanMenu(id, ++g_menuPosition[id]);
}
case 9:
{
displayBanMenu(id, --g_menuPosition[id]);
}
default:
{
new banTime = g_menuSettings[id];
@ -316,7 +328,9 @@ public actionBanMenu(id, key)
displayBanMenu(id, pos)
{
if (pos < 0)
{
return;
}
get_players(g_menuPlayers[id], g_menuPlayersNum[id]);
@ -327,14 +341,18 @@ displayBanMenu(id, pos)
new start = pos * 7;
if (start >= g_menuPlayersNum[id])
{
start = pos = g_menuPosition[id] = 0;
}
new len = formatex(menuBody, charsmax(menuBody), g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "BAN_MENU", pos + 1, (g_menuPlayersNum[id] / 7 + ((g_menuPlayersNum[id] % 7) ? 1 : 0)));
new end = start + 7;
new keys = MENU_KEY_0|MENU_KEY_8;
if (end > g_menuPlayersNum[id])
{
end = g_menuPlayersNum[id];
}
for (new a = start; a < end; ++a)
{
@ -346,23 +364,37 @@ displayBanMenu(id, pos)
++b;
if (g_coloredMenus)
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "\d%d. %s^n\w", b, name);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "#. %s^n", name);
} else {
}
}
else
{
keys |= (1<<b);
if (is_user_admin(i))
{
len += formatex(menuBody[len], charsmax(menuBody) - len, g_coloredMenus ? "%d. %s \r*^n\w" : "%d. %s *^n", ++b, name);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "%d. %s^n", ++b, name);
}
}
}
if (g_menuSettings[id])
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n8. %L^n", id, "BAN_FOR_MIN", g_menuSettings[id]);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n8. %L^n", id, "BAN_PERM");
}
if (end != g_menuPlayersNum[id])
{
@ -370,7 +402,9 @@ displayBanMenu(id, pos)
keys |= MENU_KEY_9;
}
else
{
formatex(menuBody[len], charsmax(menuBody) - len, "^n0. %L", id, pos ? "BACK" : "EXIT");
}
show_menu(id, keys, menuBody, -1, "Ban Menu");
}
@ -378,7 +412,9 @@ displayBanMenu(id, pos)
public cmdBanMenu(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
{
return PLUGIN_HANDLED;
}
g_menuOption[id] = 0;
@ -412,8 +448,14 @@ public actionSlapMenu(id, key)
displaySlapMenu(id, g_menuPosition[id]);
}
case 8: displaySlapMenu(id, ++g_menuPosition[id]);
case 9: displaySlapMenu(id, --g_menuPosition[id]);
case 8:
{
displaySlapMenu(id, ++g_menuPosition[id]);
}
case 9:
{
displaySlapMenu(id, --g_menuPosition[id]);
}
default:
{
new player = g_menuPlayers[id][g_menuPosition[id] * 7 + key];
@ -442,7 +484,9 @@ public actionSlapMenu(id, key)
show_activity_key("ADMIN_SLAP_1", "ADMIN_SLAP_2", name, name2, g_menuSettings[id]);
user_slap(player, (get_user_health(player) > g_menuSettings[id]) ? g_menuSettings[id] : 0);
} else { // aSize == 1 or g_menuOption[id] == aSize - 1 // last option
}
else // aSize == 1 or g_menuOption[id] == aSize - 1 // last option
{
log_amx("Cmd: ^"%s<%d><%s><>^" slay ^"%s<%d><%s><>^"", name, get_user_userid(id), authid, name2, get_user_userid(player), authid2);
show_activity_key("ADMIN_SLAY_1", "ADMIN_SLAY_2", name, name2);
@ -460,7 +504,9 @@ public actionSlapMenu(id, key)
displaySlapMenu(id, pos)
{
if (pos < 0)
{
return;
}
get_players(g_menuPlayers[id], g_menuPlayersNum[id]);
@ -471,14 +517,18 @@ displaySlapMenu(id, pos)
new start = pos * 7;
if (start >= g_menuPlayersNum[id])
{
start = pos = g_menuPosition[id] = 0;
}
new len = formatex(menuBody, charsmax(menuBody), g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "SLAP_SLAY_MENU", pos + 1, (g_menuPlayersNum[id] / 7 + ((g_menuPlayersNum[id] % 7) ? 1 : 0)));
new end = start + 7;
new keys = MENU_KEY_0|MENU_KEY_8;
if (end > g_menuPlayersNum[id])
{
end = g_menuPlayersNum[id];
}
for (new a = start; a < end; ++a)
{
@ -494,10 +544,14 @@ displaySlapMenu(id, pos)
else if (cs_get_user_team(i) == CS_TEAM_CT)
{
copy(team, charsmax(team), "CT");
} else {
}
else
{
get_user_team(i, team, charsmax(team));
}
} else {
}
else
{
get_user_team(i, team, charsmax(team));
}
@ -506,23 +560,37 @@ displaySlapMenu(id, pos)
++b;
if (g_coloredMenus)
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "\d%d. %s\R%s^n\w", b, name, team);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "#. %s %s^n", name, team);
} else {
}
}
else
{
keys |= (1<<b);
if (is_user_admin(i))
{
len += formatex(menuBody[len], charsmax(menuBody) - len, g_coloredMenus ? "%d. %s \r*\y\R%s^n\w" : "%d. %s * %s^n", ++b, name, team);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, g_coloredMenus ? "%d. %s\y\R%s^n\w" : "%d. %s %s^n", ++b, name, team);
}
}
}
if (g_menuOption[id] == ArraySize(g_slapsettings) - 1)
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n8. %L^n", id, "SLAY");
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n8. %L^n", id, "SLAP_WITH_DMG", g_menuSettings[id]);
}
if (end != g_menuPlayersNum[id])
{
@ -530,7 +598,9 @@ displaySlapMenu(id, pos)
keys |= MENU_KEY_9;
}
else
{
formatex(menuBody[len], charsmax(menuBody) - len, "^n0. %L", id, pos ? "BACK" : "EXIT");
}
show_menu(id, keys, menuBody, -1, "Slap/Slay Menu");
}
@ -538,7 +608,9 @@ displaySlapMenu(id, pos)
public cmdSlapMenu(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
{
return PLUGIN_HANDLED;
}
g_menuOption[id] = 0;
if (ArraySize(g_slapsettings) > 0)
@ -562,8 +634,14 @@ public actionKickMenu(id, key)
{
switch (key)
{
case 8: displayKickMenu(id, ++g_menuPosition[id]);
case 9: displayKickMenu(id, --g_menuPosition[id]);
case 8:
{
displayKickMenu(id, ++g_menuPosition[id]);
}
case 9:
{
displayKickMenu(id, --g_menuPosition[id]);
}
default:
{
new player = g_menuPlayers[id][g_menuPosition[id] * 8 + key];
@ -593,7 +671,9 @@ public actionKickMenu(id, key)
displayKickMenu(id, pos)
{
if (pos < 0)
{
return;
}
get_players(g_menuPlayers[id], g_menuPlayersNum[id]);
@ -604,14 +684,18 @@ displayKickMenu(id, pos)
new start = pos * 8;
if (start >= g_menuPlayersNum[id])
{
start = pos = g_menuPosition[id] = 0;
}
new len = formatex(menuBody, charsmax(menuBody), g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "KICK_MENU", pos + 1, (g_menuPlayersNum[id] / 8 + ((g_menuPlayersNum[id] % 8) ? 1 : 0)));
new end = start + 8;
new keys = MENU_KEY_0;
if (end > g_menuPlayersNum[id])
{
end = g_menuPlayersNum[id];
}
for (new a = start; a < end; ++a)
{
@ -623,18 +707,28 @@ displayKickMenu(id, pos)
++b;
if (g_coloredMenus)
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "\d%d. %s^n\w", b, name);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "#. %s^n", name);
} else {
}
}
else
{
keys |= (1<<b);
if (is_user_admin(i))
{
len += formatex(menuBody[len], charsmax(menuBody) - len, g_coloredMenus ? "%d. %s \r*^n\w" : "%d. %s *^n", ++b, name);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "%d. %s^n", ++b, name);
}
}
}
if (end != g_menuPlayersNum[id])
{
@ -642,7 +736,9 @@ displayKickMenu(id, pos)
keys |= MENU_KEY_9;
}
else
{
formatex(menuBody[len], charsmax(menuBody) - len, "^n0. %L", id, pos ? "BACK" : "EXIT");
}
show_menu(id, keys, menuBody, -1, "Kick Menu");
}
@ -650,7 +746,9 @@ displayKickMenu(id, pos)
public cmdKickMenu(id, level, cid)
{
if (cmd_access(id, level, cid, 1))
{
displayKickMenu(id, g_menuPosition[id] = 0);
}
return PLUGIN_HANDLED;
}
@ -696,8 +794,14 @@ public actionTeamMenu(id, key)
g_menuOption[id] = (g_menuOption[id] + 1) % 3;
displayTeamMenu(id, g_menuPosition[id]);
}
case 8: displayTeamMenu(id, ++g_menuPosition[id]);
case 9: displayTeamMenu(id, --g_menuPosition[id]);
case 8:
{
displayTeamMenu(id, ++g_menuPosition[id]);
}
case 9:
{
displayTeamMenu(id, --g_menuPosition[id]);
}
default:
{
new player = g_menuPlayers[id][g_menuPosition[id] * 6 + key];
@ -750,7 +854,9 @@ public actionTeamMenu(id, key)
cs_set_user_team(player, destTeamSlot + 1);
} else {
}
else
{
if (is_user_alive(player) && (!g_silent[id] || destTeamSlot == 2))
{
user_kill(player, 1);
@ -774,12 +880,16 @@ public actionTeamMenu(id, key)
{
allow_spectators_setting = get_pcvar_float(allow_spectators);
if (allow_spectators_setting != 1.0)
{
set_pcvar_float(allow_spectators, 1.0);
}
}
engclient_cmd(player, "jointeam", g_CSTeamNumbers[destTeamSlot]);
if (allow_spectators && allow_spectators_setting != 1.0)
{
set_pcvar_float(allow_spectators, allow_spectators_setting);
}
}
else
{
engclient_cmd(player, "jointeam", g_CSTeamNumbers[destTeamSlot]);
@ -810,7 +920,9 @@ public actionTeamMenu(id, key)
displayTeamMenu(id, pos)
{
if (pos < 0)
{
return;
}
get_players(g_menuPlayers[id], g_menuPlayersNum[id]);
@ -821,14 +933,18 @@ displayTeamMenu(id, pos)
new start = pos * 6;
if (start >= g_menuPlayersNum[id])
{
start = pos = g_menuPosition[id] = 0;
}
new len = formatex(menuBody, charsmax(menuBody), g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "TEAM_MENU", pos + 1, (g_menuPlayersNum[id] / 6 + ((g_menuPlayersNum[id] % 6) ? 1 : 0)));
new end = start + 6;
new keys = MENU_KEY_0|MENU_KEY_7|MENU_KEY_8;
if (end > g_menuPlayersNum[id])
{
end = g_menuPlayersNum[id];
}
for (new a = start; a < end; ++a)
{
@ -851,10 +967,14 @@ displayTeamMenu(id, pos)
{
copy(team, charsmax(team), "SPE");
// iteam = 6; // oO WTF is this ?? fixed g_CSTeamiNumbers.
} else {
}
else
{
iteam = get_user_team(i, team, charsmax(team));
}
} else {
}
else
{
iteam = get_user_team(i, team, charsmax(team));
}
if (!iteam)
@ -867,18 +987,28 @@ displayTeamMenu(id, pos)
++b;
if (g_coloredMenus)
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "\d%d. %s\R%s^n\w", b, name, team);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "#. %s %s^n", name, team);
} else {
}
}
else
{
keys |= (1<<b);
if (is_user_admin(i))
{
len += formatex(menuBody[len], charsmax(menuBody) - len, g_coloredMenus ? "%d. %s \r*\y\R%s^n\w" : "%d. %s * %s^n", ++b, name, team);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, g_coloredMenus ? "%d. %s\y\R%s^n\w" : "%d. %s %s^n", ++b, name, team);
}
}
}
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n7. %L: %L", id, "TRANSF_SILENT", id, g_silent[id] ? "YES" : "NO");
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n8. %L^n", id, "TRANSF_TO", g_CSTeamNames[g_menuOption[id] % 3]);
@ -889,7 +1019,9 @@ displayTeamMenu(id, pos)
keys |= MENU_KEY_9;
}
else
{
formatex(menuBody[len], charsmax(menuBody) - len, "^n0. %L", id, pos ? "BACK" : "EXIT");
}
show_menu(id, keys, menuBody, -1, "Team Menu");
}
@ -897,7 +1029,9 @@ displayTeamMenu(id, pos)
public cmdTeamMenu(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
{
return PLUGIN_HANDLED;
}
g_menuOption[id] = 0;
@ -918,8 +1052,14 @@ public actionClcmdMenu(id, key)
g_menuOption[id] %= g_menuSelectNum[id];
displayClcmdMenu(id, g_menuPosition[id]);
}
case 8: displayClcmdMenu(id, ++g_menuPosition[id]);
case 9: displayClcmdMenu(id, --g_menuPosition[id]);
case 8:
{
displayClcmdMenu(id, ++g_menuPosition[id]);
}
case 9:
{
displayClcmdMenu(id, --g_menuPosition[id]);
}
default:
{
new player = g_menuPlayers[id][g_menuPosition[id] * 7 + key];
@ -942,16 +1082,23 @@ public actionClcmdMenu(id, key)
{
server_cmd("%s", command);
server_exec();
} else if (flags & 2)
}
else if (flags & 2)
{
client_cmd(id, "%s", command);
}
else if (flags & 4)
{
client_cmd(player, "%s", command);
}
}
if (flags & 8)
{
displayClcmdMenu(id, g_menuPosition[id]);
}
}
}
return PLUGIN_HANDLED;
}
@ -959,7 +1106,9 @@ public actionClcmdMenu(id, key)
displayClcmdMenu(id, pos)
{
if (pos < 0)
{
return;
}
get_players(g_menuPlayers[id], g_menuPlayersNum[id]);
@ -970,14 +1119,18 @@ displayClcmdMenu(id, pos)
new start = pos * 7;
if (start >= g_menuPlayersNum[id])
{
start = pos = g_menuPosition[id] = 0;
}
new len = formatex(menuBody, charsmax(menuBody), g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "CL_CMD_MENU", pos + 1, (g_menuPlayersNum[id] / 7 + ((g_menuPlayersNum[id] % 7) ? 1 : 0)));
new end = start + 7;
new keys = MENU_KEY_0|MENU_KEY_8;
if (end > g_menuPlayersNum[id])
{
end = g_menuPlayersNum[id];
}
for (new a = start; a < end; ++a)
{
@ -989,23 +1142,37 @@ displayClcmdMenu(id, pos)
++b;
if (g_coloredMenus)
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "\d%d. %s^n\w", b, name);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "#. %s^n", name);
} else {
}
}
else
{
keys |= (1<<b);
if (is_user_admin(i))
{
len += formatex(menuBody[len], charsmax(menuBody) - len, g_coloredMenus ? "%d. %s \r*^n\w" : "%d. %s *^n", ++b, name);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "%d. %s^n", ++b, name);
}
}
}
if (g_menuSelectNum[id])
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n8. %s^n", g_clcmdName[g_menuSelect[id][g_menuOption[id]]]);
}
else
{
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n8. %L^n", id, "NO_CMDS");
}
if (end != g_menuPlayersNum[id])
{
@ -1013,7 +1180,9 @@ displayClcmdMenu(id, pos)
keys |= MENU_KEY_9;
}
else
{
formatex(menuBody[len], charsmax(menuBody) - len, "^n0. %L", id, pos ? "BACK" : "EXIT");
}
show_menu(id, keys, menuBody, -1, "Client Cmds Menu");
}
@ -1021,13 +1190,19 @@ displayClcmdMenu(id, pos)
public cmdClcmdMenu(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
{
return PLUGIN_HANDLED;
}
g_menuSelectNum[id] = 0;
for (new a = 0; a < g_clcmdNum; ++a)
{
if (access(id, g_clcmdMisc[a][0]))
{
g_menuSelect[id][g_menuSelectNum[id]++] = a;
}
}
g_menuOption[id] = 0;
@ -1039,14 +1214,19 @@ public cmdClcmdMenu(id, level, cid)
load_settings(szFilename[])
{
if (!file_exists(szFilename))
{
return 0;
}
new text[256], szFlags[32], szAccess[32];
new a, pos = 0;
while (g_clcmdNum < MAX_CLCMDS && read_file(szFilename, pos++, text, charsmax(text), a))
{
if (text[0] == ';') continue;
if (text[0] == ';')
{
continue;
}
if (parse(text, g_clcmdName[g_clcmdNum], charsmax(g_clcmdName[]), g_clcmdCmd[g_clcmdNum], charsmax(g_clcmdCmd[]), szFlags, charsmax(szFlags), szAccess, charsmax(szAccess)) > 3)
{