added more api to help with amxmod compat layer

cleaned up some more bcompat stuff
This commit is contained in:
David Anderson
2006-09-12 07:59:56 +00:00
parent 4f8917ec44
commit 651c5d9f01
7 changed files with 318 additions and 16 deletions

View File

@ -24,7 +24,7 @@ new g_MaxPlayers
public plugin_init()
{
register_plugin("AMX Mod Compat Engine", AMXX_VERSION_STR, "AMXX Dev Team")
register_plugin("AMX Mod Compat Engine", "1.76.rc4", "AMXX Dev Team")
g_MaxPlayers = get_maxplayers()

View File

@ -27,6 +27,11 @@ Core_Natives()
register_native("fpower", "__fpower")
register_native("flog", "__flog")
register_native("get_cmdaccess", "__get_cmdaccess")
register_native("is_translated", "__is_translated")
register_native("get_plugincmdsnum", "__get_plugincmdsnum")
register_native("get_plugincmd", "__get_plugincmd")
register_native("get_plugincvarsnum", "__get_plugincvarsnum")
register_native("get_plugincvar", "__get_plugincvar")
}
public __VelocityByAim(plid, num)
@ -185,7 +190,7 @@ public Float:__flog(plid, num)
//get_cmdaccess(cmd[], accessflags[], len)
public __get_cmdaccess(plid, num)
{
new command[32], accessflags[32]
static command[32], accessflags[32]
new ret
get_string(1, command, 31)
@ -197,3 +202,80 @@ public __get_cmdaccess(plid, num)
return ret
}
public __is_translated(plid, num)
{
static string[512]
get_string(1, string, 511)
return is_translated(string)
}
public __get_plugincmdsnum(plid, num)
{
static plugin[64]
get_string(1, plugin, 63)
return get_plugincmdsnum(plugin, get_param(2))
}
public __get_plugincmd(plid, num)
{
static plugin[64]
static command[32]
static accessflags[32]
static info[512]
get_string(1, plugin, 63)
if (get_plugincmd(plugin,
get_param(2),
command,
31,
accessflags,
31,
info,
511,
get_param(9),
get_param(10)))
{
set_string(3, command, get_param(4))
set_string(5, accessflags, get_param(6))
set_string(7, info, get_param(8))
return 1
}
return 0
}
public __get_plugincvarsnum(plid, num)
{
static plugin[64]
get_string(1, plugin, 63)
return get_plugincvarsnum(plugin, get_param(2))
}
//stock get_plugincvar(plugin[], index, cvar[], len1, value[], len2, flags=0)
public __get_plugincvar(plid, num)
{
static plugin[64]
static cvar[32]
static value[512]
get_string(1, plugin, 63)
if (get_plugincvar(plugin, get_param(2), cvar, 31, value, 511, get_param(7)))
{
set_string(3, cvar, get_param(4))
set_string(5, value, get_param(6))
return 1
}
return 0
}

View File

