[Tutorial] Plugin development guide

Try with just "amx\amx.h" (removing SDK\).

I also had the problem but that was solved doin this.
Reply

And, have you got the folder "SDK" in your project directory ?
Reply

Why I get this fail?
Code:
This was printed from the Test plugin! Yay ММММММММММММММММММММММММММММЃ\PЈLћі¶@!
Code:
cell AMX_NATIVE_CALL CheckUser(AMX* amx, cell* params)
{
	char name[24];
	g_Invoke->callNative(&PAWN::GetPlayerName, params[1], name);
	logprintf("This was printed from the Test plugin! Yay %s!",name);
	return 1;
}
Reply

I personally use sampGDK and it works correctly with this syntax :

pawn Code:
#include <sampgdk\a_players.h>

using sampgdk::logprintf;

#define AMX_DECLARE_NATIVE(native) \
            cell AMX_NATIVE_CALL native(AMX* amx, cell* params)

AMX_DECLARE_NATIVE(CheckUser)
{
      if(!IsPlayerConnected(params[1])) return logprintf("The user %d isn't connected !", params[1]), 1;
      char name[25];
      GetPlayerName(params[1], &name, 25);
      logprintf("This was printed from the Test plugin! Yay %s!", name);
      return 1;
}
Haven't ever used Invoke though, but it should be the same syntax (I think the problem comes from the fact you pass a variable where Invoke expects a pointer).
Reply

Quote:
Originally Posted by S4t3K
View Post
I personally use sampGDK and it works correctly with this syntax :

pawn Code:
#include <sampgdk\a_players.h>

using sampgdk::logprintf;

#define AMX_DECLARE_NATIVE(native) \
            cell AMX_NATIVE_CALL native(AMX* amx, cell* params)

AMX_DECLARE_NATIVE(CheckUser)
{
      if(!IsPlayerConnected(params[1])) return logprintf("The user %d isn't connected !", params[1]), 1;
      char name[25];
      GetPlayerName(params[1], &name, 25);
      logprintf("This was printed from the Test plugin! Yay %s!", name);
      return 1;
}
Haven't ever used Invoke though, but it should be the same syntax (I think the problem comes from the fact you pass a variable where Invoke expects a pointer).
Thanks, but I get this error:


(Reference to unresolved external symbol)

My Code:

Code:
#include "sampgdk/a_players.h"
#include "sampgdk/a_samp.h"
#include "sampgdk/core.h"
#include "sampgdk/sdk.h"


#include "Invoke.h"

#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
using sampgdk::logprintf;
typedef void(*logprintf_t)(char* format, ...);
extern void *pAMXFunctions;
using namespace std;

#define AMX_DECLARE_NATIVE(native) \
	cell AMX_NATIVE_CALL native(AMX* amx, cell* params)


PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() {

	return true;
}


/////////////////////////////////////


AMX_DECLARE_NATIVE(CheckUser)
{
	if (!IsPlayerConnected(params[1])) return printf("The user %d isn't connected !", params[1]), 1;
	char name[25];
	GetPlayerName(params[1], name, 25);
	printf("This was printed from the Test plugin! Yay %s!", name);
	return 1;
}

/////////////////////////////////////

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
{
	return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}

PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
{
	g_Invoke = new Invoke;
	pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];

	printf(" * plugin was loaded.");
	return true;
}

PLUGIN_EXPORT void PLUGIN_CALL Unload()
{
	printf(" * plugin was unloaded.");
}

AMX_NATIVE_INFO PluginNatives[] =
{
	{ "CheckUser", CheckUser },
	{ 0, 0 }
};

PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx)
{
	g_Invoke->amx_list.push_back(amx);
	return amx_Register(amx, PluginNatives, -1);
}


PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *amx)
{
	for (list<AMX *>::iterator i = g_Invoke->amx_list.begin(); i != g_Invoke->amx_list.end(); ++i)
	{
		if (*i == amx)
		{
			g_Invoke->amx_list.erase(i);
			break;
		}
	}
	return AMX_ERR_NONE;
}
Reply

Quote:
Originally Posted by Nils94
View Post
Thanks, but I get this error:


(Reference to unresolved external symbol)

