[Tutorial] How to create a plugin
#1

Introduction

A lot of people want to know how to create a plugin using Microsoft Visual C++ 2008/2010. Some people think it's hard but it's actually quite simple if you know how to start.
I will explain step by step below how you create your first native.

Things you need to know before starting
How
  1. Run Microsoft Visual C++ (2008/2010 version).
  2. Go to "File" tab then click "New" and select "Project".

  3. You will see the following dialog

  4. Select "Win32 Project", enter a project name and press "OK" to continue.
  5. The following dialog will appear

  6. Just press "Next" to continue.
  7. In the next dialog you have to select "DLL" under Application type and "Empty project" under additional options and press the "Finish" button.

  8. Now the only thing you're going to see is the solution explorer somewhere on the left side. (If you don't see the solution explorer press the "View" tab then select "Other windows" and click on "Solution explorer")

  9. As you can see, I called my project "Test". Do right click on "Test" in the solution explorer and go select "Properties".
  10. You will see the following dialog

  11. On the left, click "Linker" then select "Input" and write next to "Module Definition File" the name of your project or something else adding the ".def" extension behind and press "OK".

  12. Now refer yourself back to the solution explorer and do right click on your project name again and select "Add", and then click "New Item".
  13. In the dialog that pops up, select "C++ File (.cpp)" and below next to "Name" you write the thing you wrote next to "Module Definition File" (in step 11). And press "Add".

  14. Press right click on your project name, select "Add" and click "New Item" again.
  15. This time you do the same, select "C++ File (.cpp)" but now, you write next to "Name" the name you chose previously but this time using the ".cpp" extension. Then press "Add".

  16. Now you will see 2 tabs opened: "YourProjectName.def" and "YourProjectName.cpp".
  17. Open "YourProjectName.def" and paste the following thing into that:
    Code:
    EXPORTS
    	Supports
    	Load
    	Unload
    	AmxLoad
    	AmxUnload
  18. Now open "YourProjectName.cpp" and paste the following thing into that:
    pawn Code:
    #include "../SDK/plugin.h"

    typedef void
        (*logprintf_t)(char* format, ...)
    ;

    logprintf_t
        logprintf
    ;

    void
        **ppPluginData
    ;

    extern void
        *pAMXFunctions
    ;

    PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
    {
       pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
       logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];
       return 1;
    }

    PLUGIN_EXPORT void PLUGIN_CALL Unload()
    {
    }

    AMX_NATIVE_INFO projectNatives[] =
    {
       { 0, 0 }
    };


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

    PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx)
    {
       return amx_Register(amx, projectNatives, -1);
    }

    PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *amx)
    {
       return AMX_ERR_NONE;
    }
  19. Now refer yourself back to Solution explorer and right click your project name again, select "Add", and click on "New Filter". Now you will see that a new file has been created. Change the name to "SDK".
  20. Extract the "SDK" file you have downloaded in "Documents/Visual Studio 2010/Projects/YourProjectName/".
  21. Go back to the solution explorer and right click on the "SDK" filter you have created and select "Add", then click on "Existing Item".
  22. A dialog will appear, now browse to the "SDK" directory you have copied and select "amxplugin.cpp".
  23. Now that's pretty it! Now press F7 and compile it.
  24. You can find your .dll file in the Debug directory.
Create a native
  1. Add this somewhere in your .cpp script:
    pawn Code:
    static cell AMX_NATIVE_CALL YourNativeNameHere(AMX *amx, cell *params)
    {  
            logprintf("I haz made my first plugin!! :)");
            // Your codes go in here
            return 1; // Change the return value if need
    }
  2. Go to:
    pawn Code:
    AMX_NATIVE_INFO projectNatives[] =
    {
            { 0, 0 }
    };
    And add "{ "YourNativeNameHere", YourNativeNameHere }", like this:
    pawn Code:
    AMX_NATIVE_INFO projectNatives[] =
    {
            { "YourNativeNameHere", YourNativeNameHere } // In the first array dimension, you write the name of the native you're going to call in PAWN. In the second one, you write the name in .cpp file. In this case, they're the same!
    };
  3. Compile, and go to the Debug file.
  4. Select your .dll file and copy it to your server files.
  5. Create a new .pwn script and add "native YourNativeNameHere();" at the top. And just call it under "OnFilterScriptInit".
    pawn Code:
    #include <a_samp>

    native YourNativeNameHere();

    public OnFilterScriptInit()
    {
        YourNativeNameHere();
        return 1;
    }
  6. When you run your server, it should print this: "I haz made my first plugin!! ".
  7. This is just the basic. Now you can create other unique things!

    NOTE: If you want natives with parameters, you can use "params[]" starting from index 1.
