2004-02-08 11:31:54 +00:00
|
|
|
/* AMX Mod X misc.
|
|
|
|
*
|
2004-02-21 20:30:04 +00:00
|
|
|
* by the AMX Mod X Development Team
|
|
|
|
* originally developed by OLO
|
2004-02-08 11:31:54 +00:00
|
|
|
*
|
|
|
|
* This file is provided as is (no warranties).
|
|
|
|
*/
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-02-21 20:30:04 +00:00
|
|
|
#if defined _amxmisc_included
|
|
|
|
#endinput
|
|
|
|
#endif
|
|
|
|
#define _amxmisc_included
|
|
|
|
|
2007-02-19 07:03:26 +00:00
|
|
|
#if !defined _amxmodx_included
|
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
#include <amxmod>
|
|
|
|
#else
|
|
|
|
#include <amxmodx>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2006-09-01 03:29:27 +00:00
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
#if defined _translator_included
|
|
|
|
#define SIMPLE_T(%1) _T(%1)
|
|
|
|
#else
|
|
|
|
#define SIMPLE_T(%1) %1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-10-03 06:23:25 +00:00
|
|
|
stock is_user_admin(id)
|
|
|
|
{
|
|
|
|
return ( get_user_flags(id)>0 && !(get_user_flags(id)&ADMIN_USER) )
|
|
|
|
}
|
|
|
|
|
2004-02-15 02:29:51 +00:00
|
|
|
stock cmd_access(id,level,cid,num) {
|
2004-07-24 11:02:49 +00:00
|
|
|
new has_access = 0
|
|
|
|
if ( id==(is_dedicated_server()?0:1) ) {
|
|
|
|
has_access = 1
|
2004-10-03 06:23:25 +00:00
|
|
|
} else if ( level==ADMIN_ADMIN ) {
|
2004-07-24 11:02:49 +00:00
|
|
|
if ( is_user_admin(id) )
|
|
|
|
has_access = 1
|
2004-10-03 06:23:25 +00:00
|
|
|
} else if ( get_user_flags(id) & level ) {
|
2004-07-24 11:02:49 +00:00
|
|
|
has_access = 1
|
2004-10-03 06:23:25 +00:00
|
|
|
} else if (level == ADMIN_ALL) {
|
|
|
|
has_access = 1
|
2004-07-24 11:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( has_access==0 ) {
|
2006-09-01 03:29:27 +00:00
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
console_print(id, SIMPLE_T("You have no access to that command."))
|
|
|
|
#else
|
2004-08-06 18:40:59 +00:00
|
|
|
console_print(id,"%L",id,"NO_ACC_COM")
|
2006-09-01 03:29:27 +00:00
|
|
|
#endif
|
2004-02-15 02:29:51 +00:00
|
|
|
return 0
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
2004-02-08 11:31:54 +00:00
|
|
|
if (read_argc() < num) {
|
2004-01-31 20:56:22 +00:00
|
|
|
new hcmd[32], hinfo[128], hflag
|
2004-02-08 11:31:54 +00:00
|
|
|
get_concmd(cid,hcmd,31,hflag,hinfo,127,level)
|
2006-09-01 03:29:27 +00:00
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
console_print(id, SIMPLE_T("Usage: %s %s"), hcmd, SIMPLE_T(hinfo))
|
|
|
|
#else
|
2004-08-06 18:40:59 +00:00
|
|
|
console_print(id,"%L: %s %s",id,"USAGE",hcmd,hinfo)
|
2006-09-01 03:29:27 +00:00
|
|
|
#endif
|
2004-02-15 02:29:51 +00:00
|
|
|
return 0
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
2004-02-15 02:29:51 +00:00
|
|
|
return 1
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2004-07-24 11:02:49 +00:00
|
|
|
stock access(id,level) {
|
|
|
|
if ( level==ADMIN_ADMIN )
|
|
|
|
return is_user_admin(id)
|
2004-07-31 01:00:20 +00:00
|
|
|
|
|
|
|
return (get_user_flags(id) & level)
|
2004-07-24 11:02:49 +00:00
|
|
|
}
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
/* Flags:
|
2004-02-21 20:30:04 +00:00
|
|
|
* 1 - obey immunity
|
|
|
|
* 2 - allow yourself
|
|
|
|
* 4 - must be alive
|
|
|
|
* 8 - can't be bot */
|
2004-01-31 20:56:22 +00:00
|
|
|
stock cmd_target(id,const arg[],flags = 1) {
|
|
|
|
new player = find_player("bl",arg)
|
2004-02-08 11:31:54 +00:00
|
|
|
if (player) {
|
|
|
|
if ( player != find_player("blj",arg) ) {
|
2006-09-01 03:29:27 +00:00
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
console_print(id, SIMPLE_T("There are more clients matching to your argument"))
|
|
|
|
#else
|
2004-08-06 18:40:59 +00:00
|
|
|
console_print(id,"%L",id,"MORE_CL_MATCHT")
|
2006-09-01 03:29:27 +00:00
|
|
|
#endif
|
2005-01-15 09:58:51 +00:00
|
|
|
return 0
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( ( player = find_player("c",arg) )==0 && arg[0]=='#' && arg[1] )
|
2005-01-15 09:58:51 +00:00
|
|
|
player = find_player("k",str_to_num(arg[1]))
|
2004-02-08 11:31:54 +00:00
|
|
|
if (!player) {
|
2006-09-01 03:29:27 +00:00
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
console_print(id, SIMPLE_T("Client with that name or userid not found"))
|
|
|
|
#else
|
2004-08-06 18:40:59 +00:00
|
|
|
console_print(id,"%L",id,"CL_NOT_FOUND")
|
2006-09-01 03:29:27 +00:00
|
|
|
#endif
|
2004-01-31 20:56:22 +00:00
|
|
|
return 0
|
|
|
|
}
|
2004-02-08 11:31:54 +00:00
|
|
|
if (flags & 1) {
|
|
|
|
if ((get_user_flags(player)&ADMIN_IMMUNITY) && ((flags&2)?(id!=player):true) ) {
|
2004-01-31 20:56:22 +00:00
|
|
|
new imname[32]
|
|
|
|
get_user_name(player,imname,31)
|
2006-09-01 03:29:27 +00:00
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
console_print(id, SIMPLE_T("Client ^"%s^" has immunity"), imname)
|
|
|
|
#else
|
2004-08-06 18:40:59 +00:00
|
|
|
console_print(id,"%L",id,"CLIENT_IMM",imname)
|
2006-09-01 03:29:27 +00:00
|
|
|
#endif
|
2004-01-31 20:56:22 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
2004-02-08 11:31:54 +00:00
|
|
|
if (flags & 4) {
|
|
|
|
if (!is_user_alive(player)) {
|
2004-01-31 20:56:22 +00:00
|
|
|
new imname[32]
|
2005-01-15 09:58:51 +00:00
|
|
|
get_user_name(player,imname,31)
|
2006-09-01 03:29:27 +00:00
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
console_print(id, SIMPLE_T("That action can't be performed on dead client ^"%s^""), imname)
|
|
|
|
#else
|
2004-08-06 18:40:59 +00:00
|
|
|
console_print(id,"%L",id,"CANT_PERF_DEAD",imname)
|
2006-09-01 03:29:27 +00:00
|
|
|
#endif
|
2004-01-31 20:56:22 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
2004-02-08 11:31:54 +00:00
|
|
|
if (flags & 8) {
|
|
|
|
if (is_user_bot(player)) {
|
2004-01-31 20:56:22 +00:00
|
|
|
new imname[32]
|
2005-01-15 09:58:51 +00:00
|
|
|
get_user_name(player,imname,31)
|
2006-09-01 03:29:27 +00:00
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
console_print(id, SIMPLE_T("That action can't be performed on bot ^"%s^""), imname)
|
|
|
|
#else
|
2004-08-06 18:40:59 +00:00
|
|
|
console_print(id,"%L",id,"CANT_PERF_BOT",imname)
|
2006-09-01 03:29:27 +00:00
|
|
|
#endif
|
2004-01-31 20:56:22 +00:00
|
|
|
return 0
|
2005-01-15 09:58:51 +00:00
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
return player
|
|
|
|
}
|
|
|
|
|
2004-02-08 11:31:54 +00:00
|
|
|
stock show_activity( id, const name[], {Float,_}: ... ) {
|
2004-01-31 20:56:22 +00:00
|
|
|
new buffer[128]
|
2004-02-08 11:31:54 +00:00
|
|
|
format_args( buffer , 127 , 2 )
|
2006-09-01 03:29:27 +00:00
|
|
|
switch(get_cvar_num("amx_show_activity"))
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
client_print(0, print_chat, "%s %s: %s", is_user_admin(id) ? SIMPLE_T("ADMIN") : SIMPLE_T("PLAYER"), name, buffer)
|
|
|
|
#else
|
|
|
|
client_print(0, print_chat, "%L %s: %s", id, is_user_admin(id) ? "ADMIN" : "PLAYER" , name , buffer )
|
|
|
|
#endif
|
|
|
|
case 1:
|
|
|
|
#if defined AMXMOD_BCOMPAT
|
|
|
|
client_print(0, print_chat, "%s: %s", is_user_admin(id) ? SIMPLE_T("ADMIN") : SIMPLE_T("PLAYER"), buffer)
|
|
|
|
#else
|
|
|
|
client_print(0, print_chat, "%L: %s", id, is_user_admin(id) ? "ADMIN" : "PLAYER", buffer )
|
|
|
|
#endif
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-27 16:42:59 +00:00
|
|
|
stock colored_menus() {
|
2004-01-31 20:56:22 +00:00
|
|
|
new mod_name[32]
|
|
|
|
get_modname(mod_name,31)
|
2004-07-26 15:07:25 +00:00
|
|
|
|
2004-07-27 16:42:59 +00:00
|
|
|
return ( equal(mod_name,"cstrike") || equal(mod_name,"czero") || equal(mod_name,"dod") )
|
2004-07-26 15:07:25 +00:00
|
|
|
}
|
|
|
|
|
2004-07-27 16:42:59 +00:00
|
|
|
stock cstrike_running() {
|
2004-07-26 15:07:25 +00:00
|
|
|
new mod_name[32]
|
|
|
|
get_modname(mod_name,31)
|
|
|
|
|
2004-07-27 21:06:36 +00:00
|
|
|
return ( equal(mod_name,"cstrike") || equal(mod_name,"czero") || equal(mod_name,"csv15") || equal(mod_name,"cs13") )
|
2004-07-27 16:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stock is_running(const mod[]) {
|
|
|
|
new mod_name[32]
|
|
|
|
get_modname(mod_name,31)
|
|
|
|
|
|
|
|
return equal(mod_name,mod)
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2004-03-25 13:34:27 +00:00
|
|
|
stock get_basedir(name[],len)
|
|
|
|
return get_localinfo("amxx_basedir",name,len)
|
|
|
|
|
|
|
|
stock get_configsdir(name[],len)
|
|
|
|
return get_localinfo("amxx_configsdir",name,len)
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-06-29 16:38:27 +00:00
|
|
|
stock get_datadir(name[],len)
|
|
|
|
return get_localinfo("amxx_datadir",name,len)
|
|
|
|
|
2007-01-26 05:56:10 +00:00
|
|
|
stock register_menu(const title[],keys,const function[],outside=0)
|
2004-07-31 01:00:20 +00:00
|
|
|
register_menucmd(register_menuid(title,outside),keys,function)
|
|
|
|
|
2004-06-29 16:38:27 +00:00
|
|
|
/* Backwards Compatibility
|
|
|
|
* don't use it! */
|
2004-03-25 13:34:27 +00:00
|
|
|
stock get_customdir(name[],len)
|
2004-10-08 08:36:54 +00:00
|
|
|
return get_localinfo("amxx_configsdir",name,len)
|
|
|
|
|
2005-01-15 09:58:51 +00:00
|
|
|
/* Add a menu item to Menus Front-End plugin ("amxmodmenu"):
|
2004-10-08 08:36:54 +00:00
|
|
|
* MENU_TEXT: Text that will be shown for this item in menu
|
|
|
|
* MENU_CMD: Command that should be executed to start menu
|
|
|
|
* MENU_ACCESS: Access required for menu
|
2005-01-15 09:58:51 +00:00
|
|
|
* MENU_PLUGIN: The exact case-insensitive name of plugin holding the menu command
|
2004-10-08 08:36:54 +00:00
|
|
|
*/
|
|
|
|
stock AddMenuItem(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[]) {
|
2005-01-15 09:58:51 +00:00
|
|
|
AddMenuItem_call(MENU_TEXT, MENU_CMD, MENU_ACCESS, MENU_PLUGIN, false)
|
|
|
|
}
|
|
|
|
/* Just like above, but add menu item to "amx_menu", that should also be accessible by non-admins.
|
|
|
|
*/
|
|
|
|
stock AddClientMenuItem(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[]) {
|
|
|
|
AddMenuItem_call(MENU_TEXT, MENU_CMD, MENU_ACCESS, MENU_PLUGIN, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Internal function used by above stocks.
|
|
|
|
stock AddMenuItem_call(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[], const bool:ADD_TO_CLIENT_MENU) {
|
2004-10-08 08:36:54 +00:00
|
|
|
new pluginid = is_plugin_loaded("Menus Front-End")
|
|
|
|
if (pluginid == -1) {
|
|
|
|
log_amx("Can't add menu item ^"%s^" from plugin ^"%s^" to menu set because the Menus Front-End plugin itself is not loaded!", MENU_TEXT, MENU_PLUGIN)
|
|
|
|
return // Menus Front-End doesn't exist, return.
|
|
|
|
}
|
|
|
|
|
2004-10-08 08:59:04 +00:00
|
|
|
new filename[64], b[1]
|
|
|
|
get_plugin(pluginid, filename, 63, b, 0, b, 0, b, 0, b, 0)
|
2004-10-08 08:36:54 +00:00
|
|
|
|
2005-01-15 09:58:51 +00:00
|
|
|
new status = callfunc_begin(ADD_TO_CLIENT_MENU ? "AddClientMenu" : "AddMenu", filename)
|
2004-10-08 08:36:54 +00:00
|
|
|
new bool:failed = true
|
|
|
|
switch (status) {
|
|
|
|
case 1: failed = false
|
2005-01-15 12:24:14 +00:00
|
|
|
case 0: log_amx("Run time error! (AddMenuItem_call failed)")
|
|
|
|
case -2: log_amx("Function not found! (AddMenuItem_call failed)")
|
|
|
|
case -1: log_amx("Plugin not found! (AddMenuItem_call failed)")
|
2004-10-08 08:36:54 +00:00
|
|
|
}
|
|
|
|
if (failed)
|
|
|
|
return
|
2004-10-08 08:53:27 +00:00
|
|
|
// Item text
|
2004-10-08 08:36:54 +00:00
|
|
|
callfunc_push_str(MENU_TEXT)
|
|
|
|
// Cmd
|
|
|
|
callfunc_push_str(MENU_CMD)
|
|
|
|
// Access
|
|
|
|
callfunc_push_int(MENU_ACCESS)
|
2004-10-08 08:53:27 +00:00
|
|
|
// Menu exists in this plugin
|
2004-10-08 08:36:54 +00:00
|
|
|
callfunc_push_str(MENU_PLUGIN)
|
|
|
|
|
|
|
|
callfunc_end()
|
2005-03-30 11:37:41 +00:00
|
|
|
}
|
2005-09-08 15:24:28 +00:00
|
|
|
|
|
|
|
|
2005-09-08 15:29:31 +00:00
|
|
|
stock constraint_offset(low, high, seed, offset)
|
2005-09-08 15:24:28 +00:00
|
|
|
{
|
|
|
|
new numElements = high - low + 1;
|
|
|
|
offset += seed - low;
|
|
|
|
|
|
|
|
if (offset >= 0)
|
|
|
|
return low + (offset % numElements);
|
|
|
|
else
|
|
|
|
return high - (abs(offset) % numElements) + 1;
|
|
|
|
return 0; // Makes the compiler happy -_-
|
|
|
|
}
|