My Code:

Code:
#include "sampgdk/a_players.h"
#include "sampgdk/a_samp.h"
#include "sampgdk/core.h"
#include "sampgdk/sdk.h"


#include "Invoke.h"

#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
using sampgdk::logprintf;
typedef void(*logprintf_t)(char* format, ...);
extern void *pAMXFunctions;
using namespace std;

#define AMX_DECLARE_NATIVE(native) \
	cell AMX_NATIVE_CALL native(AMX* amx, cell* params)


PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() {

	return true;
}


/////////////////////////////////////


AMX_DECLARE_NATIVE(CheckUser)
{
	if (!IsPlayerConnected(params[1])) return printf("The user %d isn't connected !", params[1]), 1;
	char name[25];
	GetPlayerName(params[1], name, 25);
	printf("This was printed from the Test plugin! Yay %s!", name);
	return 1;
}

/////////////////////////////////////

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
{
	return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}

PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
{
	g_Invoke = new Invoke;
	pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];

	printf(" * plugin was loaded.");
	return true;
}

PLUGIN_EXPORT void PLUGIN_CALL Unload()
{
	printf(" * plugin was unloaded.");
}

AMX_NATIVE_INFO PluginNatives[] =
{
	{ "CheckUser", CheckUser },
	{ 0, 0 }
};

PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx)
{
	g_Invoke->amx_list.push_back(amx);
	return amx_Register(amx, PluginNatives, -1);
}


PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *amx)
{
	for (list<AMX *>::iterator i = g_Invoke->amx_list.begin(); i != g_Invoke->amx_list.end(); ++i)
	{
		if (*i == amx)
		{
			g_Invoke->amx_list.erase(i);
			break;
		}
	}
	return AMX_ERR_NONE;
}
link the library...?
Reply

Please upload example HelloWord mvs project!
Reply

Can we call pawn natives without invoking ?

If- yes, How ?
Reply

I need a little help here.. anyone got any ideas ?

VS2013 Community.



--





Reply

Have you tried following the tutorial a second time? Perhaps you forgot a crucial step.
Reply

Hmmm try going like this.

Код:
#include "../SDK/amx/amx.h"
#include "../SDK/plugincommon.h"
That can't be a legal version of VS
Reply

Oh crap, I didn't post the damn errors.. stupid me!!!

The main.cpp is fine, but the .def file is .. idk..

Using what Pottus said..

Код:
1>------ Build started: Project: projectname, Configuration: Release Win32 ------
1>  main.cpp
1>src/main.cpp(1): fatal error C1083: Cannot open include file: '../sdk/amx/amx.h': No such file or directory
1>  testproject.def
1>testproject.def(1): error C2143: syntax error : missing ';' before 'string'
1>testproject.def(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
using

Код:
#include "sdk\amx\amx.h"
#include "sdk\plugincommon.h"
Код:
------ Build started: Project: projectname, Configuration: Release Win32 ------
1>  main.cpp
1>  testproject.def
1>testproject.def(1): error C2143: syntax error : missing ';' before 'string'
1>testproject.def(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I can't believe I forgot this.. lol
Reply

Usually I add my sdk dir to the include directories of my project. Project properties > C/C++ > General > Additional Include Directories. Then you can include them like #include <amx/amx.h>

About the errors in your .def file: RMB on the file in the solution explorer > Properties > General. Make sure Item Type is set to "Does not participate in build".
Reply

Thanks ikkentim, I knew basically it shouldn't be compiling but I didn't know that!
Reply

To return string/char, look first post and chapter "How to set a string". Yeah, also like that way as Vince said.
Reply

I'm not experienced with C++ or the SDK but I guess that's the reason why the SA-MP API implements functions like GetPlayerName the way it does.
Reply

I've changed some "\" to "/" and compiler found include files.
Reply

Im using sampgdk to create plugin my question is, what make sampgdk_InvokeNative and sampgdk_CallNative different? i dont know what is the meaning of Invoke, ****** translate isn't give me right translation.
Reply

http://prntscr.com/99tdsa

Can anyone tell me what is wrong?

VS2015
Reply

Try changing the order you include stdlib/stdint and amx.h.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)