Note(s)
  • Try to figure out how to do other things. I'm just teaching you the basic on how to get started.
  • You can ask questions below, but I'm not going to answer then all.
Reply


Messages In This Thread
How to create a plugin - by RyDeR` - 06.05.2011, 16:44
Re: How to create a plugin - by steki. - 06.05.2011, 16:47
Re: How to create a plugin - by jonnyboy - 06.05.2011, 16:58
Re: How to create a plugin - by Phanto90 - 06.05.2011, 17:25
Re: How to create a plugin - by Ricop522 - 06.05.2011, 17:30
Re: How to create a plugin - by Alby Fire - 06.05.2011, 17:31
Re: How to create a plugin - by BASITJALIL - 06.05.2011, 17:46
Re: How to create a plugin - by Markx - 06.05.2011, 22:24
Re: How to create a plugin - by TheGarfield - 06.05.2011, 22:28
Re: How to create a plugin - by sciman001 - 07.05.2011, 00:52
Re: How to create a plugin - by CJ101 - 07.05.2011, 01:09
Re: How to create a plugin - by Lorenc_ - 07.05.2011, 01:13
Re: How to create a plugin - by blackwave - 07.05.2011, 01:21
Re: How to create a plugin - by Deskoft - 07.05.2011, 02:30
Re: How to create a plugin - by sciman001 - 07.05.2011, 02:44
Re: How to create a plugin - by Stigg - 07.05.2011, 03:44
Re: How to create a plugin - by RyDeR` - 07.05.2011, 08:10
Re: How to create a plugin - by Dark_Thunder - 07.05.2011, 08:16
Re: How to create a plugin - by Zh3r0 - 07.05.2011, 09:05
Re: How to create a plugin - by RyDeR` - 07.05.2011, 09:12
Re: How to create a plugin - by Zh3r0 - 07.05.2011, 09:33
Re: How to create a plugin - by RyDeR` - 07.05.2011, 10:04
Re: How to create a plugin - by Zh3r0 - 07.05.2011, 10:06
Re: How to create a plugin - by linuxthefish - 07.05.2011, 10:08
Re: How to create a plugin - by RyDeR` - 07.05.2011, 10:10
Re: How to create a plugin - by Zh3r0 - 07.05.2011, 10:18
Re: How to create a plugin - by Ironboy - 07.05.2011, 10:19
Re: How to create a plugin - by Institute - 07.05.2011, 10:49
Re: How to create a plugin - by Hiddos - 07.05.2011, 14:26
Re: How to create a plugin - by RyDeR` - 07.05.2011, 14:37
Re: How to create a plugin - by Michael@Belgium - 08.05.2011, 08:53
Re: How to create a plugin - by SkizzoTrick - 08.05.2011, 10:49
Re: How to create a plugin - by iJumbo - 08.05.2011, 10:54
Re: How to create a plugin - by me-borno - 08.05.2011, 14:45
Re: How to create a plugin - by RyDeR` - 08.05.2011, 16:52
Re: How to create a plugin - by me-borno - 08.05.2011, 16:59
Re: How to create a plugin - by Heavy_Badass - 09.05.2011, 10:55
Re: How to create a plugin - by RyDeR` - 13.05.2011, 21:55
Re: How to create a plugin - by Fj0rtizFredde - 13.05.2011, 22:13
Re: How to create a plugin - by Sasino97 - 14.05.2011, 13:56
Re: How to create a plugin - by kacper55331 - 15.05.2011, 19:33
Re: How to create a plugin - by Sasino97 - 16.05.2011, 15:19
Re: How to create a plugin - by RyDeR` - 16.05.2011, 15:34
Re: How to create a plugin - by Sasino97 - 16.05.2011, 15:40
Re: How to create a plugin - by RyDeR` - 16.05.2011, 15:45
Re: How to create a plugin - by Sasino97 - 16.05.2011, 18:14
Re: How to create a plugin - by Mean - 17.05.2011, 14:49
Re: How to create a plugin - by RyDeR` - 17.05.2011, 15:11
Re: How to create a plugin - by Raimis_R - 17.05.2011, 17:57
Re: How to create a plugin - by me-borno - 19.05.2011, 14:33
Re: How to create a plugin - by Patrik356b - 21.05.2011, 15:45
Re: How to create a plugin - by 0x5A656578 - 21.05.2011, 15:50
Re: How to create a plugin - by Patrik356b - 21.05.2011, 18:35
Re: How to create a plugin - by mariomako - 21.05.2011, 18:36
Re: How to create a plugin - by sabretur - 25.05.2011, 10:33
Re: How to create a plugin - by CyNiC - 26.05.2011, 15:20
Re: How to create a plugin - by 1337connor - 29.05.2011, 20:44
Re: How to create a plugin - by iggy1 - 30.05.2011, 11:32
Re: How to create a plugin - by Cenation - 30.05.2011, 12:23
Re: How to create a plugin - by RyDeR` - 30.05.2011, 14:27
Re: How to create a plugin - by 1337connor - 30.05.2011, 23:11
Re: How to create a plugin - by Miguel - 31.05.2011, 00:37
Re: How to create a plugin - by 1337connor - 31.05.2011, 04:45
Re: How to create a plugin - by NcP - 31.05.2011, 08:24
Re: How to create a plugin - by RyDeR` - 01.06.2011, 11:58
Re: How to create a plugin - by mumi38 - 02.06.2011, 09:39
Re: How to create a plugin - by Gamer_Z - 08.07.2011, 07:45
Re: How to create a plugin - by RyDeR` - 08.07.2011, 09:08
Re: How to create a plugin - by Guest3598475934857938411 - 25.07.2011, 23:42
Re: How to create a plugin - by DRIFT_HUNTER - 26.07.2011, 02:30
Re: How to create a plugin - by dr.pepper - 26.07.2011, 02:46
Re: How to create a plugin - by DRIFT_HUNTER - 26.07.2011, 04:31
Re: How to create a plugin - by Unknown1234 - 26.07.2011, 10:21
Re: How to create a plugin - by Guest3598475934857938411 - 26.07.2011, 14:46
Re: How to create a plugin - by iggy1 - 26.07.2011, 16:26
Re: How to create a plugin - by Guest3598475934857938411 - 27.07.2011, 00:06
Re: How to create a plugin - by FireCat - 27.07.2011, 07:16
Re: How to create a plugin - by DRIFT_HUNTER - 27.07.2011, 08:13
Re: How to create a plugin - by iPLEOMAX - 04.10.2011, 21:16
Re: How to create a plugin - by RyDeR` - 04.10.2011, 21:23
Re: How to create a plugin - by iPLEOMAX - 04.10.2011, 21:37
Re: How to create a plugin - by iPLEOMAX - 05.10.2011, 15:28
Re: How to create a plugin - by SkizzoTrick - 17.10.2011, 17:49
Re: How to create a plugin - by Lorenc_ - 23.10.2011, 09:17
Re: How to create a plugin - by iggy1 - 23.10.2011, 18:43
Re: How to create a plugin - by JordanMaddox - 26.10.2011, 18:37
Re: How to create a plugin - by Igorek - 08.11.2011, 07:14
Respuesta: How to create a plugin - by [Nikk] - 07.12.2011, 05:27
Re: How to create a plugin - by RyDeR` - 13.01.2012, 16:53
Re: How to create a plugin - by Max_Coldheart - 13.01.2012, 18:04
Re: How to create a plugin - by Gh05t_ - 13.01.2012, 19:55
Re: How to create a plugin - by Guitar - 16.03.2012, 10:47
Re: How to create a plugin - by zgintasz - 14.04.2012, 18:19
Re: How to create a plugin - by Genuine - 26.06.2012, 13:28
Re: How to create a plugin - by $$inSane - 29.06.2012, 14:32
Re: How to create a plugin - by RyDeR` - 08.07.2012, 17:10
Re: How to create a plugin - by CROSS_Hunter - 23.08.2012, 22:20
Re: How to create a plugin - by MicroD - 24.08.2012, 06:10
AW: How to create a plugin - by Kaliber - 18.09.2012, 14:30
Re: How to create a plugin - by Plovix - 27.10.2012, 18:30
Re: How to create a plugin - by hypZZ - 04.12.2012, 11:01
Re: How to create a plugin - by Tumba - 17.12.2012, 07:26
Re: How to create a plugin - by Roel - 10.01.2013, 07:14
Re: How to create a plugin - by DiGiTaL_AnGeL - 10.01.2013, 09:16
Re: How to create a plugin - by LeNy - 18.01.2013, 19:52
Re: How to create a plugin - by Gangster-rocks - 12.07.2013, 12:49
Re: How to create a plugin - by Gangster-rocks - 12.07.2013, 13:04
Re: How to create a plugin - by John_Tylor - 25.07.2013, 08:15
Re: How to create a plugin - by Necip - 25.07.2013, 09:31
Re: How to create a plugin - by Diman777 - 27.01.2014, 18:36
Re: How to create a plugin - by sampsvr - 07.02.2014, 19:48
Re : How to create a plugin - by Kilou - 18.03.2014, 17:56
Re: How to create a plugin - by jlalt - 15.10.2015, 06:23
Re: How to create a plugin - by doreto - 14.07.2016, 16:29

Forum Jump:


Users browsing this thread: 2 Guest(s)