21.03.2013, 23:06
(
Последний раз редактировалось xeeZ; 22.03.2013 в 10:03.
Причина: my English sucks
)
For anyone interested in calling natives in other plugins: I wrote a convenient function that does the argument conversion for you pushing and popping the arguments (and releasing if necessary) automatically:
https://gist.github.com/Zeex/5217723
Supported argument types are: float, const char* (C-strings), std:tring (C++ strings) and anything that implicitly converts to cell (all integral types including cell itself). You can extend it to support more types by specializing the NativeArgument class template.
Usage:
CallNative() supports up to 9 arguments but it's pretty easy to add more if you need, just add a new overload with more parameters.
Be careful passing long strings or anything that may not fit in the AMX heap/stack, which is by default 4096 bytes (can be increased with #pragma dynamic).
By the way, instead of passing a pointer to a real AMX you can use the FakeAmx class from earlier versions of GDK which can be found here:
https://github.com/Zeex/sampgdk/blob/v2.x/src/fakeamx.h
https://github.com/Zeex/sampgdk/blob...rc/fakeamx.cpp
FakeAmx will resize its heap dynamically as needed so you won't ever run out of space.
https://gist.github.com/Zeex/5217723
Supported argument types are: float, const char* (C-strings), std:tring (C++ strings) and anything that implicitly converts to cell (all integral types including cell itself). You can extend it to support more types by specializing the NativeArgument class template.
Usage:
pawn Код:
#include "call_native.h"
bool MySendClientMessage(int playerid, int color, const char *message) {
static AMX_NATIVE native = FindNative("SendClientMessage");
return CallNative<bool>(YouAmxHere, native, playerid, 0x0000FFFF, message);
}
Be careful passing long strings or anything that may not fit in the AMX heap/stack, which is by default 4096 bytes (can be increased with #pragma dynamic).
By the way, instead of passing a pointer to a real AMX you can use the FakeAmx class from earlier versions of GDK which can be found here:
https://github.com/Zeex/sampgdk/blob/v2.x/src/fakeamx.h
https://github.com/Zeex/sampgdk/blob...rc/fakeamx.cpp
FakeAmx will resize its heap dynamically as needed so you won't ever run out of space.