From 5413c59bc7eb7635f755b19188b6f50bbaebbd80 Mon Sep 17 00:00:00 2001 From: Freeman-AM Date: Sat, 21 Mar 2015 13:54:39 +0100 Subject: [PATCH 1/3] 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) { From c156c220c47ca8e45badad9a5c6f71977baec450 Mon Sep 17 00:00:00 2001 From: Freeman-AM Date: Sat, 21 Mar 2015 16:14:14 +0100 Subject: [PATCH 2/3] Replace some arrays by bitfield macros --- plugins/plmenu.sma | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/plugins/plmenu.sma b/plugins/plmenu.sma index fcde9b50..4db26806 100755 --- a/plugins/plmenu.sma +++ b/plugins/plmenu.sma @@ -36,29 +36,32 @@ new g_clcmdMisc[MAX_CLCMDS][2]; new g_clcmdNum; new g_coloredMenus; -new g_cstrike = 0; -new g_fakemeta = 0, m_iMenu, m_bTeamChanged, Menu_ChooseAppearance; +new bool:g_cstrike = false; +new bool:g_fakemeta = false, m_iMenu, m_bTeamChanged, Menu_ChooseAppearance; new Array:g_bantimes; new Array:g_slapsettings; -new g_CSTeamNames[3][] = { +new const g_CSTeamNames[3][] = { "TERRORIST", "CT", "SPECTATOR" }; -new g_CSTeamNumbers[3][] = { +new const g_CSTeamNumbers[3][] = { "1", "2", "6" }; -new g_CSTeamiNumbers[3] = { +new const g_CSTeamiNumbers[3] = { 1, 2, 3 }; -new g_CSPlayerCanSwitchFromSpec[MAX_PLAYERS + 1]; +new SwitchFromSpecStatus; +#define AllowSwitchFromSpec(%1) SwitchFromSpecStatus |= 1<<(%1&31) +#define ForbidSwitchFromSpec(%1) SwitchFromSpecStatus &= ~(1<<(%1&31)) +#define CanSwitchFromSpec(%1) SwitchFromSpecStatus & 1<<(%1&31) new g_transferingAdmin; new allow_spectators, mp_limitteams; @@ -66,7 +69,10 @@ new allow_spectators, mp_limitteams; new p_amx_tempban_maxtime; new Trie:g_tempBans; -new g_silent[MAX_PLAYERS + 1]; +new SilentTransferStatus; +#define EnableSilentTransfer(%1) SilentTransferStatus |= 1<<(%1&31) +#define DisableSilentTransfer(%1) SilentTransferStatus &= ~(1<<(%1&31)) +#define HasSilentTransfer(%1) SilentTransferStatus & 1<<(%1&31) public plugin_natives() { @@ -122,11 +128,11 @@ public plugin_init() if (LibraryExists("cstrike", LibType_Library)) { - g_cstrike = 1; + g_cstrike = true; } if (LibraryExists("fakemeta", LibType_Library)) { - g_fakemeta = 1; + g_fakemeta = true; m_iMenu = 205; m_bTeamChanged = 501; Menu_ChooseAppearance = 3; @@ -757,8 +763,8 @@ public cmdKickMenu(id, level, cid) public client_putinserver(id) { - g_CSPlayerCanSwitchFromSpec[id] = false; - g_silent[id] = false; + ForbidSwitchFromSpec(id); + DisableSilentTransfer(id); } public Event_TeamInfo() @@ -766,7 +772,7 @@ public Event_TeamInfo() new id = read_data(1); if (is_user_connected(id)) { - g_CSPlayerCanSwitchFromSpec[id] = true; + AllowSwitchFromSpec(id); } } @@ -786,7 +792,7 @@ public actionTeamMenu(id, key) { case 6: { - g_silent[id] = !g_silent[id]; + HasSilentTransfer(id) ? (DisableSilentTransfer(id)) : (EnableSilentTransfer(id)); displayTeamMenu(id, g_menuPosition[id]); } case 7: @@ -843,9 +849,9 @@ public actionTeamMenu(id, key) } } - if (g_CSPlayerCanSwitchFromSpec[player] && g_cstrike && (CS_TEAM_T <= cs_get_user_team(player) <= CS_TEAM_CT)) + if (CanSwitchFromSpec(player) && g_cstrike && (CS_TEAM_T <= cs_get_user_team(player) <= CS_TEAM_CT)) { - if (is_user_alive(player) && (!g_silent[id] || destTeamSlot == 2)) + if (is_user_alive(player) && (~HasSilentTransfer(id) || destTeamSlot == 2)) { new deaths = cs_get_user_deaths(player); user_kill(player, 1); @@ -857,7 +863,7 @@ public actionTeamMenu(id, key) } else { - if (is_user_alive(player) && (!g_silent[id] || destTeamSlot == 2)) + if (is_user_alive(player) && (~HasSilentTransfer(id) || destTeamSlot == 2)) { user_kill(player, 1); } @@ -1010,7 +1016,7 @@ displayTeamMenu(id, pos) } } - 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, "^n7. %L: %L", id, "TRANSF_SILENT", id, HasSilentTransfer(id) ? "YES" : "NO"); len += formatex(menuBody[len], charsmax(menuBody) - len, "^n8. %L^n", id, "TRANSF_TO", g_CSTeamNames[g_menuOption[id] % 3]); if (end != g_menuPlayersNum[id]) From f44ec0013399d3b96ebf1e01eb927f786e72af57 Mon Sep 17 00:00:00 2001 From: Freeman-AM Date: Thu, 26 Mar 2015 21:17:46 +0100 Subject: [PATCH 3/3] Plmenu: rollback macros --- plugins/plmenu.sma | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/plugins/plmenu.sma b/plugins/plmenu.sma index 4db26806..5bd76007 100755 --- a/plugins/plmenu.sma +++ b/plugins/plmenu.sma @@ -58,10 +58,7 @@ new const g_CSTeamiNumbers[3] = { 3 }; -new SwitchFromSpecStatus; -#define AllowSwitchFromSpec(%1) SwitchFromSpecStatus |= 1<<(%1&31) -#define ForbidSwitchFromSpec(%1) SwitchFromSpecStatus &= ~(1<<(%1&31)) -#define CanSwitchFromSpec(%1) SwitchFromSpecStatus & 1<<(%1&31) +new g_CSPlayerCanSwitchFromSpec[MAX_PLAYERS + 1]; new g_transferingAdmin; new allow_spectators, mp_limitteams; @@ -69,10 +66,7 @@ new allow_spectators, mp_limitteams; new p_amx_tempban_maxtime; new Trie:g_tempBans; -new SilentTransferStatus; -#define EnableSilentTransfer(%1) SilentTransferStatus |= 1<<(%1&31) -#define DisableSilentTransfer(%1) SilentTransferStatus &= ~(1<<(%1&31)) -#define HasSilentTransfer(%1) SilentTransferStatus & 1<<(%1&31) +new g_silent[MAX_PLAYERS + 1]; public plugin_natives() { @@ -763,8 +757,8 @@ public cmdKickMenu(id, level, cid) public client_putinserver(id) { - ForbidSwitchFromSpec(id); - DisableSilentTransfer(id); + g_CSPlayerCanSwitchFromSpec[id] = false; + g_silent[id] = false; } public Event_TeamInfo() @@ -772,7 +766,7 @@ public Event_TeamInfo() new id = read_data(1); if (is_user_connected(id)) { - AllowSwitchFromSpec(id); + g_CSPlayerCanSwitchFromSpec[id] = true; } } @@ -792,7 +786,7 @@ public actionTeamMenu(id, key) { case 6: { - HasSilentTransfer(id) ? (DisableSilentTransfer(id)) : (EnableSilentTransfer(id)); + g_silent[id] = !g_silent[id]; displayTeamMenu(id, g_menuPosition[id]); } case 7: @@ -849,9 +843,9 @@ public actionTeamMenu(id, key) } } - if (CanSwitchFromSpec(player) && g_cstrike && (CS_TEAM_T <= cs_get_user_team(player) <= CS_TEAM_CT)) + if (g_CSPlayerCanSwitchFromSpec[player] && g_cstrike && (CS_TEAM_T <= cs_get_user_team(player) <= CS_TEAM_CT)) { - if (is_user_alive(player) && (~HasSilentTransfer(id) || destTeamSlot == 2)) + if (is_user_alive(player) && (!g_silent[id] || destTeamSlot == 2)) { new deaths = cs_get_user_deaths(player); user_kill(player, 1); @@ -863,7 +857,7 @@ public actionTeamMenu(id, key) } else { - if (is_user_alive(player) && (~HasSilentTransfer(id) || destTeamSlot == 2)) + if (is_user_alive(player) && (!g_silent[id] || destTeamSlot == 2)) { user_kill(player, 1); } @@ -1016,7 +1010,7 @@ displayTeamMenu(id, pos) } } - len += formatex(menuBody[len], charsmax(menuBody) - len, "^n7. %L: %L", id, "TRANSF_SILENT", id, HasSilentTransfer(id) ? "YES" : "NO"); + 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]); if (end != g_menuPlayersNum[id])