One last feature was added today.
This is register_native, which lets you add natives with plugins. This was based on a never-completed concept by dJeyL. I have finished+implemented it at the request of T(+)rget.
Here is how it looks:
Code:
#include <amxmodx>
//I'd put these in an inc file or something <_<
native mynative(str[]);
native mynative2(str[]);
public plugin_init()
{
register_plugin("test", "1.0", "BAILOPAN")
register_srvcmd("test", "test")
register_srvcmd("test2", "test2")
}
//This is called before anything else, only these will work here.
public plugin_natives()
{
//Bail's method
register_native("mynative", "mynative_impl")
//dJeyL's method
register_native("mynative2", "mynative2_impl", 1)
}
public mynative2_impl(str[])
{
param_convert(1)
new num = str_to_num(str)
copy(str, 3, "XXX")
return num
}
public mynative_impl(id, numparams)
{
if (numparams != 1)
return log_error(10, "Bad native parameters")
new localstr[256]
get_string(1, localstr, 255)
set_string(1, "XXX", 3)
return str_to_num(localstr)
}
public test()
{
new str[10] = "123"
server_print("Result of my native: %d", mynative(str))
server_print("Modified: %s", str)
}
public test2()
{
new str[10] = "123"
server_print("Result of my native2: %d", mynative2(str))
server_print("Modified: %s", str)
}
This is very powerful, as it eliminates callfunc. You can now dynamically add natives to scripts!
__________________