SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 06/05/2011, 04:44 PM   #1
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 2,929
Reputation: 703
Default How to create a plugin

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.
__________________

Sup?

Last edited by RyDeR`; 07/05/2011 at 10:14 AM.
RyDeR` is offline   Reply With Quote
Old 06/05/2011, 04:47 PM   #2
steki.
High-roller
 
steki.'s Avatar
 
Join Date: Nov 2010
Location: São Paulo, Brasil
Posts: 2,557
Reputation: 317
Default Re: How to create a plugin

AWESOME!
__________________
Rio
steki. is offline   Reply With Quote
Old 06/05/2011, 04:58 PM   #3
jonnyboy
Huge Clucker
 
jonnyboy's Avatar
 
Join Date: Aug 2010
Location: Sweden
Posts: 410
Reputation: 3
Default Re: How to create a plugin

haha thanks. i use VS 2010
__________________

Special thanks to [GMS]toX.
jonnyboy is offline   Reply With Quote
Old 06/05/2011, 05:25 PM   #4
Phanto90
Huge Clucker
 
Phanto90's Avatar
 
Join Date: Mar 2011
Location: Milan, Italy
Posts: 337
Reputation: 36
Default Re: How to create a plugin

Nice tutorial. Althought I hope not to see too many useless plugins by users Good work ryder.
__________________


Latest Releases
FilterscriptsIncludesMaps
PRaceSystem v1.3 PBlock v1.1Electronic Shop
PVotekick v1.1PInventory v1.1
________________________
I don't script for money, stop asking for it.

Phanto90 is offline   Reply With Quote
Old 06/05/2011, 05:30 PM   #5
Ricop522
High-roller
 
Ricop522's Avatar
 
Join Date: Feb 2010
Location: ES
Posts: 2,640
Reputation: 159
Default Re: How to create a plugin

Awesome, I love that
ty!
__________________
"Any fool can write code that a
computer can understand. Good
programmers write code that
humans can understand."

AJUDA! Programação
Github
Ricop522 is offline   Reply With Quote
Old 06/05/2011, 05:31 PM   #6
Alby Fire
Big Clucker
 
Join Date: Dec 2010
Posts: 125
Reputation: 8
Default Re: How to create a plugin

Meh... you could atleast create this tutorial before I broke my ass to learn how to code a plugin...
__________________

Thank blewert for this signature
Alby Fire is offline   Reply With Quote
Old 06/05/2011, 05:46 PM   #7
BASITJALIL
Gangsta
 
Join Date: Mar 2010
Location: C:\WINDOWS\system32\BasitJalil.dll
Posts: 513
Reputation: 7
Default Re: How to create a plugin

Awesome work
BASITJALIL is offline   Reply With Quote
Old 06/05/2011, 10:24 PM   #8
Markx
Gangsta
 
Markx's Avatar
 
Join Date: Dec 2010
Location: Zagreb, Croatia
Posts: 944
Reputation: 39
Default Re: How to create a plugin

Awesome!
__________________
...Left samp for now, hope i gonna be back someday...

Markx is offline   Reply With Quote
Old 06/05/2011, 10:28 PM   #9
TheGarfield
Banned
 
Join Date: Jul 2010
Location: -_-
Posts: 649
Reputation: 11
Default Re: How to create a plugin

this tutorials is amazing and a little dificulting.
for people who knows programing C++ and C#.
TheGarfield is offline   Reply With Quote
Old 07/05/2011, 12:52 AM   #10
sciman001
Gangsta
 
Join Date: Jan 2011
Location: C:/Your Mom/Her Fat Ass/me.amx
Posts: 642
Reputation: 11
Default Re: How to create a plugin

sorry to spam, but, THANK YOU SOOO FUKEN MUCH!!!! I REALLY NEEDED THIS! THX MAN!!!!!!!!!!!!!
__________________
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
sciman001 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] IRC Plugin Incognito Plugin Development 816 06/05/2020 08:23 AM
plugin help Tom1412 Server Support 4 03/04/2011 08:08 PM
mysql plugin. loading plugin failed ikkentim Help Archive 2 10/02/2011 02:32 PM
i need irc plugin Johny_Depp Server Support 4 28/12/2009 12:12 PM
[help] how to create plugin? BombaNick Help Archive 2 20/10/2009 05:00 PM


All times are GMT. The time now is 08:47 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.