11.11.2012, 06:52
Thank you very much for tutorial,very useful for me!
#include "..\SDK\amx\amx.h" #include "..\SDK\plugincommon.h" #include "..\SDK\Invoke.h" typedef void (*logprintf_t)(char* format, ...); logprintf_t logprintf; extern void *pAMXFunctions; cell AMX_NATIVE_CALL HelloWorld(AMX* amx, cell* params) { logprintf("This was printed from the Test plugin! Yay!"); return 1; } PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() { return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES; } PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS]; logprintf = (logprintf_t) ppData[PLUGIN_DATA_LOGPRINTF]; logprintf(" * Test plugin was loaded."); return true; } PLUGIN_EXPORT void PLUGIN_CALL Unload() { logprintf(" * Test plugin was unloaded."); } cell AMX_NATIVE_CALL WhereIsPlayer(AMX* amx, cell* params) { float x = NULL, y = NULL, z = NULL; //Get the player's position (and check to see if he is even connected). if(g_Invoke->callNative(&PAWN::GetPlayerPos, params[1], &x, &y, &z)) { char name[24]; //Get the rest of the player's information (name, interior, and virtualworld) and print it. g_Invoke->callNative(&PAWN::GetPlayerName, params[1], name); int interior = g_Invoke->callNative(&PAWN::GetPlayerInterior, params[1]); int virtualworld = g_Invoke->callNative(&PAWN::GetPlayerVirtualWorld, params[1]); logprintf("%s is at X: %.2f, Y: %.2f, Z: %.2f (Virtual world: %d, Interior %d).", name, x, y, z, virtualworld, interior); return 1; } return 0; } AMX_NATIVE_INFO PluginNatives[] = { {"HelloWorld", HelloWorld}, {0, 0} }; PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx ) { return amx_Register(amx, PluginNatives, -1); } PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx ) { return AMX_ERR_NONE; }
Creando biblioteca Test\Debug\Test.lib and object Test\Debug\Test.exp Test.obj : error LNK2019: extern symbol "public: int __cdecl Invoke::callNative(struct PAWN::Native const *,...)" (?callNative@Invoke@@QAAHPBUNative@PAWN@@ZZ) unresolved external symbol referenced in function 'function' "long __cdecl WhereIsPlayer(struct tagAMX *,long *)" (?WhereIsPlayer@@YAJPAUtagAMX@@PAJ@Z) Test.obj : error LNK2001: sнmbolo externo "class Invoke * g_Invoke" (?g_Invoke@@3PAVInvoke@@A) unresolved external symbol Test\Debug\Test.dll : fatal error LNK1120: 2 unresolved external symbols ========== Generated: 0 corrects, 1 incorrect ==========
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
logprintf("A");
}
LIBRARY "WItem" EXPORTS Supports Load Unload AmxLoad AmxUnload ProcessTick
Originally Posted by Kyosaur
AmxLoad(AMX*):
This is called when a new AMX instance is loaded into the server. This will be called for every filterscript/gamemode! Because of this it isn't a good idea to store a single AMX instance for the entire plugin, instead use a queue/list/vector. In this function we also register our custom native functions we wish to provide PAWN with |
PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx)
{
AMX_HEADER* header = (AMX_HEADER*)amx->base;
AMX_NATIVE_INFO** natives = (AMX_NATIVE_INFO**)(header + header->natives);
int count = (header->libraries - header->natives) / header->defsize;
logprintf("%d native functions, header address %d, native table address %d", count, header, natives);
for(int i=0; i<count; i++)
logprintf("Native function %s, at index %d, address %d", natives[i]->name, i, natives[i]->func);
return 0;
}
This code:
Код:
#include "..\SDK\amx\amx.h" #include "..\SDK\plugincommon.h" #include "..\SDK\Invoke.h" typedef void (*logprintf_t)(char* format, ...); logprintf_t logprintf; extern void *pAMXFunctions; cell AMX_NATIVE_CALL HelloWorld(AMX* amx, cell* params) { logprintf("This was printed from the Test plugin! Yay!"); return 1; } PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() { return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES; } PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS]; logprintf = (logprintf_t) ppData[PLUGIN_DATA_LOGPRINTF]; logprintf(" * Test plugin was loaded."); return true; } PLUGIN_EXPORT void PLUGIN_CALL Unload() { logprintf(" * Test plugin was unloaded."); } cell AMX_NATIVE_CALL WhereIsPlayer(AMX* amx, cell* params) { float x = NULL, y = NULL, z = NULL; //Get the player's position (and check to see if he is even connected). if(g_Invoke->callNative(&PAWN::GetPlayerPos, params[1], &x, &y, &z)) { char name[24]; //Get the rest of the player's information (name, interior, and virtualworld) and print it. g_Invoke->callNative(&PAWN::GetPlayerName, params[1], name); int interior = g_Invoke->callNative(&PAWN::GetPlayerInterior, params[1]); int virtualworld = g_Invoke->callNative(&PAWN::GetPlayerVirtualWorld, params[1]); logprintf("%s is at X: %.2f, Y: %.2f, Z: %.2f (Virtual world: %d, Interior %d).", name, x, y, z, virtualworld, interior); return 1; } return 0; } AMX_NATIVE_INFO PluginNatives[] = { {"HelloWorld", HelloWorld}, {0, 0} }; PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx ) { return amx_Register(amx, PluginNatives, -1); } PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx ) { return AMX_ERR_NONE; } Код:
Creando biblioteca Test\Debug\Test.lib and object Test\Debug\Test.exp Test.obj : error LNK2019: extern symbol "public: int __cdecl Invoke::callNative(struct PAWN::Native const *,...)" (?callNative@Invoke@@QAAHPBUNative@PAWN@@ZZ) unresolved external symbol referenced in function 'function' "long __cdecl WhereIsPlayer(struct tagAMX *,long *)" (?WhereIsPlayer@@YAJPAUtagAMX@@PAJ@Z) Test.obj : error LNK2001: sнmbolo externo "class Invoke * g_Invoke" (?g_Invoke@@3PAVInvoke@@A) unresolved external symbol Test\Debug\Test.dll : fatal error LNK1120: 2 unresolved external symbols ========== Generated: 0 corrects, 1 incorrect ========== It's the same problem of: on page 6, here, on this tutorial. |
Could someone tell me where to find the following functions (which .h file?)
-amx_Register -amx_GetString -amx_GetAddr -amx_StrLen Thanks. |