26.04.2016, 17:19
(
Последний раз редактировалось Crystallize; 28.09.2017 в 14:15.
)
Introduction
Technically, PAWN supports plugins natively, but there was never an SDK for them released for SA:MP. Back before the main SA:MP plugin SDK was released someone was working on it but they never finished and I had no clue what was going on. Since then, however, I have learnt a vast amount more and discovered that using these plugins wasn't actually that hard - so I wrote this library to use them. Well, I more combined existing bits of code from the SA:MP plugin SDK and the open-source implementation of PAWN 3.2.3664 found here.
Use
There are some minor differences between using this system and the original SA:MP plugin SDK for the main server, and I'll detail them all here. Note that this is mostly for development on WINDOWS - I've not made a Linux version yet but doing so won't be hard.
In this example the plugin is called "npcdll" (for fairly obvious reasons), and the project is set up assuming that your plugin's directory is in "npcmodes/". This will create a file called "../../amxnpcdll.dll" (PAWN requires "amx<plugin name>.dll"), which should put it in the server root directory. I.e, my layout is:
If you put the plugin's project folder somewhere else, make sure you move the resulting .dll file to the server root (the same directory as "samp-npc.exe").
SA:MP:
NPC:
Notice the second one is "cell const" instead of "cell". Practically this makes no difference since you don't actually change those values anyway, even with reference parameters (since then the value of "params" is a pointer not the value itself), but it does make copying code awkward.
You do standard setup such as registering natives in here as normal. The main difference here is that the functions "Supports", "Load", "Unload", and "ProcessTick" don't exist. The first one isn't needed, the next two can be easily simulated with "DllMain" (standard in windows dlls), and I'm sure there's a solution for the final one but I don't know it yet.
This outputs a Windows debug string that can be read using a program such as DebugView.
Download
Get the basic project for Visual Studio here:
http://dl.dropbox.com/u/21683085/npcdll.rar
Advanced
As I said, this is a collection of several systems combined together to make it look as much as possible like standard SA:MP plugins, but it isn't really:
Credits
Full credits to ******.
Technically, PAWN supports plugins natively, but there was never an SDK for them released for SA:MP. Back before the main SA:MP plugin SDK was released someone was working on it but they never finished and I had no clue what was going on. Since then, however, I have learnt a vast amount more and discovered that using these plugins wasn't actually that hard - so I wrote this library to use them. Well, I more combined existing bits of code from the SA:MP plugin SDK and the open-source implementation of PAWN 3.2.3664 found here.
Use
There are some minor differences between using this system and the original SA:MP plugin SDK for the main server, and I'll detail them all here. Note that this is mostly for development on WINDOWS - I've not made a Linux version yet but doing so won't be hard.
- Naming
In this example the plugin is called "npcdll" (for fairly obvious reasons), and the project is set up assuming that your plugin's directory is in "npcmodes/". This will create a file called "../../amxnpcdll.dll" (PAWN requires "amx<plugin name>.dll"), which should put it in the server root directory. I.e, my layout is:
Код:
<root> ├───filterscripts ├───gamemodes ├───include ├───npcmodes │ ├───npcdll │ │ └───SDK │ │ └───amx ├───pawno ├───plugins ├───scriptfiles <etc>
- Includes
pawn Код:
#pragma library npcdll
native HelloWorld();
- Natives
SA:MP:
Код:
static cell AMX_NATIVE_CALL n_HelloWorld(AMX * amx, cell * params)
Код:
static cell AMX_NATIVE_CALL n_HelloWorld(AMX * amx, cell const * params)
- Load Functions
Код:
PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX * amx); PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX * amx);
- Printing
Код:
OutputDebugString(L"Hello from this NPC plugin!\n");
- Finally
Download
Get the basic project for Visual Studio here:
http://dl.dropbox.com/u/21683085/npcdll.rar
Advanced
As I said, this is a collection of several systems combined together to make it look as much as possible like standard SA:MP plugins, but it isn't really:
- Normal plugins are given handles to the PAWN internal functions such as "amx_GetPublic" (which is how the SA:MP GDK works); however, these plugins are NOT given these handles so instead have copies of the entire code, making the whole plugin much larger.
- The functions "AmxLoad" and "AmxUnload" are not actually called that - macros internal to Visual Studio rename them to their internal names of "amx_<project name>Init" and "amx_<project name>Cleanup". This is done just so that you don't need to rename the functions for every new project, instead everything is controlled centrally.
- In addition to the previous point, the ".def" file is still required due to incompatibilities between "__declspec(dllexport)" and "__stdcall" in Visual Studio. This again is generated at compile time with the correct function names based on the project name (see "Build Events").
- While the "SDK" includes in the project look the same as the standard SA:MP ones, they are not. "plugincommon.h" has been cut down, "amx.h" and "amx.c" are from the PAWN toolkit directly (hence the change to "const"), "osdefs.h" has been added, everything else is the same.
Credits
Full credits to ******.