Code: Select all
#include <amxmodx>
#include <amxmisc>
#if defined USING_SQL
#include <sqlx>
#endif
//new Vector:AdminList;
new AdminCount;
new PLUGINNAME[] = "AMX Mod X"
#define ADMIN_LOOKUP (1<<0)
#define ADMIN_NORMAL (1<<1)
#define ADMIN_STEAM (1<<2)
#define ADMIN_IPADDR (1<<3)
#define ADMIN_NAME (1<<4)
new g_cmdLoopback[16]
new bool:g_CaseSensitiveName[33];
// pcvars
new amx_mode;
new amx_password_field;
new amx_default_access;
public plugin_init()
{
#if defined USING_SQL
register_plugin("Admin Base (SQL)", AMXX_VERSION_STR, "AMXX Dev Team")
#else
register_plugin("Admin Base", AMXX_VERSION_STR, "AMXX Dev Team")
#endif
register_dictionary("admin.txt")
register_dictionary("common.txt")
amx_mode=register_cvar("amx_mode", "1")
amx_password_field=register_cvar("amx_password_field", "_pw")
amx_default_access=register_cvar("amx_default_access", "")
register_cvar("amx_vote_ratio", "0.02")
register_cvar("amx_vote_time", "10")
register_cvar("amx_vote_answers", "1")
register_cvar("amx_vote_delay", "60")
register_cvar("amx_last_voting", "0")
register_cvar("amx_show_activity", "2")
register_cvar("amx_votekick_ratio", "0.40")
register_cvar("amx_voteban_ratio", "0.40")
register_cvar("amx_votemap_ratio", "0.40")
set_cvar_float("amx_last_voting", 0.0)
#if defined USING_SQL
register_srvcmd("amx_sqladmins", "adminSql")
register_cvar("amx_sql_table", "admins")
#endif
register_cvar("amx_sql_host", "127.0.0.1")
register_cvar("amx_sql_user", "root")
register_cvar("amx_sql_pass", "")
register_cvar("amx_sql_db", "amx")
register_cvar("amx_sql_type", "mysql")
register_concmd("amx_reloadadmins", "cmdReload", ADMIN_CFG)
register_concmd("amx_addadmin", "addadminfn", ADMIN_RCON, "<playername|auth> <accessflags> [password] [authtype] - add specified player as an admin to users.ini")
format(g_cmdLoopback, 15, "amxauth%c%c%c%c", random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'))
register_clcmd(g_cmdLoopback, "ackSignal")
remove_user_flags(0, read_flags("z")) // Remove 'user' flag from server rights
new configsDir[64]
get_configsdir(configsDir, 63)
server_cmd("exec %s/amxx.cfg", configsDir) // Execute main configuration file
server_cmd("exec %s/sql.cfg", configsDir)
// Create a vector of 5 cells to store the info.
//AdminList=vector_create(5);
#if defined USING_SQL
server_cmd("amx_sqladmins")
#else
format(configsDir, 63, "%s/users.ini", configsDir)
loadSettings(configsDir) // Load admins accounts
#endif
}
public client_connect(id)
{
g_CaseSensitiveName[id] = false;
}
public addadminfn(id, level, cid)
{
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
new idtype = ADMIN_STEAM | ADMIN_LOOKUP
if (read_argc() >= 5)
{
new t_arg[16]
read_argv(4, t_arg, 15)
if (equali(t_arg, "steam") || equali(t_arg, "steamid") || equali(t_arg, "auth"))
{
idtype = ADMIN_STEAM
}
else if (equali(t_arg, "ip"))
{
idtype = ADMIN_IPADDR
}
else if (equali(t_arg, "name") || equali(t_arg, "nick"))
{
idtype = ADMIN_NAME
if (equali(t_arg, "name"))
idtype |= ADMIN_LOOKUP
} else {
console_print(id, "[%s] Unknown id type ^"%s^", use one of: steamid, ip, name", PLUGINNAME, t_arg)
return PLUGIN_HANDLED
}
}
new arg[33]
read_argv(1, arg, 32)
new player = -1
if (idtype & ADMIN_STEAM)
{
if (containi(arg, "STEAM_0:") == -1)
{
idtype |= ADMIN_LOOKUP
player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS)
} else {
new _steamid[44]
static _players[32], _num, _pv
get_players(_players, _num)
for (new _i=0; _i<_num; _i++)
{
_pv = _players[_i]
get_user_authid(_pv, _steamid, sizeof(_steamid)-1)
if (!_steamid[0])
continue
if (equal(_steamid, arg))
{
player = _pv
break
}
}
if (player < 1)
{
idtype &= ~ADMIN_LOOKUP
}
}
}
else if (idtype & ADMIN_NAME)
{
player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS)
if (player)
idtype |= ADMIN_LOOKUP
else
idtype &= ~ADMIN_LOOKUP
}
else if (idtype & ADMIN_IPADDR)
{
new len = strlen(arg)
new dots, chars
for (new i = 0; i < len; i++)
{
if (arg[i] == '.')
{
if (!chars || chars > 3)
break
if (++dots > 3)
break
chars = 0
} else {
chars++
}
if (dots != 3 || !chars || chars > 3)
{
idtype |= ADMIN_LOOKUP
player = find_player("dh", arg)
}
}
}
if (idtype & ADMIN_LOOKUP && !player)
{
console_print(id, "%L", id, "CL_NOT_FOUND")
return PLUGIN_HANDLED
}
new flags[64]
read_argv(2, flags, 63)
new password[64]
if (read_argc() >= 4)
read_argv(3, password, 63)
new auth[33]
new Comment[33]; // name of player to pass to comment field
if (idtype & ADMIN_LOOKUP)
{
get_user_name(player, Comment, sizeof(Comment)-1)
if (idtype & ADMIN_STEAM)
{
get_user_authid(player, auth, 32)
}
else if (idtype & ADMIN_IPADDR)
{
get_user_ip(player, auth, 32)
}
else if (idtype & ADMIN_NAME)
{
get_user_name(player, auth, 32)
}
} else {
copy(auth, 32, arg)
}
new type[16], len
if (idtype & ADMIN_STEAM)
len += format(type[len], 15-len, "c")
else if (idtype & ADMIN_IPADDR)
len += format(type[len], 15-len, "d")
if (strlen(password) > 0)
len += format(type[len], 15-len, "a")
else
len += format(type[len], 15-len, "e")
AddAdmin(id, auth, flags, password, type, Comment)
cmdReload(id, ADMIN_CFG, 0)
if (player > 0)
{
new name[32]
get_user_info(player, "name", name, 31)
accessUser(player, name)
}
return PLUGIN_HANDLED
}
AddAdmin(id, auth[], accessflags[], password[], flags[], comment[]="")
{
#if defined USING_SQL
new error[128], errno
new Handle:info = SQL_MakeStdTuple()
new Handle:sql = SQL_Connect(info, errno, error, 127)
if (sql == Empty_Handle)
{
server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_CON", error)
//backup to users.ini
#endif
// Make sure that the users.ini file exists.
new configsDir[64]
get_configsdir(configsDir, 63)
format(configsDir, 63, "%s/users.ini", configsDir)
if (!file_exists(configsDir))
{
console_print(id, "[%s] File ^"%s^" doesn't exist.", PLUGINNAME, configsDir)
return
}
// Make sure steamid isn't already in file.
new line = 0, textline[256], len
const SIZE = 63
new line_steamid[SIZE + 1], line_password[SIZE + 1], line_accessflags[SIZE + 1], line_flags[SIZE + 1], parsedParams
// <name|ip|steamid> <password> <access flags> <account flags>
while ((line = read_file(configsDir, line, textline, 255, len)))
{
if (len == 0 || equal(textline, ";", 1))
continue // comment line
parsedParams = parse(textline, line_steamid, SIZE, line_password, SIZE, line_accessflags, SIZE, line_flags, SIZE)
if (parsedParams != 4)
continue // Send warning/error?
if (containi(line_flags, flags) != -1 && equal(line_steamid, auth))
{
console_print(id, "[%s] %s already exists!", PLUGINNAME, auth)
return
}
}
// If we came here, steamid doesn't exist in users.ini. Add it.
new linetoadd[512]
if (comment[0]==0)
{
formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags)
}
else
{
formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^" ; %s", auth, password, accessflags, flags, comment)
}
console_print(id, "Adding:^n%s", linetoadd)
if (!write_file(configsDir, linetoadd))
console_print(id, "[%s] Failed writing to %s!", PLUGINNAME, configsDir)
#if defined USING_SQL
}
new table[32]
get_cvar_string("amx_sql_table", table, 31)
new Handle:query = SQL_PrepareQuery(sql, "SELECT * FROM `%s` WHERE (`auth` = '%s')", table, auth)
if (!SQL_Execute(query))
{
SQL_QueryError(query, error, 127)
server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error)
console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error)
} else if (SQL_NumResults(query)) {
console_print(id, "[%s] %s already exists!", PLUGINNAME, auth)
} else {
console_print(id, "Adding to database:^n^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags)
SQL_QueryAndIgnore(sql, "REPLACE INTO `%s` (`auth`, `password`, `access`, `flags`) VALUES ('%s', '%s', '%s', '%s')", table, auth, password, accessflags, flags)
}
SQL_FreeHandle(query)
SQL_FreeHandle(sql)
SQL_FreeHandle(info)
#endif
}
public plugin_cfg()
{
set_task(6.1, "delayed_load")
}
public delayed_load()
{
new configFile[128], curMap[64], configDir[128]
get_configsdir(configDir, sizeof(configDir)-1)
get_mapname(curMap, sizeof(curMap)-1)
new i=0;
while (curMap[i] != '_' && curMap[i++] != '^0') {/*do nothing*/}
if (curMap[i]=='_')
{
// this map has a prefix
curMap[i]='^0';
formatex(configFile, sizeof(configFile)-1, "%s/maps/prefix_%s.cfg", configDir, curMap);
if (file_exists(configFile))
{
server_cmd("exec %s", configFile);
}
}
get_mapname(curMap, sizeof(curMap)-1)
formatex(configFile, sizeof(configFile)-1, "%s/maps/%s.cfg", configDir, curMap)
if (file_exists(configFile))
{
server_cmd("exec %s", configFile)
}
}
loadSettings(szFilename[])
{
new File=fopen(szFilename,"r");
if (File)
{
new Text[512];
new Flags[32];
new Access[32]
new AuthData[44];
new Password[32];
while (!feof(File))
{
fgets(File,Text,sizeof(Text)-1);
trim(Text);
// comment
if (Text[0]==';')
{
continue;
}
Flags[0]=0;
Access[0]=0;
AuthData[0]=0;
Password[0]=0;
// not enough parameters
if (parse(Text,AuthData,sizeof(AuthData)-1,Password,sizeof(Password)-1,Access,sizeof(Access)-1,Flags,sizeof(Flags)-1) < 2)
{
continue;
}
admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));
AdminCount++;
}
fclose(File);
}
if (AdminCount == 1)
{
server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMIN");
}
else
{
server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", AdminCount);
}
return 1;
}
#if defined USING_SQL
public adminSql()
{
new table[32], error[128], type[12], errno
new Handle:info = SQL_MakeStdTuple()
new Handle:sql = SQL_Connect(info, errno, error, 127)
get_cvar_string("amx_sql_table", table, 31)
SQL_GetAffinity(type, 11)
if (sql == Empty_Handle)
{
server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_CON", error)
//backup to users.ini
new configsDir[64]
get_configsdir(configsDir, 63)
format(configsDir, 63, "%s/users.ini", configsDir)
loadSettings(configsDir) // Load admins accounts
return PLUGIN_HANDLED
}
new Handle:query
if (equali(type, "sqlite"))
{
if (!sqlite_TableExists(sql, table))
{
SQL_QueryAndIgnore(sql, "CREATE TABLE %s ( auth TEXT NOT NULL DEFAULT '', password TEXT NOT NULL DEFAULT '', access TEXT NOT NULL DEFAULT '', flags TEXT NOT NULL DEFAULT '' )", table)
}
query = SQL_PrepareQuery(sql, "SELECT auth, password, access, flags FROM %s", table)
} else {
SQL_QueryAndIgnore(sql, "CREATE TABLE IF NOT EXISTS `%s` ( `auth` VARCHAR( 32 ) NOT NULL, `password` VARCHAR( 32 ) NOT NULL, `access` VARCHAR( 32 ) NOT NULL, `flags` VARCHAR( 32 ) NOT NULL ) COMMENT = 'AMX Mod X Admins'", table)
query = SQL_PrepareQuery(sql,"SELECT `auth`,`password`,`access`,`flags` FROM `%s`", table)
}
if (!SQL_Execute(query))
{
SQL_QueryError(query, error, 127)
server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error)
} else if (!SQL_NumResults(query)) {
server_print("[AMXX] %L", LANG_SERVER, "NO_ADMINS")
} else {
AdminCount = 0
/** do this incase people change the query order and forget to modify below */
new qcolAuth = SQL_FieldNameToNum(query, "auth")
new qcolPass = SQL_FieldNameToNum(query, "password")
new qcolAccess = SQL_FieldNameToNum(query, "access")
new qcolFlags = SQL_FieldNameToNum(query, "flags")
new AuthData[44];
new Password[44];
new Access[32];
new Flags[32];
while (SQL_MoreResults(query))
{
SQL_ReadResult(query, qcolAuth, AuthData, sizeof(AuthData)-1);
SQL_ReadResult(query, qcolPass, Password, sizeof(Password)-1);
SQL_ReadResult(query, qcolAccess, Access, sizeof(Access)-1);
SQL_ReadResult(query, qcolFlags, Flags, sizeof(Flags)-1);
admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));
++AdminCount;
SQL_NextRow(query)
}
if (AdminCount == 1)
{
server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")
}
else
{
server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", AdminCount)
}
SQL_FreeHandle(query)
SQL_FreeHandle(sql)
SQL_FreeHandle(info)
}
return PLUGIN_HANDLED
}
#endif
public cmdReload(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
//strip original flags (patch submitted by mrhunt)
remove_user_flags(0, read_flags("z"))
admins_flush();
#if !defined USING_SQL
new filename[128]
get_configsdir(filename, 127)
format(filename, 63, "%s/users.ini", filename)
AdminCount = 0;
loadSettings(filename); // Re-Load admins accounts
if (id != 0)
{
if (AdminCount == 1)
{
console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMIN");
}
else
{
console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", AdminCount);
}
}
#else
AdminCount = 0
adminSql()
if (id != 0)
{
if (AdminCount == 1)
console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")
else
console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", AdminCount)
}
#endif
new players[32], num, pv
new name[32]
get_players(players, num)
for (new i=0; i<num; i++)
{
pv = players[i]
get_user_name(pv, name, 31)
accessUser(pv, name)
}
return PLUGIN_HANDLED
}
getAccess(id, name[], authid[], ip[], password[])
{
new index = -1
new result = 0
static Count;
static Flags;
static Access;
static AuthData[44];
static Password[32];
g_CaseSensitiveName[id] = false;
Count=admins_num();
for (new i = 0; i < Count; ++i)
{
Flags=admins_lookup(i,AdminProp_Flags);
admins_lookup(i,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
if (Flags & FLAG_AUTHID)
{
if (equal(authid, AuthData))
{
index = i
break
}
}
else if (Flags & FLAG_IP)
{
new c = strlen(AuthData)
if (AuthData[c - 1] == '.') /* check if this is not a xxx.xxx. format */
{
if (equal(AuthData, ip, c))
{
index = i
break
}
} /* in other case an IP must just match */
else if (equal(ip, AuthData))
{
index = i
break
}
}
else
{
if (Flags & FLAG_CASE_SENSITIVE)
{
if (Flags & FLAG_TAG)
{
if (contain(name, AuthData) != -1)
{
index = i
g_CaseSensitiveName[id] = true
break
}
}
else if (equal(name, AuthData))
{
index = i
g_CaseSensitiveName[id] = true
break
}
}
else
{
if (Flags & FLAG_TAG)
{
if (containi(name, AuthData) != -1)
{
index = i
break
}
}
else if (equali(name, AuthData))
{
index = i
break
}
}
}
}
if (index != -1)
{
Access=admins_lookup(index,AdminProp_Access);
if (Flags & FLAG_NOPASS)
{
result |= 8
new sflags[32]
get_flags(Access, sflags, 31)
set_user_flags(id, Access)
log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, sflags, ip)
}
else
{
admins_lookup(index,AdminProp_Password,Password,sizeof(Password)-1);
if (equal(password, Password))
{
result |= 12
set_user_flags(id, Access)
new sflags[32]
get_flags(Access, sflags, 31)
log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, sflags, ip)
}
else
{
result |= 1
if (Flags & FLAG_KICK)
{
result |= 2
log_amx("Login: ^"%s<%d><%s><>^" kicked due to invalid password (account ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, ip)
}
}
}
}
else if (get_pcvar_float(amx_mode) == 2.0)
{
result |= 2
}
else
{
new defaccess[32]
get_pcvar_string(amx_default_access, defaccess, 31)
if (!strlen(defaccess))
{
copy(defaccess, 32, "z")
}
new idefaccess = read_flags(defaccess)
if (idefaccess)
{
result |= 8
set_user_flags(id, idefaccess)
}
}
return result
}
accessUser(id, name[] = "")
{
remove_user_flags(id)
new userip[32], userauthid[32], password[32], passfield[32], username[32]
get_user_ip(id, userip, 31, 1)
get_user_authid(id, userauthid, 31)
if (name[0])
{
copy(username, 31, name)
}
else
{
get_user_name(id, username, 31)
}
get_pcvar_string(amx_password_field, passfield, 31)
get_user_info(id, passfield, password, 31)
new result = getAccess(id, username, userauthid, userip, password)
if (result & 1)
{
client_cmd(id, "echo ^"* %L^"", id, "INV_PAS")
}
if (result & 2)
{
client_cmd(id, "%s", g_cmdLoopback)
return PLUGIN_HANDLED
}
if (result & 4)
{
client_cmd(id, "echo ^"* %L^"", id, "PAS_ACC")
}
if (result & 8)
{
client_cmd(id, "echo ^"* %L^"", id, "PRIV_SET")
}
return PLUGIN_CONTINUE
}
public client_infochanged(id)
{
if (!is_user_connected(id) || !get_pcvar_num(amx_mode))
{
return PLUGIN_CONTINUE
}
new newname[32], oldname[32]
get_user_name(id, oldname, 31)
get_user_info(id, "name", newname, 31)
if (g_CaseSensitiveName[id])
{
if (!equal(newname, oldname))
{
accessUser(id, newname)
}
}
else
{
if (!equali(newname, oldname))
{
accessUser(id, newname)
}
}
return PLUGIN_CONTINUE
}
public ackSignal(id)
{
server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "NO_ENTRY")
return PLUGIN_HANDLED
}
public client_authorized(id)
return get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE
public client_putinserver(id)
{
if (!is_dedicated_server() && id == 1)
return get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE
return PLUGIN_CONTINUE
}
Code: Select all
#include <amxmodx>
#include <amxmisc>
new g_msgChannel
#define MAX_CLR 10
new g_Colors[MAX_CLR][] = {"COL_WHITE", "COL_RED", "COL_GREEN", "COL_BLUE", "COL_YELLOW", "COL_MAGENTA", "COL_CYAN", "COL_ORANGE", "COL_OCEAN", "COL_MAROON"}
new g_Values[MAX_CLR][] = {{255, 255, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 0}, {255, 0, 255}, {0, 255, 255}, {227, 96, 8}, {45, 89, 116}, {103, 44, 38}}
new Float:g_Pos[4][] = {{0.0, 0.0}, {0.05, 0.55}, {-1.0, 0.2}, {-1.0, 0.7}}
new amx_show_activity;
new g_AdminChatFlag = ADMIN_CHAT;
public plugin_init()
{
new admin_chat_id
register_plugin("Admin Chat", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("adminchat.txt")
register_dictionary("common.txt")
register_clcmd("say", "cmdSayChat", ADMIN_CHAT, "@[@|@|@][w|r|g|b|y|m|c]<text> - displays hud message")
register_clcmd("say_team", "cmdSayAdmin", 0, "@<text> - displays message to admins")
register_concmd("amx_say", "cmdSay", ADMIN_CHAT, "<message> - sends message to all players")
admin_chat_id = register_concmd("amx_chat", "cmdChat", ADMIN_CHAT, "<message> - sends message to admins")
register_concmd("amx_psay", "cmdPsay", ADMIN_CHAT, "<name or #userid> <message> - sends private message")
register_concmd("amx_tsay", "cmdTsay", ADMIN_CHAT, "<color> <message> - sends left side hud message to all players")
register_concmd("amx_csay", "cmdTsay", ADMIN_CHAT, "<color> <message> - sends center hud message to all players")
amx_show_activity = get_cvar_pointer("amx_show_activity");
if (amx_show_activity == 0)
{
amx_show_activity = register_cvar("amx_show_activity", "2");
}
new str[1]
get_concmd(admin_chat_id, str, 0, g_AdminChatFlag, str, 0, -1)
}
public cmdSayChat(id)
{
if (!access(id, g_AdminChatFlag))
{
return PLUGIN_CONTINUE
}
new said[6], i = 0
read_argv(1, said, 5)
while (said[i] == '@')
{
i++
}
if (!i || i > 3)
{
return PLUGIN_CONTINUE
}
new message[192], a = 0
read_args(message, 191)
remove_quotes(message)
switch (said[i])
{
case 'r': a = 1
case 'g': a = 2
case 'b': a = 3
case 'y': a = 4
case 'm': a = 5
case 'c': a = 6
case 'o': a = 7
}
new n, s = i
if (a)
{
n++
s++
}
while (said[s] && isspace(said[s]))
{
n++
s++
}
new name[32], authid[32], userid
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
userid = get_user_userid(id)
log_amx("Chat: ^"%s<%d><%s><>^" tsay ^"%s^"", name, userid, authid, message[i + n])
log_message("^"%s<%d><%s><>^" triggered ^"amx_tsay^" (text ^"%s^") (color ^"%L^")", name, userid, authid, message[i + n], "en", g_Colors[a])
if (++g_msgChannel > 6 || g_msgChannel < 3)
{
g_msgChannel = 3
}
new Float:verpos = g_Pos[i][1] + float(g_msgChannel) / 35.0
set_hudmessage(g_Values[a][0], g_Values[a][1], g_Values[a][2], g_Pos[i][0], verpos, 0, 6.0, 6.0, 0.5, 0.15, -1)
switch ( get_pcvar_num(amx_show_activity) )
{
case 3, 4:
{
new maxpl = get_maxplayers();
for (new pl = 1; pl <= maxpl; pl++)
{
if (is_user_connected(pl) && !is_user_bot(pl))
{
if (is_user_admin(pl))
{
show_hudmessage(pl, "%s : %s", name, message[i + n])
client_print(pl, print_notify, "%s : %s", name, message[i + n])
}
else
{
show_hudmessage(pl, "%s", message[i + n])
client_print(pl, print_notify, "%s", message[i + n])
}
}
}
}
case 2:
{
show_hudmessage(0, "%s : %s", name, message[i + n])
client_print(0, print_notify, "%s : %s", name, message[i + n])
}
default:
{
show_hudmessage(0, "%s", message[i + n])
client_print(0, print_notify, "%s", message[i + n])
}
}
return PLUGIN_HANDLED
}
public cmdSayAdmin(id)
{
new said[2]
read_argv(1, said, 1)
if (said[0] != '@')
return PLUGIN_CONTINUE
new message[192], name[32], authid[32], userid
new players[32], inum
read_args(message, 191)
remove_quotes(message)
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
userid = get_user_userid(id)
log_amx("Chat: ^"%s<%d><%s><>^" chat ^"%s^"", name, userid, authid, message[1])
log_message("^"%s<%d><%s><>^" triggered ^"amx_chat^" (text ^"%s^")", name, userid, authid, message[1])
if (is_user_admin(id))
format(message, 191, "(%L) %s : %s", id, "ADMIN", name, message[1])
else
format(message, 191, "(%L) %s : %s", id, "PLAYER", name, message[1])
get_players(players, inum)
for (new i = 0; i < inum; ++i)
{
// dont print the message to the client that used the cmd if he has ADMIN_CHAT to avoid double printing
if (players[i] != id && get_user_flags(players[i]) & g_AdminChatFlag)
client_print(players[i], print_chat, "%s", message)
}
client_print(id, print_chat, "%s", message)
return PLUGIN_HANDLED
}
public cmdChat(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new message[192], name[32], players[32], inum, authid[32], userid
read_args(message, 191)
remove_quotes(message)
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
userid = get_user_userid(id)
get_players(players, inum)
log_amx("Chat: ^"%s<%d><%s><>^" chat ^"%s^"", name, userid, authid, message)
log_message("^"%s<%d><%s><>^" triggered ^"amx_chat^" (text ^"%s^")", name, userid, authid, message)
format(message, 191, "(ADMINS) %s : %s", name, message)
console_print(id, "%s", message)
for (new i = 0; i < inum; ++i)
{
if (access(players[i], g_AdminChatFlag))
client_print(players[i], print_chat, "%s", message)
}
return PLUGIN_HANDLED
}
public cmdSay(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new message[192], name[32], authid[32], userid
read_args(message, 191)
remove_quotes(message)
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
userid = get_user_userid(id)
client_print(0, print_chat, "%L", LANG_PLAYER, "PRINT_ALL", name, message)
console_print(id, "%L", LANG_PLAYER, "PRINT_ALL", name, message)
log_amx("Chat: ^"%s<%d><%s><>^" say ^"%s^"", name, userid, authid, message)
log_message("^"%s<%d><%s><>^" triggered ^"amx_say^" (text ^"%s^")", name, userid, authid, message)
return PLUGIN_HANDLED
}
public cmdPsay(id, level, cid)
{
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
new name[32]
read_argv(1, name, 31)
new priv = cmd_target(id, name, 0)
if (!priv)
return PLUGIN_HANDLED
new length = strlen(name) + 1
get_user_name(priv, name, 31);
new message[192], name2[32], authid[32], authid2[32], userid, userid2
get_user_authid(id, authid, 31)
get_user_name(id, name2, 31)
userid = get_user_userid(id)
read_args(message, 191)
if (message[0] == '"' && message[length] == '"') // HLSW fix
{
message[0] = ' '
message[length] = ' '
length += 2
}
remove_quotes(message[length])
get_user_name(priv, name, 31)
if (id && id != priv)
client_print(id, print_chat, "(%s) %s : %s", name, name2, message[length])
client_print(priv, print_chat, "(%s) %s : %s", name, name2, message[length])
console_print(id, "(%s) %s : %s", name, name2, message[length])
get_user_authid(priv, authid2, 31)
userid2 = get_user_userid(priv)
log_amx("Chat: ^"%s<%d><%s><>^" psay ^"%s<%d><%s><>^" ^"%s^"", name2, userid, authid, name, userid2, authid2, message[length])
log_message("^"%s<%d><%s><>^" triggered ^"amx_psay^" against ^"%s<%d><%s><>^" (text ^"%s^")", name2, userid, authid, name, userid2, authid2, message[length])
return PLUGIN_HANDLED
}
public cmdTsay(id, level, cid)
{
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
new cmd[16], color[16], color2[16], message[192], name[32], authid[32], userid = 0
read_argv(0, cmd, 15)
new bool:tsay = (tolower(cmd[4]) == 't')
read_args(message, 191)
remove_quotes(message)
parse(message, color, 15)
new found = 0, a = 0
new lang[3], langnum = get_langsnum()
for (new i = 0; i < MAX_CLR; ++i)
{
for (new j = 0; j < langnum; j++)
{
get_lang(j, lang)
format(color2, 15, "%L", lang, g_Colors[i])
if (equali(color, color2))
{
a = i
found = 1
break
}
}
if (found == 1)
break
}
new length = found ? (strlen(color) + 1) : 0
if (++g_msgChannel > 6 || g_msgChannel < 3)
g_msgChannel = 3
new Float:verpos = (tsay ? 0.55 : 0.1) + float(g_msgChannel) / 35.0
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
userid = get_user_userid(id)
set_hudmessage(g_Values[a][0], g_Values[a][1], g_Values[a][2], tsay ? 0.05 : -1.0, verpos, 0, 6.0, 6.0, 0.5, 0.15, -1)
switch ( get_pcvar_num(amx_show_activity) )
{
case 3, 4:
{
new maxpl = get_maxplayers();
for (new pl = 1; pl <= maxpl; pl++)
{
if (is_user_connected(pl) && !is_user_bot(pl))
{
if (is_user_admin(pl))
{
show_hudmessage(pl, "%s : %s", name, message[length])
client_print(pl, print_notify, "%s : %s", name, message[length])
}
else
{
show_hudmessage(pl, "%s", message[length])
client_print(pl, print_notify, "%s", message[length])
}
}
}
console_print(id, "%s : %s", name, message[length])
}
case 2:
{
show_hudmessage(0, "%s : %s", name, message[length])
client_print(0, print_notify, "%s : %s", name, message[length])
console_print(id, "%s : %s", name, message[length])
}
default:
{
show_hudmessage(0, "%s", message[length])
client_print(0, print_notify, "%s", message[length])
console_print(id, "%s", message[length])
}
}
log_amx("Chat: ^"%s<%d><%s><>^" %s ^"%s^"", name, userid, authid, cmd[4], message[length])
log_message("^"%s<%d><%s><>^" triggered ^"%s^" (text ^"%s^") (color ^"%s^")", name, userid, authid, cmd, message[length], color2)
return PLUGIN_HANDLED
}
Code: Select all
#include <amxmodx>
#include <amxmisc>
// This is not a dynamic array because it would be bad for 24/7 map servers.
#define OLD_CONNECTION_QUEUE 10
new g_pauseCon
new Float:g_pausAble
new bool:g_Paused
new bool:g_PauseAllowed = false
new g_addCvar[] = "amx_cvar add %s"
new pausable;
new rcon_password;
// Old connection queue
new g_Names[OLD_CONNECTION_QUEUE][32];
new g_SteamIDs[OLD_CONNECTION_QUEUE][32];
new g_IPs[OLD_CONNECTION_QUEUE][32];
new g_Access[OLD_CONNECTION_QUEUE];
new g_Tracker;
new g_Size;
stock InsertInfo(id)
{
// Scan to see if this entry is the last entry in the list
// If it is, then update the name and access
// If it is not, then insert it again.
if (g_Size > 0)
{
new ip[32]
new auth[32];
get_user_authid(id, auth, charsmax(auth));
get_user_ip(id, ip, charsmax(ip), 1/*no port*/);
new last = 0;
if (g_Size < sizeof(g_SteamIDs))
{
last = g_Size - 1;
}
else
{
last = g_Tracker - 1;
if (last < 0)
{
last = g_Size - 1;
}
}
if (equal(auth, g_SteamIDs[last]) &&
equal(ip, g_IPs[last])) // need to check ip too, or all the nosteams will while it doesn't work with their illegitimate server
{
get_user_name(id, g_Names[last], charsmax(g_Names[]));
g_Access[last] = get_user_flags(id);
return;
}
}
// Need to insert the entry
new target = 0; // the slot to save the info at
// Queue is not yet full
if (g_Size < sizeof(g_SteamIDs))
{
target = g_Size;
++g_Size;
}
else
{
target = g_Tracker;
++g_Tracker;
// If we reached the end of the array, then move to the front
if (g_Tracker == sizeof(g_SteamIDs))
{
g_Tracker = 0;
}
}
get_user_authid(id, g_SteamIDs[target], charsmax(g_SteamIDs[]));
get_user_name(id, g_Names[target], charsmax(g_Names[]));
get_user_ip(id, g_IPs[target], charsmax(g_IPs[]), 1/*no port*/);
g_Access[target] = get_user_flags(id);
}
stock GetInfo(i, name[], namesize, auth[], authsize, ip[], ipsize, &access)
{
if (i >= g_Size)
{
abort(AMX_ERR_NATIVE, "GetInfo: Out of bounds (%d:%d)", i, g_Size);
}
new target = (g_Tracker + i) % sizeof(g_SteamIDs);
copy(name, namesize, g_Names[target]);
copy(auth, authsize, g_SteamIDs[target]);
copy(ip, ipsize, g_IPs[target]);
access = g_Access[target];
}
public client_disconnect(id)
{
if (!is_user_bot(id))
{
InsertInfo(id);
}
}
public plugin_init()
{
register_plugin("Admin Commands", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("admincmd.txt")
register_dictionary("common.txt")
register_dictionary("adminhelp.txt")
register_concmd("amx_kick", "cmdKick", ADMIN_KICK, "<name or #userid> [reason]")
register_concmd("amx_ban", "cmdBan", ADMIN_BAN, "<name or #userid> <minutes> [reason]")
register_concmd("amx_banip", "cmdBanIP", ADMIN_BAN, "<name or #userid> <minutes> [reason]")
register_concmd("amx_addban", "cmdAddBan", ADMIN_BAN, "<^"authid^" or ip> <minutes> [reason]")
register_concmd("amx_unban", "cmdUnban", ADMIN_BAN, "<^"authid^" or ip>")
register_concmd("amx_slay", "cmdSlay", ADMIN_SLAY, "<name or #userid>")
register_concmd("amx_slap", "cmdSlap", ADMIN_SLAY, "<name or #userid> [power]")
register_concmd("amx_leave", "cmdLeave", ADMIN_KICK, "<tag> [tag] [tag] [tag]")
register_concmd("amx_pause", "cmdPause", ADMIN_CVAR, "- pause or unpause the game")
register_concmd("amx_who", "cmdWho", ADMIN_ADMIN, "- displays who is on server")
register_concmd("amx_cvar", "cmdCvar", ADMIN_CVAR, "<cvar> [value]")
register_concmd("amx_plugins", "cmdPlugins", ADMIN_ADMIN)
register_concmd("amx_modules", "cmdModules", ADMIN_ADMIN)
register_concmd("amx_map", "cmdMap", ADMIN_MAP, "<mapname>")
register_concmd("amx_cfg", "cmdCfg", ADMIN_CFG, "<filename>")
register_concmd("amx_nick", "cmdNick", ADMIN_SLAY, "<name or #userid> <new nick>")
register_concmd("amx_last", "cmdLast", ADMIN_BAN, "- list the last few disconnected clients info");
register_clcmd("amx_rcon", "cmdRcon", ADMIN_RCON, "<command line>")
register_clcmd("amx_showrcon", "cmdShowRcon", ADMIN_RCON, "<command line>")
register_clcmd("pauseAck", "cmdLBack")
rcon_password=get_cvar_pointer("rcon_password");
pausable=get_cvar_pointer("pausable");
}
public plugin_cfg()
{
// Cvars which can be changed only with rcon access
server_cmd(g_addCvar, "rcon_password")
server_cmd(g_addCvar, "amx_show_activity")
server_cmd(g_addCvar, "amx_mode")
server_cmd(g_addCvar, "amx_password_field")
server_cmd(g_addCvar, "amx_default_access")
server_cmd(g_addCvar, "amx_reserved_slots")
server_cmd(g_addCvar, "amx_reservation")
server_cmd(g_addCvar, "amx_sql_table");
server_cmd(g_addCvar, "amx_sql_host");
server_cmd(g_addCvar, "amx_sql_user");
server_cmd(g_addCvar, "amx_sql_pass");
server_cmd(g_addCvar, "amx_sql_db");
server_cmd(g_addCvar, "amx_sql_type");
}
public cmdKick(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32]
read_argv(1, arg, 31)
new player = cmd_target(id, arg, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF)
if (!player)
return PLUGIN_HANDLED
new authid[32], authid2[32], name2[32], name[32], userid2, reason[32]
get_user_authid(id, authid, 31)
get_user_authid(player, authid2, 31)
get_user_name(player, name2, 31)
get_user_name(id, name, 31)
userid2 = get_user_userid(player)
read_argv(2, reason, 31)
remove_quotes(reason)
log_amx("Kick: ^"%s<%d><%s><>^" kick ^"%s<%d><%s><>^" (reason ^"%s^")", name, get_user_userid(id), authid, name2, userid2, authid2, reason)
show_activity_key("ADMIN_KICK_1", "ADMIN_KICK_2", name, name2);
if (is_user_bot(player))
server_cmd("kick #%d", userid2)
else
{
if (reason[0])
server_cmd("kick #%d ^"%s^"", userid2, reason)
else
server_cmd("kick #%d", userid2)
}
console_print(id, "[AMXX] Client ^"%s^" kicked", name2)
return PLUGIN_HANDLED
}
public cmdUnban(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32], authid[32], name[32]
read_argv(1, arg, 31)
if (contain(arg, ".") != -1)
{
server_cmd("removeip ^"%s^";writeip", arg)
console_print(id, "[AMXX] %L", id, "IP_REMOVED", arg)
} else {
server_cmd("removeid %s;writeid", arg)
console_print(id, "[AMXX] %L", id, "AUTHID_REMOVED", arg)
}
get_user_name(id, name, 31)
show_activity_key("ADMIN_UNBAN_1", "ADMIN_UNBAN_2", name, arg);
get_user_authid(id, authid, 31)
log_amx("Cmd: ^"%s<%d><%s><>^" unban ^"%s^"", name, get_user_userid(id), authid, arg)
return PLUGIN_HANDLED
}
/* amx_addban is a special command now.
* If a user with rcon uses it, it bans the user. No questions asked.
* If a user without rcon but with ADMIN_BAN uses it, it will scan the old
* connection queue, and if it finds the info for a player in it, it will
* check their old access. If they have immunity, it will not ban.
* If they do not have immunity, it will ban. If the user is not found,
* it will refuse to ban the target.
*/
public cmdAddBan(id, level, cid)
{
if (!cmd_access(id, level, cid, 3, true)) // check for ADMIN_BAN access
{
if (get_user_flags(id) & level) // Getting here means they didn't input enough args
{
return PLUGIN_HANDLED;
}
if (!cmd_access(id, ADMIN_RCON, cid, 3)) // If somehow they have ADMIN_RCON without ADMIN_BAN, continue
{
return PLUGIN_HANDLED;
}
}
new arg[32], authid[32], name[32], minutes[32], reason[32]
read_argv(1, arg, 31)
read_argv(2, minutes, 31)
read_argv(3, reason, 31)
if (!(get_user_flags(id) & ADMIN_RCON))
{
new bool:canban = false;
new bool:isip = false;
// Limited access to this command
if (equali(arg, "STEAM_ID_PENDING") ||
equali(arg, "STEAM_ID_LAN") ||
equali(arg, "HLTV") ||
equali(arg, "4294967295") ||
equali(arg, "VALVE_ID_LAN") ||
equali(arg, "VALVE_ID_PENDING"))
{
// Hopefully we never get here, so ML shouldn't be needed
console_print(id, "Cannot ban %s", arg);
return PLUGIN_HANDLED;
}
if (contain(arg, ".") != -1)
{
isip = true;
}
// Scan the disconnection queue
if (isip)
{
new IP[32];
new Name[32];
new dummy[1];
new Access;
for (new i = 0; i < g_Size; i++)
{
GetInfo(i, Name, charsmax(Name), dummy, 0, IP, charsmax(IP), Access);
if (equal(IP, arg))
{
if (Access & ADMIN_IMMUNITY)
{
console_print(id, "[AMXX] %s : %L", IP, id, "CLIENT_IMM", Name);
return PLUGIN_HANDLED;
}
// User did not have immunity
canban = true;
}
}
}
else
{
new Auth[32];
new Name[32];
new dummy[1];
new Access;
for (new i = 0; i < g_Size; i++)
{
GetInfo(i, Name, charsmax(Name), Auth, charsmax(Auth), dummy, 0, Access);
if (equal(Auth, arg))
{
if (Access & ADMIN_IMMUNITY)
{
console_print(id, "[AMXX] %s : %L", Auth, id, "CLIENT_IMM", Name);
return PLUGIN_HANDLED;
}
// User did not have immunity
canban = true;
}
}
}
if (!canban)
{
console_print(id, "[AMXX] You may only ban recently disconnected clients. Use ^"amx_last^" to view.");
return PLUGIN_HANDLED;
}
}
// User has access to ban their target
if (contain(arg, ".") != -1)
{
server_cmd("addip ^"%s^" ^"%s^";wait;writeip", minutes, arg)
console_print(id, "[AMXX] Ip ^"%s^" added to ban list", arg)
} else {
server_cmd("banid ^"%s^" ^"%s^";wait;writeid", minutes, arg)
console_print(id, "[AMXX] Authid ^"%s^" added to ban list", arg)
}
get_user_name(id, name, 31)
show_activity_key("ADMIN_ADDBAN_1", "ADMIN_ADDBAN_2", name, arg);
get_user_authid(id, authid, 31)
log_amx("Cmd: ^"%s<%d><%s><>^" ban ^"%s^" (minutes ^"%s^") (reason ^"%s^")", name, get_user_userid(id), authid, arg, minutes, reason)
return PLUGIN_HANDLED
}
public cmdBan(id, level, cid)
{
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
new target[32], minutes[8], reason[64]
read_argv(1, target, 31)
read_argv(2, minutes, 7)
read_argv(3, reason, 63)
new player = cmd_target(id, target, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_NO_BOTS | CMDTARGET_ALLOW_SELF)
if (!player)
return PLUGIN_HANDLED
new authid[32], name2[32], authid2[32], name[32]
new userid2 = get_user_userid(player)
get_user_authid(player, authid2, 31)
get_user_authid(id, authid, 31)
get_user_name(player, name2, 31)
get_user_name(id, name, 31)
log_amx("Ban: ^"%s<%d><%s><>^" ban and kick ^"%s<%d><%s><>^" (minutes ^"%s^") (reason ^"%s^")", name, get_user_userid(id), authid, name2, userid2, authid2, minutes, reason)
new temp[64], banned[16], nNum = str_to_num(minutes)
if (nNum)
format(temp, 63, "%L", player, "FOR_MIN", minutes)
else
format(temp, 63, "%L", player, "PERM")
format(banned, 15, "%L", player, "BANNED")
if (reason[0])
server_cmd("kick #%d ^"%s (%s %s)^";wait;banid ^"%s^" ^"%s^";wait;writeid", userid2, reason, banned, temp, minutes, authid2)
else
server_cmd("kick #%d ^"%s %s^";wait;banid ^"%s^" ^"%s^";wait;writeid", userid2, banned, temp, minutes, authid2)
// Display the message to all clients
new msg[256];
new len;
new maxpl = get_maxplayers();
for (new i = 1; i <= maxpl; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
{
len = formatex(msg, charsmax(msg), "%L", i, "BAN");
len += formatex(msg[len], charsmax(msg) - len, " %s ", name2);
if (nNum)
{
len += formatex(msg[len], charsmax(msg) - len, "%L", i, "FOR_MIN", minutes);
}
else
{
len += formatex(msg[len], charsmax(msg) - len, "%L", i, "PERM");
}
if (strlen(reason) > 0)
{
formatex(msg[len], charsmax(msg) - len, " (%L: %s)", i, "REASON", reason);
}
show_activity_id(i, id, name, msg);
}
}
console_print(id, "[AMXX] %L", id, "CLIENT_BANNED", name2)
return PLUGIN_HANDLED
}
public cmdBanIP(id, level, cid)
{
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
new target[32], minutes[8], reason[64]
read_argv(1, target, 31)
read_argv(2, minutes, 7)
read_argv(3, reason, 63)
new player = cmd_target(id, target, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_NO_BOTS | CMDTARGET_ALLOW_SELF)
if (!player)
{
// why is this here?
// no idea
// player = cmd_target(id, target, 9);
return PLUGIN_HANDLED
}
new authid[32], name2[32], authid2[32], name[32]
new userid2 = get_user_userid(player)
get_user_authid(player, authid2, 31)
get_user_authid(id, authid, 31)
get_user_name(player, name2, 31)
get_user_name(id, name, 31)
log_amx("Ban: ^"%s<%d><%s><>^" ban and kick ^"%s<%d><%s><>^" (minutes ^"%s^") (reason ^"%s^")", name, get_user_userid(id), authid, name2, userid2, authid2, minutes, reason)
new temp[64], banned[16], nNum = str_to_num(minutes)
if (nNum)
format(temp, 63, "%L", player, "FOR_MIN", minutes)
else
format(temp, 63, "%L", player, "PERM")
format(banned, 15, "%L", player, "BANNED")
new address[32]
get_user_ip(player, address, 31, 1)
if (reason[0])
server_cmd("kick #%d ^"%s (%s %s)^";wait;addip ^"%s^" ^"%s^";wait;writeip", userid2, reason, banned, temp, minutes, address)
else
server_cmd("kick #%d ^"%s %s^";wait;addip ^"%s^" ^"%s^";wait;writeip", userid2, banned, temp, minutes, address)
// Display the message to all clients
new msg[256];
new len;
new maxpl = get_maxplayers();
for (new i = 1; i <= maxpl; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
{
len = formatex(msg, charsmax(msg), "%L", i, "BAN");
len += formatex(msg[len], charsmax(msg) - len, " %s ", name2);
if (nNum)
{
formatex(msg[len], charsmax(msg) - len, "%L", i, "FOR_MIN", minutes);
}
else
{
formatex(msg[len], charsmax(msg) - len, "%L", i, "PERM");
}
if (strlen(reason) > 0)
{
formatex(msg[len], charsmax(msg) - len, " (%L: %s)", i, "REASON", reason);
}
show_activity_id(i, id, name, msg);
}
}
console_print(id, "[AMXX] %L", id, "CLIENT_BANNED", name2)
return PLUGIN_HANDLED
}
public cmdSlay(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32]
read_argv(1, arg, 31)
new player = cmd_target(id, arg, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF | CMDTARGET_ONLY_ALIVE)
if (!player)
return PLUGIN_HANDLED
user_kill(player)
new authid[32], name2[32], authid2[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
get_user_authid(player, authid2, 31)
get_user_name(player, name2, 31)
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);
console_print(id, "[AMXX] %L", id, "CLIENT_SLAYED", name2)
return PLUGIN_HANDLED
}
public cmdSlap(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32]
read_argv(1, arg, 31)
new player = cmd_target(id, arg, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF | CMDTARGET_ONLY_ALIVE)
if (!player)
return PLUGIN_HANDLED
new spower[32], authid[32], name2[32], authid2[32], name[32]
read_argv(2, spower, 31)
new damage = str_to_num(spower)
user_slap(player, damage)
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
get_user_authid(player, authid2, 31)
get_user_name(player, name2, 31)
log_amx("Cmd: ^"%s<%d><%s><>^" slap with %d damage ^"%s<%d><%s><>^"", name, get_user_userid(id), authid, damage, name2, get_user_userid(player), authid2)
show_activity_key("ADMIN_SLAP_1", "ADMIN_SLAP_2", name, name2, damage);
console_print(id, "[AMXX] %L", id, "CLIENT_SLAPED", name2, damage)
return PLUGIN_HANDLED
}
public chMap(map[])
{
server_cmd("changelevel %s", map)
}
public cmdMap(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32]
new arglen = read_argv(1, arg, 31)
if (!is_map_valid(arg))
{
console_print(id, "[AMXX] %L", id, "MAP_NOT_FOUND")
return PLUGIN_HANDLED
}
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
show_activity_key("ADMIN_MAP_1", "ADMIN_MAP_2", name, arg);
log_amx("Cmd: ^"%s<%d><%s><>^" changelevel ^"%s^"", name, get_user_userid(id), authid, arg)
new _modName[10]
get_modname(_modName, 9)
if (!equal(_modName, "zp"))
{
message_begin(MSG_ALL, SVC_INTERMISSION)
message_end()
}
set_task(2.0, "chMap", 0, arg, arglen + 1)
return PLUGIN_HANDLED
}
stock bool:onlyRcon(const name[])
{
new pentru=get_cvar_pointer(name);
if (pentru && get_pcvar_flags(pentru) & FCVAR_PROTECTED)
{
return true;
}
return false;
}
public cmdCvar(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32], arg2[64]
read_argv(1, arg, 31)
read_argv(2, arg2, 63)
new pointer;
if (equal(arg, "add") && (get_user_flags(id) & ADMIN_RCON))
{
if ((pointer=get_cvar_pointer(arg2))!=0)
{
new flags=get_pcvar_flags(pointer);
if (!(flags & FCVAR_PROTECTED))
{
set_pcvar_flags(pointer,flags | FCVAR_PROTECTED);
}
}
return PLUGIN_HANDLED
}
if ((pointer=get_cvar_pointer(arg))==0)
{
console_print(id, "[AMXX] %L", id, "UNKNOWN_CVAR", arg)
return PLUGIN_HANDLED
}
if (onlyRcon(arg) && !(get_user_flags(id) & ADMIN_RCON))
{
// Exception for the new onlyRcon rules:
// sv_password is allowed to be modified by ADMIN_PASSWORD
if (!(equali(arg,"sv_password") && (get_user_flags(id) & ADMIN_PASSWORD)))
{
console_print(id, "[AMXX] %L", id, "CVAR_NO_ACC")
return PLUGIN_HANDLED
}
}
if (read_argc() < 3)
{
get_pcvar_string(pointer, arg2, 63)
console_print(id, "[AMXX] %L", id, "CVAR_IS", arg, arg2)
return PLUGIN_HANDLED
}
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
log_amx("Cmd: ^"%s<%d><%s><>^" set cvar (name ^"%s^") (value ^"%s^")", name, get_user_userid(id), authid, arg, arg2)
set_cvar_string(arg, arg2)
// Display the message to all clients
new cvar_val[64];
new maxpl = get_maxplayers();
for (new i = 1; i <= maxpl; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
{
if (get_pcvar_flags(pointer) & FCVAR_PROTECTED || equali(arg, "rcon_password"))
{
formatex(cvar_val, charsmax(cvar_val), "*** %L ***", i, "PROTECTED");
}
else
{
copy(cvar_val, charsmax(cvar_val), arg2);
}
show_activity_id(i, id, name, "%L", i, "SET_CVAR_TO", "", arg, cvar_val);
}
}
console_print(id, "[AMXX] %L", id, "CVAR_CHANGED", arg, arg2)
return PLUGIN_HANDLED
}
public cmdPlugins(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (id==0) // If server executes redirect this to "amxx plugins" for more in depth output
{
server_cmd("amxx plugins");
server_exec();
return PLUGIN_HANDLED;
}
new name[32], version[32], author[32], filename[32], status[32]
new lName[32], lVersion[32], lAuthor[32], lFile[32], lStatus[32]
format(lName, 31, "%L", id, "NAME")
format(lVersion, 31, "%L", id, "VERSION")
format(lAuthor, 31, "%L", id, "AUTHOR")
format(lFile, 31, "%L", id, "FILE")
format(lStatus, 31, "%L", id, "STATUS")
new StartPLID=0;
new EndPLID;
new Temp[96]
new num = get_pluginsnum()
if (read_argc() > 1)
{
read_argv(1,Temp,sizeof(Temp)-1);
StartPLID=str_to_num(Temp)-1; // zero-based
}
EndPLID=min(StartPLID + 10, num);
new running = 0
console_print(id, "----- %L -----", id, "LOADED_PLUGINS")
console_print(id, "%-18.17s %-11.10s %-17.16s %-16.15s %-9.8s", lName, lVersion, lAuthor, lFile, lStatus)
new i=StartPLID;
while (i <EndPLID)
{
get_plugin(i++, filename, 31, name, 31, version, 31, author, 31, status, 31)
console_print(id, "%-18.17s %-11.10s %-17.16s %-16.15s %-9.8s", name, version, author, filename, status)
if (status[0]=='d' || status[0]=='r') // "debug" or "running"
running++
}
console_print(id, "%L", id, "PLUGINS_RUN", EndPLID-StartPLID, running)
console_print(id, "----- %L -----",id,"HELP_ENTRIES",StartPLID + 1,EndPLID,num);
if (EndPLID < num)
{
formatex(Temp,sizeof(Temp)-1,"----- %L -----",id,"HELP_USE_MORE", EndPLID + 1);
replace_all(Temp,sizeof(Temp)-1,"amx_help","amx_plugins");
console_print(id,"%s",Temp);
}
else
{
formatex(Temp,sizeof(Temp)-1,"----- %L -----",id,"HELP_USE_BEGIN");
replace_all(Temp,sizeof(Temp)-1,"amx_help","amx_plugins");
console_print(id,"%s",Temp);
}
return PLUGIN_HANDLED
}
public cmdModules(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new name[32], version[32], author[32], status, sStatus[16]
new lName[32], lVersion[32], lAuthor[32], lStatus[32];
format(lName, 31, "%L", id, "NAME")
format(lVersion, 31, "%L", id, "VERSION")
format(lAuthor, 31, "%L", id, "AUTHOR")
format(lStatus, charsmax(lStatus), "%L", id, "STATUS")
new num = get_modulesnum()
console_print(id, "%L:", id, "LOADED_MODULES")
console_print(id, "%-23.22s %-11.10s %-20.19s %-11.10s", lName, lVersion, lAuthor, lStatus)
for (new i = 0; i < num; i++)
{
get_module(i, name, 31, author, 31, version, 31, status)
switch (status)
{
case module_loaded: copy(sStatus, 15, "running")
default:
{
copy(sStatus, 15, "bad load");
copy(name, charsmax(name), "unknown");
copy(author, charsmax(author), "unknown");
copy(version, charsmax(version), "unknown");
}
}
console_print(id, "%-23.22s %-11.10s %-20.19s %-11.10s", name, version, author, sStatus)
}
console_print(id, "%L", id, "NUM_MODULES", num)
return PLUGIN_HANDLED
}
public cmdCfg(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[128]
read_argv(1, arg, 127)
if (!file_exists(arg))
{
console_print(id, "[AMXX] %L", id, "FILE_NOT_FOUND", arg)
return PLUGIN_HANDLED
}
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
log_amx("Cmd: ^"%s<%d><%s><>^" execute cfg (file ^"%s^")", name, get_user_userid(id), authid, arg)
console_print(id, "[AMXX] Executing file ^"%s^"", arg)
server_cmd("exec %s", arg)
show_activity_key("ADMIN_CONF_1", "ADMIN_CONF_2", name, arg);
return PLUGIN_HANDLED
}
public cmdLBack()
{
if (!g_PauseAllowed)
return PLUGIN_CONTINUE
new paused[25]
format(paused, 24, "%L", g_pauseCon, g_Paused ? "UNPAUSED" : "PAUSED")
set_cvar_float("pausable", g_pausAble)
console_print(g_pauseCon, "[AMXX] Server %s", paused)
g_PauseAllowed = false
if (g_Paused)
g_Paused = false
else
g_Paused = true
return PLUGIN_HANDLED
}
public cmdPause(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new authid[32], name[32], slayer = id
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
if (pausable!=0)
{
g_pausAble = get_pcvar_float(pausable)
}
if (!slayer)
slayer = find_player("h")
if (!slayer)
{
console_print(id, "[AMXX] %L", id, "UNABLE_PAUSE")
return PLUGIN_HANDLED
}
set_cvar_float("pausable", 1.0)
g_PauseAllowed = true
client_cmd(slayer, "pause;pauseAck")
log_amx("Cmd: ^"%s<%d><%s><>^" %s server", name, get_user_userid(id), authid, g_Paused ? "unpause" : "pause")
console_print(id, "[AMXX] %L", id, g_Paused ? "UNPAUSING" : "PAUSING")
// Display the message to all clients
new maxpl = get_maxplayers();
for (new i = 1; i <= maxpl; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
{
show_activity_id(i, id, name, "%L server", i, g_Paused ? "UNPAUSE" : "PAUSE");
}
}
g_pauseCon = id
return PLUGIN_HANDLED
}
public cmdShowRcon(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new password[64]
get_pcvar_string(rcon_password, password, 63)
if (!password[0])
{
cmdRcon(id, level, cid)
} else {
new args[128]
read_args(args, 127)
client_cmd(id, "rcon_password %s", password)
client_cmd(id, "rcon %s", args)
}
return PLUGIN_HANDLED
}
public cmdRcon(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[128], authid[32], name[32]
read_args(arg, 127)
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
log_amx("Cmd: ^"%s<%d><%s><>^" server console (cmdline ^"%s^")", name, get_user_userid(id), authid, arg)
console_print(id, "[AMXX] %L", id, "COM_SENT_SERVER", arg)
server_cmd("%s", arg)
return PLUGIN_HANDLED
}
public cmdWho(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new players[32], inum, cl_on_server[64], authid[32], name[32], flags, sflags[32]
new lImm[16], lRes[16], lAccess[16], lYes[16], lNo[16]
format(lImm, 15, "%L", id, "IMMU")
format(lRes, 15, "%L", id, "RESERV")
format(lAccess, 15, "%L", id, "ACCESS")
format(lYes, 15, "%L", id, "YES")
format(lNo, 15, "%L", id, "NO")
get_players(players, inum)
format(cl_on_server, 63, "%L", id, "CLIENTS_ON_SERVER")
console_print(id, "^n%s:^n # %-16.15s %-20s %-8s %-4.3s %-4.3s %s", cl_on_server, "nick", "authid", "userid", lImm, lRes, lAccess)
for (new a = 0; a < inum; ++a)
{
get_user_authid(players[a], authid, 31)
get_user_name(players[a], name, 31)
flags = get_user_flags(players[a])
get_flags(flags, sflags, 31)
console_print(id, "%2d %-16.15s %-20s %-8d %-6.5s %-6.5s %s", players[a], name, authid,
get_user_userid(players[a]), (flags&ADMIN_IMMUNITY) ? lYes : lNo, (flags&ADMIN_RESERVATION) ? lYes : lNo, sflags)
}
console_print(id, "%L", id, "TOTAL_NUM", inum)
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
log_amx("Cmd: ^"%s<%d><%s><>^" ask for players list", name, get_user_userid(id), authid)
return PLUGIN_HANDLED
}
hasTag(name[], tags[4][32], tagsNum)
{
for (new a = 0; a < tagsNum; ++a)
if (contain(name, tags[a]) != -1)
return a
return -1
}
public cmdLeave(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new argnum = read_argc()
new ltags[4][32]
new ltagsnum = 0
for (new a = 1; a < 5; ++a)
{
if (a < argnum)
read_argv(a, ltags[ltagsnum++], 31)
else
ltags[ltagsnum++][0] = 0
}
new nick[32], ires, pnum = get_maxplayers() + 1, count = 0, lReason[128]
for (new b = 1; b < pnum; ++b)
{
if (!is_user_connected(b) && !is_user_connecting(b)) continue
get_user_name(b, nick, 31)
ires = hasTag(nick, ltags, ltagsnum)
if (ires != -1)
{
console_print(id, "[AMXX] %L", id, "SKIP_MATCH", nick, ltags[ires])
continue
}
if (get_user_flags(b) & ADMIN_IMMUNITY)
{
console_print(id, "[AMXX] %L", id, "SKIP_IMM", nick)
continue
}
console_print(id, "[AMXX] %L", id, "KICK_PL", nick)
if (is_user_bot(b))
server_cmd("kick #%d", get_user_userid(b))
else
{
format(lReason, 127, "%L", b, "YOU_DROPPED")
server_cmd("kick #%d ^"%s^"", get_user_userid(b), lReason)
}
count++
}
console_print(id, "[AMXX] %L", id, "KICKED_CLIENTS", count)
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
log_amx("Kick: ^"%s<%d><%s><>^" leave some group (tag1 ^"%s^") (tag2 ^"%s^") (tag3 ^"%s^") (tag4 ^"%s^")", name, get_user_userid(id), authid, ltags[0], ltags[1], ltags[2], ltags[3])
show_activity_key("ADMIN_LEAVE_1", "ADMIN_LEAVE_2", name, ltags[0], ltags[1], ltags[2], ltags[3]);
return PLUGIN_HANDLED
}
public cmdNick(id, level, cid)
{
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
new arg1[32], arg2[32], authid[32], name[32], authid2[32], name2[32]
read_argv(1, arg1, 31)
read_argv(2, arg2, 31)
new player = cmd_target(id, arg1, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF)
if (!player)
return PLUGIN_HANDLED
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
get_user_authid(player, authid2, 31)
get_user_name(player, name2, 31)
client_cmd(player, "name ^"%s^"", arg2)
log_amx("Cmd: ^"%s<%d><%s><>^" change nick to ^"%s^" ^"%s<%d><%s><>^"", name, get_user_userid(id), authid, arg2, name2, get_user_userid(player), authid2)
show_activity_key("ADMIN_NICK_1", "ADMIN_NICK_2", name, name2, arg2);
console_print(id, "[AMXX] %L", id, "CHANGED_NICK", name2, arg2)
return PLUGIN_HANDLED
}
public cmdLast(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
{
return PLUGIN_HANDLED;
}
new name[32];
new authid[32];
new ip[32];
new flags[32];
new access;
// This alignment is a bit weird (it should grow if the name is larger)
// but otherwise for the more common shorter name, it'll wrap in server console
// Steam client display is all skewed anyway because of the non fixed font.
console_print(id, "%19s %20s %15s %s", "name", "authid", "ip", "access");
for (new i = 0; i < g_Size; i++)
{
GetInfo(i, name, charsmax(name), authid, charsmax(authid), ip, charsmax(ip), access);
get_flags(access, flags, charsmax(flags));
console_print(id, "%19s %20s %15s %s", name, authid, ip, flags);
}
console_print(id, "%d old connections saved.", g_Size);
return PLUGIN_HANDLED;
}
Code: Select all
#include <amxmodx>
#define DISPLAY_MSG // Comment to disable message on join
#define HELPAMOUNT 10 // Number of commands per page
public plugin_init()
{
register_plugin("Admin Help", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("adminhelp.txt")
register_concmd("amx_help", "cmdHelp", 0, "<page> [nr of cmds (only for server)] - displays this help")
}
#if defined DISPLAY_MSG
public client_putinserver(id)
{
if (is_user_bot(id))
return
set_task(15.0, "dispInfo", id)
}
public client_disconnect(id)
{
remove_task(id)
}
#endif
public cmdHelp(id, level, cid)
{
new arg1[8], flags = get_user_flags(id)
new start = read_argv(1, arg1, 7) ? str_to_num(arg1) : 1
new lHelpAmount = HELPAMOUNT
// HACK: ADMIN_ADMIN is never set as a user's actual flags, so those types of commands never show
if (flags > 0 && !(flags & ADMIN_USER))
{
flags |= ADMIN_ADMIN;
}
if (id == 0 && read_argc() == 3)
lHelpAmount = read_argv(2, arg1, 7) ? str_to_num(arg1) : HELPAMOUNT
if (--start < 0)
start = 0
new clcmdsnum = get_concmdsnum(flags, id)
if (start >= clcmdsnum)
start = clcmdsnum - 1
console_print(id, "^n----- %L -----", id, "HELP_COMS")
new info[128], cmd[32], eflags
new end = start + lHelpAmount // HELPAMOUNT
if (end > clcmdsnum)
end = clcmdsnum
for (new i = start; i < end; i++)
{
get_concmd(i, cmd, 31, eflags, info, 127, flags, id)
console_print(id, "%3d: %s %s", i + 1, cmd, info)
}
console_print(id, "----- %L -----", id, "HELP_ENTRIES", start + 1, end, clcmdsnum)
if (end < clcmdsnum)
console_print(id, "----- %L -----", id, "HELP_USE_MORE", end + 1)
else
console_print(id, "----- %L -----", id, "HELP_USE_BEGIN")
return PLUGIN_HANDLED
}
#if defined DISPLAY_MSG
public dispInfo(id)
{
client_print(id, print_chat, "%L", id, "TYPE_HELP")
new nextmap[32]
get_cvar_string("amx_nextmap", nextmap, 31)
if (get_cvar_float("mp_timelimit"))
{
new timeleft = get_timeleft()
if (timeleft > 0)
{
client_print(id, print_chat, "%L", id, "TIME_INFO_1", timeleft / 60, timeleft % 60, nextmap)
} else {
client_print(id, print_chat, "%L", id, "TIME_INFO_2", nextmap)
}
}
}
#endif
Code: Select all
#include <amxmodx>
#include <amxmisc>
new g_cmdLoopback[16]
new g_ResPtr
new g_HidePtr
public plugin_init()
{
register_plugin("Slots Reservation", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("adminslots.txt")
register_dictionary("common.txt")
g_ResPtr = register_cvar("amx_reservation", "0")
g_HidePtr = register_cvar("amx_hideslots", "0")
format(g_cmdLoopback, 15, "amxres%c%c%c%c", random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'))
register_clcmd(g_cmdLoopback, "ackSignal")
}
public plugin_cfg()
{
set_task(3.0, "MapLoaded")
}
public MapLoaded()
{
if (!get_pcvar_num(g_HidePtr))
return
new maxplayers = get_maxplayers()
new players = get_playersnum(1)
new limit = maxplayers - get_pcvar_num(g_ResPtr)
setVisibleSlots(players, maxplayers, limit)
}
public ackSignal(id)
{
new lReason[64]
format(lReason, 63, "%L", id, "DROPPED_RES")
server_cmd("kick #%d ^"%s^"", get_user_userid(id), lReason)
return PLUGIN_HANDLED
}
public client_authorized(id)
{
new maxplayers = get_maxplayers()
new players = get_playersnum(1)
new limit = maxplayers - get_pcvar_num(g_ResPtr)
if (access(id, ADMIN_RESERVATION) || (players <= limit))
{
if (get_pcvar_num(g_HidePtr) == 1)
setVisibleSlots(players, maxplayers, limit)
return PLUGIN_CONTINUE
}
client_cmd(id, "%s", g_cmdLoopback)
return PLUGIN_HANDLED
}
public client_disconnect(id)
{
if (!get_pcvar_num(g_HidePtr))
return PLUGIN_CONTINUE
new maxplayers = get_maxplayers()
setVisibleSlots(get_playersnum(1) - 1, maxplayers, maxplayers - get_pcvar_num(g_ResPtr))
return PLUGIN_CONTINUE
}
setVisibleSlots(players, maxplayers, limit)
{
new num = players + 1
if (players == maxplayers)
num = maxplayers
else if (players < limit)
num = limit
set_cvar_num("sv_visiblemaxplayers", num)
}
Code: Select all
#include <amxmodx>
#include <amxmisc>
new g_Answer[128]
new g_optionName[4][64]
new g_voteCount[4]
new g_validMaps
new g_yesNoVote
new g_coloredMenus
new g_voteCaller
new g_Execute[256]
new g_execLen
new bool:g_execResult
new Float:g_voteRatio
public plugin_init()
{
register_plugin("Admin Votes", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("adminvote.txt")
register_dictionary("common.txt")
register_dictionary("mapsmenu.txt")
register_menucmd(register_menuid("Change map to "), MENU_KEY_1|MENU_KEY_2, "voteCount")
register_menucmd(register_menuid("Choose map: "), MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4, "voteCount")
register_menucmd(register_menuid("Kick "), MENU_KEY_1|MENU_KEY_2, "voteCount")
register_menucmd(register_menuid("Ban "), MENU_KEY_1|MENU_KEY_2, "voteCount")
register_menucmd(register_menuid("Vote: "), MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4, "voteCount")
register_menucmd(register_menuid("The result: "), MENU_KEY_1|MENU_KEY_2, "actionResult")
register_concmd("amx_votemap", "cmdVoteMap", ADMIN_VOTE, "<map> [map] [map] [map]")
register_concmd("amx_votekick", "cmdVoteKickBan", ADMIN_VOTE, "<name or #userid>")
register_concmd("amx_voteban", "cmdVoteKickBan", ADMIN_VOTE, "<name or #userid>")
register_concmd("amx_vote", "cmdVote", ADMIN_VOTE, "<question> <answer#1> <answer#2>")
register_concmd("amx_cancelvote", "cmdCancelVote", ADMIN_VOTE, "- cancels last vote")
g_coloredMenus = colored_menus()
}
public cmdCancelVote(id, level, cid)
{
if (!cmd_access(id, level, cid, 0))
return PLUGIN_HANDLED
if (task_exists(99889988, 1))
{
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
log_amx("Vote: ^"%s<%d><%s><>^" cancel vote session", name, get_user_userid(id), authid)
new maxpl=get_maxplayers();
new msg[256];
for (new i = 1; i <= maxpl; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
{
// HACK: ADMIN_CANC_VOTE_{1,2} keys were designed very poorly. Remove all : and %s in it.
LookupLangKey(msg, charsmax(msg), "ADMIN_CANC_VOTE_1", i);
replace_all(msg, charsmax(msg), "%s", "");
replace_all(msg, charsmax(msg), ":", "");
trim(msg);
show_activity_id(i, id, name, msg);
}
}
console_print(id, "%L", id, "VOTING_CANC")
client_print(0,print_chat,"%L",LANG_PLAYER,"VOTING_CANC")
remove_task(99889988, 1)
set_cvar_float("amx_last_voting", get_gametime())
}
else
console_print(id, "%L", id, "NO_VOTE_CANC")
return PLUGIN_HANDLED
}
public delayedExec(cmd[])
server_cmd("%s", cmd)
public autoRefuse()
{
log_amx("Vote: %L", "en", "RES_REF")
client_print(0, print_chat, "%L", LANG_PLAYER, "RES_REF")
}
public actionResult(id, key)
{
remove_task(4545454)
switch (key)
{
case 0:
{
set_task(2.0, "delayedExec", 0, g_Execute, g_execLen)
log_amx("Vote: %L", "en", "RES_ACCEPTED")
client_print(0, print_chat, "%L", LANG_PLAYER, "RES_ACCEPTED")
}
case 1: autoRefuse()
}
return PLUGIN_HANDLED
}
public checkVotes()
{
new best = 0
if (!g_yesNoVote)
{
for (new a = 0; a < 4; ++a)
if (g_voteCount[a] > g_voteCount[best])
best = a
}
new votesNum = g_voteCount[0] + g_voteCount[1] + g_voteCount[2] + g_voteCount[3]
new iRatio = votesNum ? floatround(g_voteRatio * float(votesNum), floatround_ceil) : 1
new iResult = g_voteCount[best]
new players[32], pnum, i
get_players(players, pnum, "c")
if (iResult < iRatio)
{
new lVotingFailed[64]
for (i = 0; i < pnum; i++)
{
format(lVotingFailed, 63, "%L", players[i], "VOTING_FAILED")
if (g_yesNoVote)
client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_1", lVotingFailed, g_voteCount[0], g_voteCount[1], iRatio)
else
client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_2", lVotingFailed, iResult, iRatio)
}
format(lVotingFailed, 63, "%L", "en", "VOTING_FAILED")
log_amx("Vote: %s (got ^"%d^") (needed ^"%d^")", lVotingFailed, iResult, iRatio)
return PLUGIN_CONTINUE
}
g_execLen = format(g_Execute, 255, g_Answer, g_optionName[best]) + 1
if (g_execResult)
{
g_execResult = false
if (is_user_connected(g_voteCaller))
{
new menuBody[512], lTheResult[32], lYes[16], lNo[16]
format(lTheResult, 31, "%L", g_voteCaller, "THE_RESULT")
format(lYes, 15, "%L", g_voteCaller, "YES")
format(lNo, 15, "%L", g_voteCaller, "NO")
new len = format(menuBody, 511, g_coloredMenus ? "\y%s: \w%s^n^n" : "%s: %s^n^n", lTheResult, g_Execute)
len += format(menuBody[len], 511 - len, g_coloredMenus ? "\y%L^n\w" : "%L^n", g_voteCaller, "WANT_CONTINUE")
format(menuBody[len], 511 - len, "^n1. %s^n2. %s", lYes, lNo)
show_menu(g_voteCaller, 0x03, menuBody, 10, "The result: ")
set_task(10.0, "autoRefuse", 4545454)
}
else
set_task(2.0, "delayedExec", 0, g_Execute, g_execLen)
}
new lVotingSuccess[32]
for (i = 0; i < pnum; i++)
{
format(lVotingSuccess, 31, "%L", players[i], "VOTING_SUCCESS")
client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_3", lVotingSuccess, iResult, iRatio, g_Execute)
}
format(lVotingSuccess, 31, "%L", "en", "VOTING_SUCCESS")
log_amx("Vote: %s (got ^"%d^") (needed ^"%d^") (result ^"%s^")", lVotingSuccess, iResult, iRatio, g_Execute)
return PLUGIN_CONTINUE
}
public voteCount(id, key)
{
if (get_cvar_num("amx_vote_answers"))
{
new name[32]
get_user_name(id, name, 31)
if (g_yesNoVote)
client_print(0, print_chat, "%L", LANG_PLAYER, key ? "VOTED_AGAINST" : "VOTED_FOR", name)
else
client_print(0, print_chat, "%L", LANG_PLAYER, "VOTED_FOR_OPT", name, key + 1)
}
++g_voteCount[key]
return PLUGIN_HANDLED
}
public cmdVoteMap(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new Float:voting = get_cvar_float("amx_last_voting")
if (voting > get_gametime())
{
console_print(id, "%L", id, "ALREADY_VOTING")
return PLUGIN_HANDLED
}
if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
{
console_print(id, "%L", id, "VOTING_NOT_ALLOW")
return PLUGIN_HANDLED
}
new argc = read_argc()
if (argc > 5) argc = 5
g_validMaps = 0
g_optionName[0][0] = 0
g_optionName[1][0] = 0
g_optionName[2][0] = 0
g_optionName[3][0] = 0
for (new i = 1; i < argc; ++i)
{
read_argv(i, g_optionName[g_validMaps], 31)
if (is_map_valid(g_optionName[g_validMaps]))
g_validMaps++
}
if (g_validMaps == 0)
{
new lMaps[16]
format(lMaps, 15, "%L", id, (argc == 2) ? "MAP_IS" : "MAPS_ARE")
console_print(id, "%L", id, "GIVEN_NOT_VALID", lMaps)
return PLUGIN_HANDLED
}
new menu_msg[256], len = 0
new keys = 0
if (g_validMaps > 1)
{
keys = MENU_KEY_0
len = format(menu_msg, 255, g_coloredMenus ? "\y%L: \w^n^n" : "%L: ^n^n", LANG_SERVER, "CHOOSE_MAP")
new temp[128]
for (new a = 0; a < g_validMaps; ++a)
{
format(temp, 127, "%d. %s^n", a+1, g_optionName[a])
len += copy(menu_msg[len], 255-len, temp)
keys |= (1<<a)
}
format(menu_msg[len], 255-len, "^n0. %L", LANG_SERVER, "NONE")
g_yesNoVote = 0
} else {
new lChangeMap[32], lYes[16], lNo[16]
format(lChangeMap, 31, "%L", LANG_SERVER, "CHANGE_MAP_TO")
format(lYes, 15, "%L", LANG_SERVER, "YES")
format(lNo, 15, "%L", LANG_SERVER, "NO")
format(menu_msg, 255, g_coloredMenus ? "\y%s %s?\w^n^n1. %s^n2. %s" : "%s %s?^n^n1. %s^n2. %s", lChangeMap, g_optionName[0], lYes, lNo)
keys = MENU_KEY_1|MENU_KEY_2
g_yesNoVote = 1
}
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
if (argc == 2)
log_amx("Vote: ^"%s<%d><%s><>^" vote map (map ^"%s^")", name, get_user_userid(id), authid, g_optionName[0])
else
log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")", name, get_user_userid(id), authid, g_optionName[0], g_optionName[1], g_optionName[2], g_optionName[3])
new maxpl=get_maxplayers();
new msg[256];
for (new i = 1; i <= maxpl; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
{
// HACK: ADMIN_VOTE_MAP_{1,2} keys were designed very poorly. Remove all : and %s in it.
LookupLangKey(msg, charsmax(msg), "ADMIN_VOTE_MAP_1", i);
replace_all(msg, charsmax(msg), "%s", "");
replace_all(msg, charsmax(msg), ":", "");
trim(msg);
show_activity_id(i, id, name, msg);
}
}
g_execResult = true
new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
set_cvar_float("amx_last_voting", get_gametime() + vote_time)
g_voteRatio = get_cvar_float("amx_votemap_ratio")
g_Answer = "changelevel %s"
show_menu(0, keys, menu_msg, floatround(vote_time), (g_validMaps > 1) ? "Choose map: " : "Change map to ")
set_task(vote_time, "checkVotes", 99889988)
g_voteCaller = id
console_print(id, "%L", id, "VOTING_STARTED")
g_voteCount = {0, 0, 0, 0}
return PLUGIN_HANDLED
}
public cmdVote(id, level, cid)
{
if (!cmd_access(id, level, cid, 4))
return PLUGIN_HANDLED
new Float:voting = get_cvar_float("amx_last_voting")
if (voting > get_gametime())
{
console_print(id, "%L", id, "ALREADY_VOTING")
return PLUGIN_HANDLED
}
if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
{
console_print(id, "%L", id, "VOTING_NOT_ALLOW")
return PLUGIN_HANDLED
}
new quest[48]
read_argv(1, quest, 47)
if ((contain(quest, "sv_password") != -1) || (contain(quest, "rcon_password") != -1) || (contain(quest, "kick") != -1) ||
(contain(quest, "addip") != -1) || (contain(quest, "ban") != -1))
{
console_print(id, "%L", id, "VOTING_FORBIDDEN")
return PLUGIN_HANDLED
}
new count=read_argc();
for (new i=0;i<4 && (i+2)<count;i++)
{
read_argv(i+2, g_optionName[i], sizeof(g_optionName[])-1);
}
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
log_amx("Vote: ^"%s<%d><%s><>^" vote custom (question ^"%s^") (option#1 ^"%s^") (option#2 ^"%s^")", name, get_user_userid(id), authid, quest, g_optionName[0], g_optionName[1])
new maxpl=get_maxplayers();
new msg[256];
for (new i = 1; i <= maxpl; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
{
// HACK: ADMIN_VOTE_CUS_{1,2} keys were designed very poorly. Remove all : and %s in it.
LookupLangKey(msg, charsmax(msg), "ADMIN_VOTE_CUS_1", i);
replace_all(msg, charsmax(msg), "%s", "");
replace_all(msg, charsmax(msg), ":", "");
trim(msg);
show_activity_id(i, id, name, msg);
}
}
new menu_msg[512], lVote[16]
format(lVote, 15, "%L", LANG_SERVER, "VOTE")
count-=2;
if (count>4)
{
count=4;
}
// count now shows how many options were listed
new keys=0;
for (new i=0;i<count;i++)
{
keys |= (1<<i);
}
new len=formatex(menu_msg, sizeof(menu_msg)-1, g_coloredMenus ? "\y%s: %s\w^n^n" : "%s: %s^n^n", lVote, quest);
for (new i=0;i<count;i++)
{
len+=formatex(menu_msg[len], sizeof(menu_msg) - 1 - len ,"%d. %s^n",i+1,g_optionName[i]);
}
g_execResult = false
new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
set_cvar_float("amx_last_voting", get_gametime() + vote_time)
g_voteRatio = get_cvar_float("amx_vote_ratio")
replace_all(quest,sizeof(quest)-1,"%","");
format(g_Answer, 127, "%s - %%s", quest)
show_menu(0, keys, menu_msg, floatround(vote_time), "Vote: ")
set_task(vote_time, "checkVotes", 99889988)
g_voteCaller = id
console_print(id, "%L", id, "VOTING_STARTED")
g_voteCount = {0, 0, 0, 0}
g_yesNoVote = 0
return PLUGIN_HANDLED
}
public cmdVoteKickBan(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new Float:voting = get_cvar_float("amx_last_voting")
if (voting > get_gametime())
{
console_print(id, "%L", id, "ALREADY_VOTING")
return PLUGIN_HANDLED
}
if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
{
console_print(id, "%L", id, "VOTING_NOT_ALLOW")
return PLUGIN_HANDLED
}
new cmd[32]
read_argv(0, cmd, 31)
new voteban = equal(cmd, "amx_voteban")
new arg[32]
read_argv(1, arg, 31)
new player = cmd_target(id, arg, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF)
if (!player)
return PLUGIN_HANDLED
if (voteban && is_user_bot(player))
{
new imname[32]
get_user_name(player, imname, 31)
console_print(id, "%L", id, "ACTION_PERFORMED", imname)
return PLUGIN_HANDLED
}
new keys = MENU_KEY_1|MENU_KEY_2
new menu_msg[256], lYes[16], lNo[16], lKickBan[16]
format(lYes, 15, "%L", LANG_SERVER, "YES")
format(lNo, 15, "%L", LANG_SERVER, "NO")
format(lKickBan, 15, "%L", LANG_SERVER, voteban ? "BAN" : "KICK")
ucfirst(lKickBan)
get_user_name(player, arg, 31)
format(menu_msg, 255, g_coloredMenus ? "\y%s %s?\w^n^n1. %s^n2. %s" : "%s %s?^n^n1. %s^n2. %s", lKickBan, arg, lYes, lNo)
g_yesNoVote = 1
new bool:ipban=false;
if (voteban)
{
get_user_authid(player, g_optionName[0], sizeof(g_optionName[])-1);
// Do the same check that's in plmenu to determine if this should be an IP ban instead
if (equal("4294967295", g_optionName[0])
|| equal("HLTV", g_optionName[0])
|| equal("STEAM_ID_LAN", g_optionName[0])
|| equali("VALVE_ID_LAN", g_optionName[0]))
{
get_user_ip(player, g_optionName[0], sizeof(g_optionName[])-1, 1);
ipban=true;
}
}
else
{
num_to_str(get_user_userid(player), g_optionName[0], 31)
}
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
log_amx("Vote: ^"%s<%d><%s><>^" vote %s (target ^"%s^")", name, get_user_userid(id), authid, voteban ? "ban" : "kick", arg)
new maxpl=get_maxplayers();
new msg[256];
new right[256];
new dummy[1];
for (new i = 1; i <= maxpl; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
{
formatex(lKickBan, charsmax(lKickBan), "%L", i, voteban ? "BAN" : "KICK");
// HACK: ADMIN_VOTE_FOR{1,2} keys are really weird. Tokenize and ignore the text before the :
LookupLangKey(msg, charsmax(msg), "ADMIN_VOTE_FOR_1", i);
strtok(msg, dummy, 0, right, charsmax(right), ':');
trim(right);
show_activity_id(i, id, name, right, lKickBan, arg);
}
}
g_execResult = true
new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
set_cvar_float("amx_last_voting", get_gametime() + vote_time)
g_voteRatio = get_cvar_float(voteban ? "amx_voteban_ratio" : "amx_votekick_ratio")
if (voteban)
{
if (ipban==true)
{
g_Answer = "addip 30.0 %s";
}
else
{
g_Answer = "banid 30.0 %s kick";
}
}
else
{
g_Answer = "kick #%s";
}
show_menu(0, keys, menu_msg, floatround(vote_time), voteban ? "Ban " : "Kick ")
set_task(vote_time, "checkVotes", 99889988)
g_voteCaller = id
console_print(id, "%L", id, "VOTING_STARTED")
g_voteCount = {0, 0, 0, 0}
return PLUGIN_HANDLED
}
Code: Select all
#include <amxmodx>
new Float:g_Flooding[33] = {0.0, ...}
new g_Flood[33] = {0, ...}
new amx_flood_time;
public plugin_init()
{
register_plugin("Anti Flood", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("antiflood.txt")
register_clcmd("say", "chkFlood")
register_clcmd("say_team", "chkFlood")
amx_flood_time=register_cvar("amx_flood_time", "0.75")
}
public chkFlood(id)
{
new Float:maxChat = get_pcvar_float(amx_flood_time)
if (maxChat)
{
new Float:nexTime = get_gametime()
if (g_Flooding[id] > nexTime)
{
if (g_Flood[id] >= 3)
{
client_print(id, print_notify, "** %L **", id, "STOP_FLOOD")
g_Flooding[id] = nexTime + maxChat + 3.0
return PLUGIN_HANDLED
}
g_Flood[id]++
}
else if (g_Flood[id])
{
g_Flood[id]--
}
g_Flooding[id] = nexTime + maxChat
}
return PLUGIN_CONTINUE
}
Code: Select all
#include <amxmodx>
#include <amxmisc>
#define X_POS -1.0
#define Y_POS 0.20
#define HOLD_TIME 12.0
new Array:g_Values
new Array:g_Messages
new g_MessagesNum
new g_Current
#define charsof(%1) (sizeof(%1)-1)
new amx_freq_imessage;
public plugin_init()
{
g_Messages=ArrayCreate(384);
g_Values=ArrayCreate(3);
register_plugin("Info. Messages", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("imessage.txt")
register_dictionary("common.txt")
register_srvcmd("amx_imessage", "setMessage")
amx_freq_imessage=register_cvar("amx_freq_imessage", "10")
new lastinfo[8]
get_localinfo("lastinfomsg", lastinfo, 7)
g_Current = str_to_num(lastinfo)
set_localinfo("lastinfomsg", "")
}
public infoMessage()
{
if (g_Current >= g_MessagesNum)
g_Current = 0
// No messages, just get out of here
if (g_MessagesNum==0)
{
return;
}
new values[3];
new Message[384];
ArrayGetString(g_Messages, g_Current, Message, charsof(Message));
ArrayGetArray(g_Values, g_Current, values);
new hostname[64];
get_cvar_string("hostname", hostname, 63);
replace(Message, 380, "%hostname%", hostname);
set_hudmessage(values[0], values[1], values[2], X_POS, Y_POS, 0, 0.5, HOLD_TIME, 2.0, 2.0, -1);
show_hudmessage(0, "%s", Message);
client_print(0, print_console, "%s", Message);
++g_Current;
new Float:freq_im = get_pcvar_float(amx_freq_imessage);
if (freq_im > 0.0)
set_task(freq_im, "infoMessage", 12345);
}
public setMessage()
{
new Message[384];
remove_task(12345)
read_argv(1, Message, 380)
while (replace(Message, 380, "\n", "^n")) {}
new mycol[12]
new vals[3];
read_argv(2, mycol, 11) // RRRGGGBBB
vals[2] = str_to_num(mycol[6])
mycol[6] = 0
vals[1] = str_to_num(mycol[3])
mycol[3] = 0
vals[0] = str_to_num(mycol[0])
g_MessagesNum++
new Float:freq_im = get_pcvar_float(amx_freq_imessage)
ArrayPushString(g_Messages, Message);
ArrayPushArray(g_Values, vals);
if (freq_im > 0.0)
set_task(freq_im, "infoMessage", 12345)
return PLUGIN_HANDLED
}
public plugin_end()
{
new lastinfo[8]
num_to_str(g_Current, lastinfo, 7)
set_localinfo("lastinfomsg", lastinfo)
}
Code: Select all
#include <amxmodx>
#include <amxmisc>
#define SELECTMAPS 5
#define charsof(%1) (sizeof(%1)-1)
new Array:g_mapName;
new g_mapNums;
new g_nextName[SELECTMAPS]
new g_voteCount[SELECTMAPS + 2]
new g_mapVoteNum
new g_teamScore[2]
new g_lastMap[32]
new g_coloredMenus
new bool:g_selected = false
public plugin_init()
{
register_plugin("Nextmap Chooser", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("mapchooser.txt")
register_dictionary("common.txt")
g_mapName=ArrayCreate(32);
new MenuName[64]
format(MenuName, 63, "%L", "en", "CHOOSE_NEXTM")
register_menucmd(register_menuid(MenuName), (-1^(-1<<(SELECTMAPS+2))), "countVote")
register_cvar("amx_extendmap_max", "90")
register_cvar("amx_extendmap_step", "15")
if (cstrike_running())
register_event("TeamScore", "team_score", "a")
get_localinfo("lastMap", g_lastMap, 31)
set_localinfo("lastMap", "")
new maps_ini_file[64]
get_configsdir(maps_ini_file, 63);
format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file);
if (!file_exists(maps_ini_file))
get_cvar_string("mapcyclefile", maps_ini_file, 63)
if (loadSettings(maps_ini_file))
set_task(15.0, "voteNextmap", 987456, "", 0, "b")
g_coloredMenus = colored_menus()
}
public checkVotes()
{
new b = 0
for (new a = 0; a < g_mapVoteNum; ++a)
if (g_voteCount[b] < g_voteCount[a])
b = a
if (g_voteCount[SELECTMAPS] > g_voteCount[b]
&& g_voteCount[SELECTMAPS] > g_voteCount[SELECTMAPS+1])
{
new mapname[32]
get_mapname(mapname, 31)
new Float:steptime = get_cvar_float("amx_extendmap_step")
set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") + steptime)
client_print(0, print_chat, "%L", LANG_PLAYER, "CHO_FIN_EXT", steptime)
log_amx("Vote: Voting for the nextmap finished. Map %s will be extended to next %.0f minutes", mapname, steptime)
return
}
new smap[32]
if (g_voteCount[b] && g_voteCount[SELECTMAPS + 1] <= g_voteCount[b])
{
ArrayGetString(g_mapName, g_nextName[b], smap, charsof(smap));
set_cvar_string("amx_nextmap", smap);
}
get_cvar_string("amx_nextmap", smap, 31)
client_print(0, print_chat, "%L", LANG_PLAYER, "CHO_FIN_NEXT", smap)
log_amx("Vote: Voting for the nextmap finished. The nextmap will be %s", smap)
}
public countVote(id, key)
{
if (get_cvar_float("amx_vote_answers"))
{
new name[32]
get_user_name(id, name, 31)
if (key == SELECTMAPS)
client_print(0, print_chat, "%L", LANG_PLAYER, "CHOSE_EXT", name)
else if (key < SELECTMAPS)
{
new map[32];
ArrayGetString(g_mapName, g_nextName[key], map, charsof(map));
client_print(0, print_chat, "%L", LANG_PLAYER, "X_CHOSE_X", name, map);
}
}
++g_voteCount[key]
return PLUGIN_HANDLED
}
bool:isInMenu(id)
{
for (new a = 0; a < g_mapVoteNum; ++a)
if (id == g_nextName[a])
return true
return false
}
public voteNextmap()
{
new winlimit = get_cvar_num("mp_winlimit")
new maxrounds = get_cvar_num("mp_maxrounds")
if (winlimit)
{
new c = winlimit - 2
if ((c > g_teamScore[0]) && (c > g_teamScore[1]))
{
g_selected = false
return
}
}
else if (maxrounds)
{
if ((maxrounds - 2) > (g_teamScore[0] + g_teamScore[1]))
{
g_selected = false
return
}
} else {
new timeleft = get_timeleft()
if (timeleft < 1 || timeleft > 129)
{
g_selected = false
return
}
}
if (g_selected)
return
g_selected = true
new menu[512], a, mkeys = (1<<SELECTMAPS + 1)
new pos = format(menu, 511, g_coloredMenus ? "\y%L:\w^n^n" : "%L:^n^n", LANG_SERVER, "CHOOSE_NEXTM")
new dmax = (g_mapNums > SELECTMAPS) ? SELECTMAPS : g_mapNums
for (g_mapVoteNum = 0; g_mapVoteNum < dmax; ++g_mapVoteNum)
{
a = random_num(0, g_mapNums - 1)
while (isInMenu(a))
if (++a >= g_mapNums) a = 0
g_nextName[g_mapVoteNum] = a
pos += format(menu[pos], 511, "%d. %a^n", g_mapVoteNum + 1, ArrayGetStringHandle(g_mapName, a));
mkeys |= (1<<g_mapVoteNum)
g_voteCount[g_mapVoteNum] = 0
}
menu[pos++] = '^n'
g_voteCount[SELECTMAPS] = 0
g_voteCount[SELECTMAPS + 1] = 0
new mapname[32]
get_mapname(mapname, 31)
if ((winlimit + maxrounds) == 0 && (get_cvar_float("mp_timelimit") < get_cvar_float("amx_extendmap_max")))
{
pos += format(menu[pos], 511, "%d. %L^n", SELECTMAPS + 1, LANG_SERVER, "EXTED_MAP", mapname)
mkeys |= (1<<SELECTMAPS)
}
format(menu[pos], 511, "%d. %L", SELECTMAPS+2, LANG_SERVER, "NONE")
new MenuName[64]
format(MenuName, 63, "%L", "en", "CHOOSE_NEXTM")
show_menu(0, mkeys, menu, 15, MenuName)
set_task(15.0, "checkVotes")
client_print(0, print_chat, "%L", LANG_SERVER, "TIME_CHOOSE")
client_cmd(0, "spk Gman/Gman_Choose2")
log_amx("Vote: Voting for the nextmap started")
}
stock bool:ValidMap(mapname[])
{
if ( is_map_valid(mapname) )
{
return true;
}
// If the is_map_valid check failed, check the end of the string
new len = strlen(mapname) - 4;
// The mapname was too short to possibly house the .bsp extension
if (len < 0)
{
return false;
}
if ( equali(mapname[len], ".bsp") )
{
// If the ending was .bsp, then cut it off.
// the string is byref'ed, so this copies back to the loaded text.
mapname[len] = '^0';
// recheck
if ( is_map_valid(mapname) )
{
return true;
}
}
return false;
}
loadSettings(filename[])
{
if (!file_exists(filename))
return 0
new szText[32]
new currentMap[32]
new buff[256];
get_mapname(currentMap, 31)
new fp=fopen(filename,"r");
while (!feof(fp))
{
buff[0]='^0';
fgets(fp, buff, charsof(buff));
parse(buff, szText, charsof(szText));
if (szText[0] != ';' &&
ValidMap(szText) &&
!equali(szText, g_lastMap) &&
!equali(szText, currentMap))
{
ArrayPushString(g_mapName, szText);
++g_mapNums;
}
}
fclose(fp);
return g_mapNums
}
public team_score()
{
new team[2]
read_data(1, team, 1)
g_teamScore[(team[0]=='C') ? 0 : 1] = read_data(2)
}
public plugin_end()
{
new current_map[32]
get_mapname(current_map, 31)
set_localinfo("lastMap", current_map)
}
Code: Select all
/* AMX Mod X
#include <amxmodx>
#include <amxmisc>
new Array:g_mapName;
new g_mapNums
new g_menuPosition[33]
new g_voteCount[5]
new g_voteSelected[33][4]
new g_voteSelectedNum[33]
new g_coloredMenus
new g_choosed
public plugin_init()
{
register_plugin("Maps Menu", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("mapsmenu.txt")
register_dictionary("common.txt")
register_clcmd("amx_mapmenu", "cmdMapsMenu", ADMIN_MAP, "- displays changelevel menu")
register_clcmd("amx_votemapmenu", "cmdVoteMapMenu", ADMIN_VOTE, "- displays votemap menu")
register_menucmd(register_menuid("Changelevel Menu"), 1023, "actionMapsMenu")
register_menucmd(register_menuid("Which map do you want?"), 527, "voteCount")
register_menucmd(register_menuid("Change map to"), 527, "voteCount")
register_menucmd(register_menuid("Votemap Menu"), 1023, "actionVoteMapMenu")
register_menucmd(register_menuid("The winner: "), 3, "actionResult")
g_mapName=ArrayCreate(32);
new maps_ini_file[64];
get_configsdir(maps_ini_file, 63);
format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file);
if (!file_exists(maps_ini_file))
get_cvar_string("mapcyclefile", maps_ini_file, sizeof(maps_ini_file) - 1);
if (!file_exists(maps_ini_file))
format(maps_ini_file, 63, "mapcycle.txt")
load_settings(maps_ini_file)
g_coloredMenus = colored_menus()
}
public autoRefuse()
{
log_amx("Vote: %L", "en", "RESULT_REF")
client_print(0, print_chat, "%L", LANG_PLAYER, "RESULT_REF")
}
public actionResult(id, key)
{
remove_task(4545454)
switch (key)
{
case 0:
{
new _modName[10]
get_modname(_modName, 9)
if (!equal(_modName, "zp"))
{
message_begin(MSG_ALL, SVC_INTERMISSION)
message_end()
}
new tempMap[32];
ArrayGetString(g_mapName, g_choosed, tempMap, charsmax(tempMap));
set_task(2.0, "delayedChange", 0, tempMap, strlen(tempMap) + 1)
log_amx("Vote: %L", "en", "RESULT_ACC")
client_print(0, print_chat, "%L", LANG_PLAYER, "RESULT_ACC")
}
case 1: autoRefuse()
}
return PLUGIN_HANDLED
}
public checkVotes(id)
{
id -= 34567
new num, ppl[32], a = 0
get_players(ppl, num, "c")
if (num == 0) num = 1
g_choosed = -1
for (new i = 0; i < g_voteSelectedNum[id]; ++i)
if (g_voteCount[a] < g_voteCount[i])
a = i
new votesNum = g_voteCount[0] + g_voteCount[1] + g_voteCount[2] + g_voteCount[3] + g_voteCount[4]
new iRatio = votesNum ? floatround(get_cvar_float("amx_votemap_ratio") * float(votesNum), floatround_ceil) : 1
new iResult = g_voteCount[a]
if (iResult >= iRatio)
{
g_choosed = g_voteSelected[id][a]
new tempMap[32];
ArrayGetString(g_mapName, g_choosed, tempMap, charsmax(tempMap));
client_print(0, print_chat, "%L %s", LANG_PLAYER, "VOTE_SUCCESS", tempMap);
log_amx("Vote: %L %s", "en", "VOTE_SUCCESS", tempMap);
}
if (g_choosed != -1)
{
if (is_user_connected(id))
{
new menuBody[512]
new tempMap[32];
ArrayGetString(g_mapName, g_choosed, tempMap, charsmax(tempMap));
new len = format(menuBody, 511, g_coloredMenus ? "\y%L: \w%s^n^n" : "%L: %s^n^n", id, "THE_WINNER", tempMap)
len += format(menuBody[len], 511 - len, g_coloredMenus ? "\y%L^n\w" : "%L^n", id, "WANT_CONT")
format(menuBody[len], 511-len, "^n1. %L^n2. %L", id, "YES", id, "NO")
show_menu(id, 0x03, menuBody, 10, "The winner: ")
set_task(10.0, "autoRefuse", 4545454)
} else {
new _modName[10]
get_modname(_modName, 9)
if (!equal(_modName, "zp"))
{
message_begin(MSG_ALL, SVC_INTERMISSION)
message_end()
}
new tempMap[32];
ArrayGetString(g_mapName, g_choosed, tempMap, charsmax(tempMap));
set_task(2.0, "delayedChange", 0, tempMap, strlen(tempMap) + 1)
}
} else {
client_print(0, print_chat, "%L", LANG_PLAYER, "VOTE_FAILED")
log_amx("Vote: %L", "en", "VOTE_FAILED")
}
remove_task(34567 + id)
}
public voteCount(id, key)
{
if (key > 3)
{
client_print(0, print_chat, "%L", LANG_PLAYER, "VOT_CANC")
remove_task(34567 + id)
set_cvar_float("amx_last_voting", get_gametime())
log_amx("Vote: Cancel vote session")
return PLUGIN_HANDLED
}
if (get_cvar_float("amx_vote_answers"))
{
new name[32]
get_user_name(id, name, 31)
client_print(0, print_chat, "%L", LANG_PLAYER, "X_VOTED_FOR", name, key + 1)
}
++g_voteCount[key]
return PLUGIN_HANDLED
}
isMapSelected(id, pos)
{
for (new a = 0; a < g_voteSelectedNum[id]; ++a)
if (g_voteSelected[id][a] == pos)
return 1
return 0
}
displayVoteMapsMenu(id, pos)
{
if (pos < 0)
return
new menuBody[512], b = 0, start = pos * 7
if (start >= g_mapNums)
start = pos = g_menuPosition[id] = 0
new len = format(menuBody, 511, g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "VOTEMAP_MENU", pos + 1, (g_mapNums / 7 + ((g_mapNums % 7) ? 1 : 0)))
new end = start + 7, keys = MENU_KEY_0
if (end > g_mapNums)
end = g_mapNums
new tempMap[32];
for (new a = start; a < end; ++a)
{
ArrayGetString(g_mapName, a, tempMap, charsmax(tempMap));
if (g_voteSelectedNum[id] == 4 || isMapSelected(id, pos * 7 + b))
{
++b
if (g_coloredMenus)
len += format(menuBody[len], 511-len, "\d%d. %s^n\w", b, tempMap)
else
len += format(menuBody[len], 511-len, "#. %s^n", tempMap)
} else {
keys |= (1<<b)
len += format(menuBody[len], 511-len, "%d. %s^n", ++b, tempMap)
}
}
if (g_voteSelectedNum[id])
{
keys |= MENU_KEY_8
len += format(menuBody[len], 511-len, "^n8. %L^n", id, "START_VOT")
}
else
len += format(menuBody[len], 511-len, g_coloredMenus ? "^n\d8. %L^n\w" : "^n#. %L^n", id, "START_VOT")
if (end != g_mapNums)
{
len += format(menuBody[len], 511-len, "^n9. %L...^n0. %L^n", id, "MORE", id, pos ? "BACK" : "EXIT")
keys |= MENU_KEY_9
}
else
len += format(menuBody[len], 511-len, "^n0. %L^n", id, pos ? "BACK" : "EXIT")
if (g_voteSelectedNum[id])
len += format(menuBody[len], 511-len, g_coloredMenus ? "^n\y%L:^n\w" : "^n%L:^n", id, "SEL_MAPS")
else
len += format(menuBody[len], 511-len, "^n^n")
for (new c = 0; c < 4; c++)
{
if (c < g_voteSelectedNum[id])
{
ArrayGetString(g_mapName, g_voteSelected[id][c], tempMap, charsmax(tempMap));
len += format(menuBody[len], 511-len, "%s^n", tempMap)
}
else
len += format(menuBody[len], 511-len, "^n")
}
new menuName[64]
format(menuName, 63, "%L", "en", "VOTEMAP_MENU")
show_menu(id, keys, menuBody, -1, menuName)
}
public cmdVoteMapMenu(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (get_cvar_float("amx_last_voting") > get_gametime())
{
client_print(id, print_chat, "%L", id, "ALREADY_VOT")
return PLUGIN_HANDLED
}
g_voteSelectedNum[id] = 0
if (g_mapNums)
{
displayVoteMapsMenu(id, g_menuPosition[id] = 0)
} else {
console_print(id, "%L", id, "NO_MAPS_MENU")
client_print(id, print_chat, "%L", id, "NO_MAPS_MENU")
}
return PLUGIN_HANDLED
}
public cmdMapsMenu(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (g_mapNums)
{
displayMapsMenu(id, g_menuPosition[id] = 0)
} else {
console_print(id, "%L", id, "NO_MAPS_MENU")
client_print(id, print_chat, "%L", id, "NO_MAPS_MENU")
}
return PLUGIN_HANDLED
}
public delayedChange(mapname[])
server_cmd("changelevel %s", mapname)
public actionVoteMapMenu(id, key)
{
new tempMap[32];
switch (key)
{
case 7:
{
new Float:voting = get_cvar_float("amx_last_voting")
if (voting > get_gametime())
{
client_print(id, print_chat, "%L", id, "ALREADY_VOT")
return PLUGIN_HANDLED
}
if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
{
client_print(id, print_chat, "%L", id, "VOT_NOW_ALLOW")
return PLUGIN_HANDLED
}
g_voteCount = {0, 0, 0, 0, 0}
new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
set_cvar_float("amx_last_voting", get_gametime() + vote_time)
new iVoteTime = floatround(vote_time)
set_task(vote_time, "checkVotes", 34567 + id)
new menuBody[512]
new players[32]
new pnum, keys, len
get_players(players, pnum)
if (g_voteSelectedNum[id] > 1)
{
len = format(menuBody, 511, g_coloredMenus ? "\y%L^n\w^n" : "%L^n^n", id, "WHICH_MAP")
for (new c = 0; c < g_voteSelectedNum[id]; ++c)
{
ArrayGetString(g_mapName, g_voteSelected[id][c], tempMap, charsmax(tempMap));
len += format(menuBody[len], 511, "%d. %s^n", c + 1, tempMap)
keys |= (1<<c)
}
keys |= (1<<8)
len += format(menuBody[len], 511, "^n9. %L^n", id, "NONE")
} else {
ArrayGetString(g_mapName, g_voteSelected[id][0], tempMap, charsmax(tempMap));
len = format(menuBody, 511, g_coloredMenus ? "\y%L^n%s?^n\w^n1. %L^n2. %L^n" : "%L^n%s?^n^n1. %L^n2. %L^n", id, "CHANGE_MAP_TO", tempMap, id, "YES", id, "NO")
keys = MENU_KEY_1|MENU_KEY_2
}
new menuName[64]
format(menuName, 63, "%L", "en", "WHICH_MAP")
for (new b = 0; b < pnum; ++b)
if (players[b] != id)
show_menu(players[b], keys, menuBody, iVoteTime, menuName)
format(menuBody[len], 511, "^n0. %L", id, "CANC_VOTE")
keys |= MENU_KEY_0
show_menu(id, keys, menuBody, iVoteTime, menuName)
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
show_activity_key("ADMIN_V_MAP_1", "ADMIN_V_MAP_2", name);
new tempMapA[32];
new tempMapB[32];
new tempMapC[32];
new tempMapD[32];
if (g_voteSelectedNum[id] > 0)
{
ArrayGetString(g_mapName, g_voteSelected[id][0], tempMapA, charsmax(tempMapA));
}
else
{
copy(tempMapA, charsmax(tempMapA), "");
}
if (g_voteSelectedNum[id] > 1)
{
ArrayGetString(g_mapName, g_voteSelected[id][1], tempMapB, charsmax(tempMapB));
}
else
{
copy(tempMapB, charsmax(tempMapB), "");
}
if (g_voteSelectedNum[id] > 2)
{
ArrayGetString(g_mapName, g_voteSelected[id][2], tempMapC, charsmax(tempMapC));
}
else
{
copy(tempMapC, charsmax(tempMapC), "");
}
if (g_voteSelectedNum[id] > 3)
{
ArrayGetString(g_mapName, g_voteSelected[id][3], tempMapD, charsmax(tempMapD));
}
else
{
copy(tempMapD, charsmax(tempMapD), "");
}
log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")",
name, get_user_userid(id), authid,
tempMapA, tempMapB, tempMapC, tempMapD)
}
case 8: displayVoteMapsMenu(id, ++g_menuPosition[id])
case 9: displayVoteMapsMenu(id, --g_menuPosition[id])
default:
{
g_voteSelected[id][g_voteSelectedNum[id]++] = g_menuPosition[id] * 7 + key
displayVoteMapsMenu(id, g_menuPosition[id])
}
}
return PLUGIN_HANDLED
}
public actionMapsMenu(id, key)
{
switch (key)
{
case 8: displayMapsMenu(id, ++g_menuPosition[id])
case 9: displayMapsMenu(id, --g_menuPosition[id])
default:
{
new a = g_menuPosition[id] * 8 + key
new _modName[10]
get_modname(_modName, 9)
if (!equal(_modName, "zp"))
{
message_begin(MSG_ALL, SVC_INTERMISSION)
message_end()
}
new authid[32], name[32]
get_user_authid(id, authid, 31)
get_user_name(id, name, 31)
new tempMap[32];
ArrayGetString(g_mapName, a, tempMap, charsmax(tempMap));
show_activity_key("ADMIN_CHANGEL_1", "ADMIN_CHANGEL_2", name, tempMap);
log_amx("Cmd: ^"%s<%d><%s><>^" changelevel ^"%s^"", name, get_user_userid(id), authid, tempMap)
set_task(2.0, "delayedChange", 0, tempMap, strlen(tempMap) + 1)
/* displayMapsMenu(id, g_menuPosition[id]) */
}
}
return PLUGIN_HANDLED
}
displayMapsMenu(id, pos)
{
if (pos < 0)
return
new menuBody[512]
new tempMap[32]
new start = pos * 8
new b = 0
if (start >= g_mapNums)
start = pos = g_menuPosition[id] = 0
new len = format(menuBody, 511, g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "CHANGLE_MENU", pos + 1, (g_mapNums / 8 + ((g_mapNums % 8) ? 1 : 0)))
new end = start + 8
new keys = MENU_KEY_0
if (end > g_mapNums)
end = g_mapNums
for (new a = start; a < end; ++a)
{
keys |= (1<<b)
ArrayGetString(g_mapName, a, tempMap, charsmax(tempMap));
len += format(menuBody[len], 511-len, "%d. %s^n", ++b, tempMap)
}
if (end != g_mapNums)
{
format(menuBody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
keys |= MENU_KEY_9
}
else
format(menuBody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT")
new menuName[64]
format(menuName, 63, "%L", "en", "CHANGLE_MENU")
show_menu(id, keys, menuBody, -1, menuName)
}
stock bool:ValidMap(mapname[])
{
if ( is_map_valid(mapname) )
{
return true;
}
// If the is_map_valid check failed, check the end of the string
new len = strlen(mapname) - 4;
// The mapname was too short to possibly house the .bsp extension
if (len < 0)
{
return false;
}
if ( equali(mapname[len], ".bsp") )
{
// If the ending was .bsp, then cut it off.
// the string is byref'ed, so this copies back to the loaded text.
mapname[len] = '^0';
// recheck
if ( is_map_valid(mapname) )
{
return true;
}
}
return false;
}
load_settings(filename[])
{
new fp = fopen(filename, "r");
if (!fp)
{
return 0;
}
new text[256];
new tempMap[32];
while (!feof(fp))
{
fgets(fp, text, charsmax(text));
if (text[0] == ';')
{
continue;
}
if (parse(text, tempMap, charsmax(tempMap)) < 1)
{
continue;
}
if (!ValidMap(tempMap))
{
continue;
}
ArrayPushString(g_mapName, tempMap);
g_mapNums++;
}
return 1;
}
Code: Select all
#include <amxmodx>
// WARNING: If you comment this line make sure
// that in your mapcycle file maps don't repeat.
// However the same map in a row is still valid.
#define OBEY_MAPCYCLE
new g_nextMap[32]
new g_mapCycle[32]
new g_pos
public plugin_init()
{
register_plugin("NextMap", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("nextmap.txt")
register_event("30", "changeMap", "a")
register_clcmd("say nextmap", "sayNextMap", 0, "- displays nextmap")
register_clcmd("say currentmap", "sayCurrentMap", 0, "- display current map")
register_clcmd("say ff", "sayFFStatus", 0, "- display friendly fire status")
register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY)
new szString[32], szString2[32], szString3[8]
get_localinfo("lastmapcycle", szString, 31)
parse(szString, szString2, 31, szString3, 7)
g_pos = str_to_num(szString3)
get_cvar_string("mapcyclefile", g_mapCycle, 31)
if (!equal(g_mapCycle, szString2))
g_pos = 0 // mapcyclefile has been changed - go from first
readMapCycle(g_mapCycle, g_nextMap, 31)
set_cvar_string("amx_nextmap", g_nextMap)
format(szString3, 31, "%s %d", g_mapCycle, g_pos) // save lastmapcycle settings
set_localinfo("lastmapcycle", szString3)
}
getNextMapName(szArg[], iMax)
{
new len = get_cvar_string("amx_nextmap", szArg, iMax)
if (ValidMap(szArg)) return len
len = copy(szArg, iMax, g_nextMap)
set_cvar_string("amx_nextmap", g_nextMap)
return len
}
public sayNextMap()
{
new name[32]
getNextMapName(name, 31)
client_print(0, print_chat, "%L %s", LANG_PLAYER, "NEXT_MAP", name)
}
public sayCurrentMap()
{
new mapname[32]
get_mapname(mapname, 31)
client_print(0, print_chat, "%L: %s", LANG_PLAYER, "PLAYED_MAP", mapname)
}
public sayFFStatus()
{
client_print(0, print_chat, "%L: %L", LANG_PLAYER, "FRIEND_FIRE", LANG_PLAYER, get_cvar_num("mp_friendlyfire") ? "ON" : "OFF")
}
public delayedChange(param[])
{
set_cvar_float("mp_chattime", get_cvar_float("mp_chattime") - 2.0)
server_cmd("changelevel %s", param)
}
public changeMap()
{
new string[32]
new Float:chattime = get_cvar_float("mp_chattime")
set_cvar_float("mp_chattime", chattime + 2.0) // make sure mp_chattime is long
new len = getNextMapName(string, 31) + 1
set_task(chattime, "delayedChange", 0, string, len) // change with 1.5 sec. delay
}
new g_warning[] = "WARNING: Couldn't find a valid map or the file doesn't exist (file ^"%s^")"
stock bool:ValidMap(mapname[])
{
if ( is_map_valid(mapname) )
{
return true;
}
// If the is_map_valid check failed, check the end of the string
new len = strlen(mapname) - 4;
// The mapname was too short to possibly house the .bsp extension
if (len < 0)
{
return false;
}
if ( equali(mapname[len], ".bsp") )
{
// If the ending was .bsp, then cut it off.
// the string is byref'ed, so this copies back to the loaded text.
mapname[len] = '^0';
// recheck
if ( is_map_valid(mapname) )
{
return true;
}
}
return false;
}
#if defined OBEY_MAPCYCLE
readMapCycle(szFileName[], szNext[], iNext)
{
new b, i = 0, iMaps = 0
new szBuffer[32], szFirst[32]
if (file_exists(szFileName))
{
while (read_file(szFileName, i++, szBuffer, 31, b))
{
if (!isalnum(szBuffer[0]) || !ValidMap(szBuffer)) continue
if (!iMaps)
copy(szFirst, 31, szBuffer)
if (++iMaps > g_pos)
{
copy(szNext, iNext, szBuffer)
g_pos = iMaps
return
}
}
}
if (!iMaps)
{
log_amx(g_warning, szFileName)
get_mapname(szFirst, 31)
}
copy(szNext, iNext, szFirst)
g_pos = 1
}
#else
readMapCycle(szFileName[], szNext[], iNext)
{
new b, i = 0, iMaps = 0
new szBuffer[32], szFirst[32], szCurrent[32]
get_mapname(szCurrent, 31)
new a = g_pos
if (file_exists(szFileName))
{
while (read_file(szFileName, i++, szBuffer, 31, b))
{
if (!isalnum(szBuffer[0]) || !ValidMap(szBuffer)) continue
if (!iMaps)
{
iMaps = 1
copy(szFirst, 31, szBuffer)
}
if (iMaps == 1)
{
if (equali(szCurrent, szBuffer))
{
if (a-- == 0)
iMaps = 2
}
} else {
if (equali(szCurrent, szBuffer))
++g_pos
else
g_pos = 0
copy(szNext, iNext, szBuffer)
return
}
}
}
if (!iMaps)
{
log_amx(g_warning, szFileName)
copy(szNext, iNext, szCurrent)
}
else
copy(szNext, iNext, szFirst)
g_pos = 0
}
#endif
Code: Select all
#include <amxmodx>
#include <amxmisc>
#define SPEED 0.3
#define SCROLLMSG_SIZE 512
new g_startPos
new g_endPos
new g_scrollMsg[SCROLLMSG_SIZE]
new g_displayMsg[SCROLLMSG_SIZE]
new Float:g_xPos
new g_Length
new g_Frequency
public plugin_init()
{
register_plugin("Scrolling Message", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("scrollmsg.txt")
register_dictionary("common.txt")
register_srvcmd("amx_scrollmsg", "setMessage")
}
public showMsg()
{
new a = g_startPos, i = 0
while (a < g_endPos)
g_displayMsg[i++] = g_scrollMsg[a++]
g_displayMsg[i] = 0
if (g_endPos < g_Length)
g_endPos++
if (g_xPos > 0.35)
g_xPos -= 0.0063
else
{
g_startPos++
g_xPos = 0.35
}
set_hudmessage(200, 100, 0, g_xPos, 0.90, 0, SPEED, SPEED, 0.05, 0.05, 2)
show_hudmessage(0, "%s", g_displayMsg)
}
public msgInit()
{
g_endPos = 1
g_startPos = 0
g_xPos = 0.65
new hostname[64]
get_cvar_string("hostname", hostname, 63)
replace(g_scrollMsg, SCROLLMSG_SIZE-1, "%hostname%", hostname)
g_Length = strlen(g_scrollMsg)
set_task(SPEED, "showMsg", 123, "", 0, "a", g_Length + 48)
client_print(0, print_console, "%s", g_scrollMsg)
}
public setMessage()
{
remove_task(123) /* remove current messaging */
read_argv(1, g_scrollMsg, SCROLLMSG_SIZE-1)
g_Length = strlen(g_scrollMsg)
new mytime[32]
read_argv(2, mytime, 31)
g_Frequency = str_to_num(mytime)
if (g_Frequency > 0)
{
new minimal = floatround((g_Length + 48) * (SPEED + 0.1))
if (g_Frequency < minimal)
{
server_print("%L", LANG_SERVER, "MIN_FREQ", minimal)
g_Frequency = minimal
}
server_print("%L", LANG_SERVER, "MSG_FREQ", g_Frequency / 60, g_Frequency % 60)
set_task(float(g_Frequency), "msgInit", 123, "", 0, "b")
}
else
server_print("%L", LANG_SERVER, "MSG_DISABLED")
return PLUGIN_HANDLED
}
Code: Select all
#include <amxmodx>
#include <amxmisc>
#define SPEED 0.3
#define SCROLLMSG_SIZE 512
new g_startPos
new g_endPos
new g_scrollMsg[SCROLLMSG_SIZE]
new g_displayMsg[SCROLLMSG_SIZE]
new Float:g_xPos
new g_Length
new g_Frequency
public plugin_init()
{
register_plugin("Scrolling Message", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("scrollmsg.txt")
register_dictionary("common.txt")
register_srvcmd("amx_scrollmsg", "setMessage")
}
public showMsg()
{
new a = g_startPos, i = 0
while (a < g_endPos)
g_displayMsg[i++] = g_scrollMsg[a++]
g_displayMsg[i] = 0
if (g_endPos < g_Length)
g_endPos++
if (g_xPos > 0.35)
g_xPos -= 0.0063
else
{
g_startPos++
g_xPos = 0.35
}
set_hudmessage(200, 100, 0, g_xPos, 0.90, 0, SPEED, SPEED, 0.05, 0.05, 2)
show_hudmessage(0, "%s", g_displayMsg)
}
public msgInit()
{
g_endPos = 1
g_startPos = 0
g_xPos = 0.65
new hostname[64]
get_cvar_string("hostname", hostname, 63)
replace(g_scrollMsg, SCROLLMSG_SIZE-1, "%hostname%", hostname)
g_Length = strlen(g_scrollMsg)
set_task(SPEED, "showMsg", 123, "", 0, "a", g_Length + 48)
client_print(0, print_console, "%s", g_scrollMsg)
}
public setMessage()
{
remove_task(123) /* remove current messaging */
read_argv(1, g_scrollMsg, SCROLLMSG_SIZE-1)
g_Length = strlen(g_scrollMsg)
new mytime[32]
read_argv(2, mytime, 31)
g_Frequency = str_to_num(mytime)
if (g_Frequency > 0)
{
new minimal = floatround((g_Length + 48) * (SPEED + 0.1))
if (g_Frequency < minimal)
{
server_print("%L", LANG_SERVER, "MIN_FREQ", minimal)
g_Frequency = minimal
}
server_print("%L", LANG_SERVER, "MSG_FREQ", g_Frequency / 60, g_Frequency % 60)
set_task(float(g_Frequency), "msgInit", 123, "", 0, "b")
}
else
server_print("%L", LANG_SERVER, "MSG_DISABLED")
return PLUGIN_HANDLED
}
Code: Select all
#include <amxmodx>
new g_TimeSet[32][2]
new g_LastTime
new g_CountDown
new g_Switch
public plugin_init()
{
register_plugin("TimeLeft", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("timeleft.txt")
register_cvar("amx_time_voice", "1")
register_srvcmd("amx_time_display", "setDisplaying")
register_cvar("amx_timeleft", "00:00", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
register_clcmd("say timeleft", "sayTimeLeft", 0, "- displays timeleft")
register_clcmd("say thetime", "sayTheTime", 0, "- displays current time")
set_task(0.8, "timeRemain", 8648458, "", 0, "b")
}
public sayTheTime(id)
{
if (get_cvar_num("amx_time_voice"))
{
new mhours[6], mmins[6], whours[32], wmins[32], wpm[6]
get_time("%H", mhours, 5)
get_time("%M", mmins, 5)
new mins = str_to_num(mmins)
new hrs = str_to_num(mhours)
if (mins)
num_to_word(mins, wmins, 31)
else
wmins[0] = 0
if (hrs < 12)
wpm = "am "
else
{
if (hrs > 12) hrs -= 12
wpm = "pm "
}
if (hrs)
num_to_word(hrs, whours, 31)
else
whours = "twelve "
client_cmd(id, "spk ^"fvox/time_is_now %s_period %s%s^"", whours, wmins, wpm)
}
new ctime[64]
get_time("%m/%d/%Y - %H:%M:%S", ctime, 63)
client_print(0, print_chat, "%L: %s", LANG_PLAYER, "THE_TIME", ctime)
return PLUGIN_CONTINUE
}
public sayTimeLeft(id)
{
if (get_cvar_float("mp_timelimit"))
{
new a = get_timeleft()
if (get_cvar_num("amx_time_voice"))
{
new svoice[128]
setTimeVoice(svoice, 127, 0, a)
client_cmd(id, "%s", svoice)
}
client_print(0, print_chat, "%L: %d:%02d", LANG_PLAYER, "TIME_LEFT", (a / 60), (a % 60))
}
else
client_print(0, print_chat, "%L", LANG_PLAYER, "NO_T_LIMIT")
return PLUGIN_CONTINUE
}
setTimeText(text[], len, tmlf, id)
{
new secs = tmlf % 60
new mins = tmlf / 60
if (secs == 0)
format(text, len, "%d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE")
else if (mins == 0)
format(text, len, "%d %L", secs, id, (secs > 1) ? "SECONDS" : "SECOND")
else
format(text, len, "%d %L %d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE", secs, id, (secs > 1) ? "SECONDS" : "SECOND")
}
setTimeVoice(text[], len, flags, tmlf)
{
new temp[7][32]
new secs = tmlf % 60
new mins = tmlf / 60
for (new a = 0;a < 7;++a)
temp[a][0] = 0
if (secs > 0)
{
num_to_word(secs, temp[4], 31)
if (!(flags & 8))
temp[5] = "seconds " /* there is no "second" in default hl */
}
if (mins > 59)
{
new hours = mins / 60
num_to_word(hours, temp[0], 31)
if (!(flags & 8))
temp[1] = "hours "
mins = mins % 60
}
if (mins > 0)
{
num_to_word(mins, temp[2], 31)
if (!(flags & 8))
temp[3] = "minutes "
}
if (!(flags & 4))
temp[6] = "remaining "
return format(text, len, "spk ^"vox/%s%s%s%s%s%s%s^"", temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6])
}
findDispFormat(time)
{
for (new i = 0; g_TimeSet[i][0]; ++i)
{
if (g_TimeSet[i][1] & 16)
{
if (g_TimeSet[i][0] > time)
{
if (!g_Switch)
{
g_CountDown = g_Switch = time
remove_task(8648458)
set_task(1.0, "timeRemain", 34543, "", 0, "b")
}
return i
}
}
else if (g_TimeSet[i][0] == time)
{
return i
}
}
return -1
}
public setDisplaying()
{
new arg[32], flags[32], num[32]
new argc = read_argc() - 1
new i = 0
while (i < argc && i < 32)
{
read_argv(i + 1, arg, 31)
parse(arg, flags, 31, num, 31)
g_TimeSet[i][0] = str_to_num(num)
g_TimeSet[i][1] = read_flags(flags)
i++
}
g_TimeSet[i][0] = 0
return PLUGIN_HANDLED
}
public timeRemain(param[])
{
new gmtm = get_timeleft()
new tmlf = g_Switch ? --g_CountDown : gmtm
new stimel[12]
format(stimel, 11, "%02d:%02d", gmtm / 60, gmtm % 60)
set_cvar_string("amx_timeleft", stimel)
if (g_Switch && gmtm > g_Switch)
{
remove_task(34543)
g_Switch = 0
set_task(0.8, "timeRemain", 8648458, "", 0, "b")
return
}
if (tmlf > 0 && g_LastTime != tmlf)
{
g_LastTime = tmlf
new tm_set = findDispFormat(tmlf)
if (tm_set != -1)
{
new flags = g_TimeSet[tm_set][1]
new arg[128]
if (flags & 1)
{
new players[32], pnum
get_players(players, pnum, "c")
for (new i = 0; i < pnum; i++)
{
setTimeText(arg, 127, tmlf, players[i])
if (flags & 16)
set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 1.1, 0.1, 0.5, -1)
else
set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 3.0, 0.0, 0.5, -1)
show_hudmessage(players[i], "%s", arg)
}
}
if (flags & 2)
{
setTimeVoice(arg, 127, flags, tmlf)
client_cmd(0, "%s", arg)
}
}
}
}
Multumesc ExtreamCS anticipat.