25.03.2017, 21:06
(
Последний раз редактировалось WopsS; 25.03.2017 в 22:54.
)
Sorry for the double post, but here is a prototype for SetTimerEx.
or
The second one is better since you don't need total_arguments anymore.
You can use it like this:
At OnPublicCall I have this
For floats use amx_ctof(param[index]).
// The only problem is with the strings, I cannot manage to get them, but maybe I'm doing it wrong.
I managed to get the strings using sampgdk_fakeamx_get_string and handle a special case for s. Now SetTimerEx looks like
and OnPublicCall
At the top of the file add
The call:
I can't find another way to pass strings for this function.
P.S: You need to pass the length of the string if you want to get it back.
Код:
template<typename... Args> const int SetTimerEx(const std::string& func_name, const int interval, const bool repeating, const size_t total_arguments, const std::string& format, Args&& ...args) { static AMX_NATIVE native = sampgdk::FindNative("SetTimerEx"); return sampgdk::InvokeNative(native, (std::string("sibs") + std::string(total_arguments, 'r')).c_str(), func_name.c_str(), interval, repeating, format.c_str(), std::forward<Args>(args)...); }
Код:
template<typename... Args> const int SetTimerEx(const std::string& func_name, const int interval, const bool repeating, const std::string& format, Args&& ...args) { static AMX_NATIVE native = sampgdk::FindNative("SetTimerEx"); return sampgdk::InvokeNative(native, (std::string("sibs") + std::string(format.length(), 'r')).c_str(), func_name.c_str(), interval, repeating, format.c_str(), std::forward<Args>(args)...); }
You can use it like this:
Код:
int test = 10; int test2 = 20; int test3 = 30; SetTimerEx("TestTimer", 1000, true, 3, "iii", &test, &test2, &test3);
Код:
PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall(AMX *amx, const char *name, cell *params, cell *retval) { auto Name = std::string(name); if (Name == "TestTimer") { std::cout << "TestTimer(" << params[1] << ", " << params[2] << ", " << params[3] << ")" << std::endl; } return true; }
// The only problem is with the strings, I cannot manage to get them, but maybe I'm doing it wrong.
I managed to get the strings using sampgdk_fakeamx_get_string and handle a special case for s. Now SetTimerEx looks like
Код:
template<typename... Args> const int SetTimerEx(const std::string& func_name, const int interval, const bool repeating, const std::string& format, Args&& ...args) { static AMX_NATIVE native = sampgdk::FindNative("SetTimerEx"); std::string function_format = "sibs"; for (size_t i = 0; i < format.length(); i++) { function_format += format[i] == 's' ? "s" : "r"; } return sampgdk::InvokeNative(native, function_format.c_str(), func_name.c_str(), interval, repeating, format.c_str(), std::forward<Args>(args)...); }
Код:
PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall(AMX *amx, const char *name, cell *params, cell *retval) { auto Name = std::string(name); if (Name == "TestTimer") { char string[7]; sampgdk_fakeamx_get_string(params[5], string, params[4] + 1); std::cout << "TestTimer(" << params[1] << ", " << params[2] << ", " << amx_ctof(params[3]) << ", \"" << string << "\")" << std::endl; } return true; }
Код:
extern void sampgdk_fakeamx_get_string(cell address, char *dest, int size);
Код:
int test = 10; int test2 = 20; float test3 = 30.456f; std::string test4 = "Hello!"; size_t test4_length = test4.length(); SetTimerEx("TestTimer", 1000, true, "iifis", &test, &test2, &test3, &test4_length, test4.c_str());
P.S: You need to pass the length of the string if you want to get it back.