From 5413c59bc7eb7635f755b19188b6f50bbaebbd80 Mon Sep 17 00:00:00 2001 From: Freeman-AM Date: Sat, 21 Mar 2015 13:54:39 +0100 Subject: [PATCH] plmenu: improve readability, more compliance to amxmodx style --- plugins/plmenu.sma | 276 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 228 insertions(+), 48 deletions(-) diff --git a/plugins/plmenu.sma b/plugins/plmenu.sma index 672dc9e1..fcde9b50 100755 --- a/plugins/plmenu.sma +++ b/plugins/plmenu.sma @@ -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; @@ -132,7 +134,7 @@ public plugin_init() new modname[9]; get_modname(modname, charsmax(modname)); - if( equal(modname, "cstrike") || equal(modname, "czero") ) + if (equal(modname, "cstrike") || equal(modname, "czero")) { register_event("TeamInfo", "Event_TeamInfo", "a", "2=TERRORIST", "2=CT"); register_event("TextMsg", "Event_TextMsg", "b", "1=4", "2=#Only_1_Team_Change"); @@ -145,13 +147,13 @@ public plugin_init() public plugin_cfg() { new x = get_xvar_id("g_tempBans"); - if( x ) + if (x) { g_tempBans = Trie:get_xvar_num(x); } new amx_tempban_maxtime[] = "amx_tempban_maxtime"; p_amx_tempban_maxtime = get_cvar_pointer(amx_tempban_maxtime); - if( !p_amx_tempban_maxtime ) + if (!p_amx_tempban_maxtime) { p_amx_tempban_maxtime = register_cvar(amx_tempban_maxtime, "4320", FCVAR_PROTECTED); server_cmd("amx_cvar add %s", amx_tempban_maxtime); @@ -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,12 +244,18 @@ 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]; - if( ~get_user_flags(id) & ( ADMIN_BAN | ADMIN_RCON ) && (banTime <= 0 || banTime > get_pcvar_num(p_amx_tempban_maxtime)) ) + if (~get_user_flags(id) & (ADMIN_BAN | ADMIN_RCON) && (banTime <= 0 || banTime > get_pcvar_num(p_amx_tempban_maxtime))) { console_print(id, "%L", id, "NO_ACC_COM"); displayBanMenu(id, g_menuPosition[id]); @@ -261,7 +273,7 @@ public actionBanMenu(id, key) log_amx("Ban: ^"%s<%d><%s><>^" ban and kick ^"%s<%d><%s><>^" (minutes ^"%d^")", name, get_user_userid(id), authid, name2, userid2, authid2, banTime); - if ( !banTime ) // permanent + if (!banTime) // permanent { for (new i = 1; i <= MaxClients; i++) { @@ -290,7 +302,7 @@ public actionBanMenu(id, key) get_user_ip(player, ipa, charsmax(ipa), 1); server_cmd("addip %d %s;writeip", banTime, ipa); - if( g_tempBans ) + if (g_tempBans) { TrieSetString(g_tempBans, ipa, authid); } @@ -298,7 +310,7 @@ public actionBanMenu(id, key) else { server_cmd("banid %d #%d kick;writeid", banTime, userid2); - if( g_tempBans ) + if (g_tempBans) { TrieSetString(g_tempBans, authid2, authid); } @@ -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< 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< 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,16 +707,26 @@ 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<= 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,13 +967,17 @@ 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 ) + if (!iteam) { iteam = 3; // fix get_user_team returning 0 on spectators } @@ -867,16 +987,26 @@ 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<= 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< 3) {