@ -54,7 +54,7 @@ stock strtonum(const string[])
stock build_path(path[], len, {Float,_}:... )
{
format_args(path, len, 2)
format_args(path, len, 2);
new pathlen = strlen(path);
new basedir[32];
if (containi(path, "$basedir") != -1)
@ -66,22 +66,22 @@ stock build_path(path[], len, {Float,_}:... )
}
if ((pathlen+strlen(basedir)-strlen("$basedir")) < len)
{
replace(path, len, "$basedir", basedir)
replace(path, len, "$basedir", basedir);
}
}
new dir[64], subdir[63];
if (containi(path, "$configdir") != -1)
{
get_localinfo("amxx_configsdir", dir, 63)
get_localinfo("amxx_configsdir", dir, 63);
if (!dir[0])
{
format(dir, 63, "%s/configs", basedir)
format(dir, 63, "%s/configs", basedir);
}
if ((pathlen+strlen(basedir)-strlen("$configdir")) < len)
{
replace(path, len, "$configdir", dir)
replace(path, len, "$configdir", dir);
}
dir[0] = '^0'
dir[0] = '^0';
}
if (containi(path, "$langdir") != -1)
{
@ -95,7 +95,7 @@ stock build_path(path[], len, {Float,_}:... )
{
replace(path, len, "$langdir", dir);
}
dir[0] = '^0''
dir[0] = '^0';
}
if (containi(path, "$modulesdir") != -1)
{
@ -128,14 +128,14 @@ stock build_path(path[], len, {Float,_}:... )
get_localinfo("amx_logs", dir, 63);
if (!dir[0])
{
format(dir, 63, "%s/logs", basedir)
format(dir, 63, "%s/logs", basedir);
}
if ((pathlen+strlen(basedir)-strlen("$logdir")) < len)
{
replace(path, len, "$logdir", dir);
}
}
return 1
return 1;
}
stock is_user_authorized(id)
@ -161,7 +161,7 @@ stock angle_to_vector(Float:vector[3], FRU, Float:ret[3])
return angle_vector(vector, FRU, ret);
}
get_cmdaccess(cmd[], accessflags[], len)
stock get_cmdaccess(cmd[], accessflags[], len)
{
new num = get_concmdsnum(-1);
new command[32], info[3];
@ -179,3 +179,120 @@ get_cmdaccess(cmd[], accessflags[], len)
return 0;
}
stock is_translated(const sentence[])
{
return (GetLangTransKey(sentence) != TransKey_Bad);
}
stock get_plugincmdsnum(plugin[], type=7)
{
new plid = find_plugin_byfile(plugin);
new our_type;
/**
* Whoever wrote this was a bit confused about the type stuff...
*/
if (type == 1) {
our_type = 1;
} else if (type == 4) {
our_type = 0;
} else {
our_type = -1;
}
new found = 0;
new total = get_concmdsnum(-1, our_type);
for (new i=0; i<total; i++)
{
if (plid == get_concmd_plid(i, -1, our_type))
{
found++;
}
}
return found;
}
stock get_plugincmd(plugin[], index, cmd[], len1, accessflags[], len2, info[], len3, destid=-1, type=7)
{
new plid = find_plugin_byfile(plugin);
new our_type;
/**
* Whoever wrote this was a bit confused about the type stuff...
*/
if (type == 1) {
our_type = 1;
} else if (type == 4) {
our_type = 0;
} else {
our_type = -1;
}
new found_iter = 0;
new total = get_concmdsnum(-1, our_type);
for (new i=0; i<total; i++)
{
if (plid == get_concmd_plid(i, -1, our_type))
{
if (found_iter == index)
{
new flags, result;
result = get_concmd(i, cmd, len1, flags, info, len3, -1, our_type);
get_flags(flags, accessflags, len2);
return result;
}
found_iter++;
}
}
/* get rid of a compiler warning */
destid = -1;
return (++destid);
}
stock get_plugincvar(plugin[], index, cvar[], len1, value[], len2, flags=0)
{
new plid = find_plugin_byfile(plugin);
new total = get_plugins_cvarsnum();
new cvar_flags, plugin_id, pcvar_handle;
new iter_id = 0;
for (new i=0; i<total; i++)
{
get_plugins_cvar(i, cvar, len1, cvar_flags, plugin_id, pcvar_handle);
if ((plugin_id == plid)
&& (!flags || (cvar_flags & flags)))
{
if (iter_id == index)
{
get_pcvar_string(pcvar_handle, value, len2);
return 1;
}
iter_id++;
}
}
return 0;
}
stock get_plugincvarsnum(plugin[], flags=0)
{
new plid = find_plugin_byfile(plugin);
new total = get_plugins_cvarsnum();
new cvar_flags, plugin_id;
new cvars_total = 0;
for (new i=0; i<total; i++)
{
get_plugins_cvar(i, "", 0, cvar_flags, plugin_id);
if ((plugin_id == plid)
&& (!flags || (cvar_flags & flags)))
{
cvars_total++;
}
}
return cvars_total;
}

View File

@ -497,9 +497,18 @@ then function returns only server cmds, if positive then
returns only client cmds. in other case returns all console commands. */
native get_concmd(index,cmd[],len1,&flags, info[],len2, flag, id = -1);
/* Gets the parent plugin id of a console command. */
native get_concmd_plid(cid, flag_mask, id_type);
/* Returns number of registered console commands. */
native get_concmdsnum(flag,id = -1);
/* Returns the number of plugin-registered cvars. */
native get_plugins_cvarsnum();
/* Returns information about a plugin-registered cvar. */
native get_plugins_cvar(num, name[], namelen, &flags=0, &plugin_id=0, &pcvar_handle=0);
/* Gets unique id of menu. Outside set to 1 allows
* to catch menus outside a plugin where register_menuid is called. */
native register_menuid(const menu[], outside=0 );
@ -588,8 +597,10 @@ native get_modulesnum();
native is_plugin_loaded(const name[]);
/* Gets info about plugin by given index.
* Function returns -1 if plugin doesn't exist with given index. */
native get_plugin(index,filename[],len1,name[],len2,version[],len3,author[],len4,status[],len5);
* Function returns -1 if plugin doesn't exist with given index.
* Note: the [...] portion should not be used, and is only for backward compatibility.
*/
native get_plugin(index,filename[],len1,name[],len2,version[],len3,author[],len4,status[],len5,...);
/* Returns number of all loaded plugins. */
native get_pluginsnum();

View File

@ -25,11 +25,22 @@ native register_dictionary(const filename[]);
//returns 1 if the language is loaded, 0 otherwise.
native lang_exists(const name[]);
enum TransKey
{
TransKey_Bad = -1,
};
/**
* Adds or finds a translation key.
*/
native TransKey:CreateLangKey(const key[]);
/**
* Finds a translation key id without adding on failure.
* Returns -1 on not found.
*/
native TransKey:GetLangTransKey(const key[]);
/**
* Adds a translation.
*/