AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [TUT] Creating AMXX modules (VS 2013 - 2019) (https://forums.alliedmods.net/showthread.php?t=318119)

thEsp 08-14-2019 18:13

[TUT] Creating AMXX modules (VS 2013 - 2019)
 
Hello, and welcome to this tutorial about creating AMX Mod X modules!
Althought there are many or few related tutorials, not many of them were reliable and simple.

First of all, you should have Visual Studio installed. You should also be knowing the basics of C++.

----------------------------------------------------------------------------------------------------------------------------

Initializing - creating the module
1. Open the "New project" dialog, and create a Win32 C++ project. Make sure you chose the project to be empty.


2. Change the "Configuration type" (Right click on project > Properties) to "Dynamic Library (.dll)".


3. We're almost set. Now create a folder named "sdk" (recommended) and put the below files into it.

4. Open "moduleconfig.h" and give credentials to your module.

----------------------------------------------------------------------------------------------------------------------------

Programming the module
Writing beautiful code is a virtue. We'll (try to) do the exact same thing... :)

1. Create a header (.h) and source (.cpp) file. Both should have the same name.

2. Include the AMXX API ("amxxmodule.h"), and anything else that you need (i.e: 3rd-party libraries, MM, HLSDK etc.).


3. A good way of keeping the module beautiful is by organizing the code well.

So create a namespace with a proper name and declare functions (+ things you need), this goes into your header.

PHP Code:

namespace ModTuto_Natives
{
    
//                     native ModTuto_PrintMsg(const Message[], any:...);
    
static cell AMX_NATIVE_CALL ModTuto_PrintMsg(AMXamxcellparams);
    
// amx = the pointer to the calling plugin, params = arguments.
    // Adding a native declaration as a comment is a good way to keep track of WHAT you ARE writing.
    
    
AMX_NATIVE_INFO ModTuto_NativesInfo[] = 
    {
        
// { "Name", Function }
        
        
"ModTuto_PrintMsg"ModTuto_PrintMsg },

        { 
NULLNULL // Add this in the end.
    
};
}; 

4. Now you have to define your functions. Make sure you have included the main header where the functions are declared.
PHP Code:

#include "modtuto.h"

void OnAmxxAttach()
{
    
MF_AddNatives(ModTuto_Natives::ModTuto_NativesInfo);
    
// Add the natives from "modtuto.h".
}

void OnAmxxDetach()
{
    
// This function is necessary, even if you have nothing to declare here. The compiler will throw a linker error otherwise.
    // This can be useful for clearing/destroying a handles system.
}

// Define the functions previously defined.
cell AMX_NATIVE_CALL ModTuto_Natives::ModTuto_PrintMsg(AMXamxcellparams)
{
    
charpFullMsg MF_FormatAmxString(amxparams10);
    
// We declared a char pointer, and gave it a value.
    // The value is, a formatted string returned from "MF_FormatAmxString", a function similar to "sprintf".
    
    
sprintf(pFullMsg"%s\n"pFullMsg);
    
// This will push '\n' (newline ANSI character) into "pFullMsg". It's recommended to use AMSTL (alliedmodders std template librarly), but we won't get too deep into it.

    
MF_PrintSrvConsole(pFullMsg);
    
// This will print "pFullMsg" in the server console.

    
return 0;
    
// What we return here goes in the calling plugin.


Bonus
1. If you keep getting an error specifying "_CRT_SECURE_NO_WARNINGS", open project properties and go to "C/C++" then "Preprocessor", and paste "_CRT_SECURE_NO_WARNINGS" in the first textbox ("Preprocessor definitions").


2. The module (binary; ".dll" file) should have an "_amxx" suffix in order to work properly. You really don't need to name your project with it.
If renaming the module over and over again (after compiling) seems tiring, then open project properties and head to "General" settings, and append "_amxx" to the "Target Name" textbox.

3. Make sure you don't over-include the header.
Code:
#if defined _modtuto_included // Check if module/header is already included.     #endinput // Exit. #endif #define _modtuto_included // Declare that the module/header is included.

4. Prepare the module.
Code:
#pragma reqlib modtuto // Require the module. #if !defined AMXMODX_NOAUTOLOAD // Check if current AMXX (version/build) does not automatically load modules.     #pragma loadlib modtuto // Manually load the module. #endif

5. Define the natives in your Pawn header.
Code:
native ModTuto_PrintMsg(const szMessage[], any:...);

I have uploaded the source to my GitHub account. Check its repository here.
So, in conclusion we have a fully working module. :)
https://i.imgur.com/d27Vbrj.png

Other references:
- AMXX SDK & misc
- Metamod & HL SDK

I've possibly done many spelling mistakes or usen incorrect terms, so correcting me is appreciated. If you got any trouble or need help (regarding the same topic) then ask me here, I'll try my best to answer.

TheDS1337 08-15-2019 05:24

Re: [TUT] Creating AMXX modules (The easiest way)
 
Quote:

Originally Posted by thEsp (Post 2663281)
First of all, you should have Visual Studio IDE installed. I don't recommend any other IDE since they lack in many aspects.

Afaik AMXx uses AMBuild that have been used in SM for ages, so MSVC is not really a requirement. this is the modern way of working with modules/extensions.

thEsp 08-15-2019 05:46

Re: [TUT] Creating AMXX modules (The easiest way)
 
Quote:

Originally Posted by TheDS1337 (Post 2663328)
Afaik AMXx uses AMBuild that have been used in SM for ages, so MSVC is not really a requirement. this is the modern way of working with modules/extensions.

I have seen AMXX modules using AMBuild, so seems what you said is valid. But so far I have no idea what it is used for, if it does what I'm thinking (converting/removing requirement for VS) then I'll just try to understand it and append the tutorial.

Ali0mer 09-15-2019 13:40

Re: [TUT] Creating AMXX modules (The easiest way)
 
Hello friend, im really intersted to learn the amxx modules..
Im beginner in Pawn language im still learning

I see here that the modules work better than anything?
so if i want to make a module works with a plugin i just have to add only the natives in modules then the other parts on the plugin?

thEsp 09-15-2019 13:44

Re: [TUT] Creating AMXX modules (The easiest way)
 
Quote:

Originally Posted by Ali0mer (Post 2667065)
Hello friend, im really intersted to learn the amxx modules..
Im beginner in Pawn language im still learning

I see here that the modules work better than anything?
so if i want to make a module works with a plugin i just have to add only the natives in modules then the other parts on the plugin?

I fear you are a bit unclear :/. AMXX Modules are obviously better(faster, reliable, capable) than AMXX scripts, perhaps worse compared to MM ones. Outside of natives you can use forwards, also, you wouldn't need some additional plugin to do more stuff.

Ali0mer 09-15-2019 15:23

Re: [TUT] Creating AMXX modules (The easiest way)
 
Like I said im still beginner n im sorry
What your advice to me should i first learn pawn until i become amxx scripter
Then I going to make modules?

thEsp 09-15-2019 16:53

Re: [TUT] Creating AMXX modules (The easiest way)
 
Quote:

Originally Posted by Ali0mer (Post 2667077)
Like I said im still beginner n im sorry
What your advice to me should i first learn pawn until i become amxx scripter
Then I going to make modules?

Anything from https://wiki.alliedmods.net/Category...ng_(AMX_Mod_X) will do just fine to learn Pawn, therefore that's too off-topic... I guess.
Making modules is easy if you know C/C++ or/and content of the game, frankly it's 2019 and there are A LOT of sources to do that.

Celena Luna 10-21-2020 05:37

Re: [TUT] Creating AMXX modules (The easiest way)
 
For Visual Studio 2019 there are few change and additional step you need to go though
If the image is too hard to see, click on it.
----------------------------------------------------------------------------------------------------------------------------
Quote:

Initializing - creating the module
1. Open the "New project" dialog, and create a Win32 C++ project. Make sure you choosed the project to be empty.

1. At "New project dialog", at the "Language" column choose "C++" and create an Empty Project



----------------------------------------------------------------------------------------------------------------------------
Quote:

3. We're almost set. Now create a folder named "sdk" (Recommended) and put the [below-mentioned] files into it.
1. Go to project folder (Right click on Project > Open Folder in File Explorer) and create a folder with the same name as your project name.

2. Go inside the folder you just create and make another folder name "sdk" there.
3. get 3 following files: "amxxmodule.cpp", "amxxmodule.h" and "moduleconfig.h" from AMXX SDK and patse it in "sdk" folder. (he didn't mention those files name from the original post)
4. Back to Visual Studio, Create new "filter/folder" name "sdk" (Right click on Project > Add > New Filter)
5. Add all 3 files that you pasted in the "sdk" folder at step 3 into the "sdk" folder inside Visual Studio (Right click on Project > Add > Add Existing Item... > (Browse those file) > Add)

----------------------------------------------------------------------------------------------------------------------------
Bonus++
If somehow you get some error like "cannot open source file "IGameConfigs.h", do this following step:
1. Open project property (Right click on project > Properties) and go to VC++ Directories, Include Directories then <Edit>.
2. Get AMXX master folder's directory (amxmodx-master\public\)
3. Go back to Visual Studio, Click on "New Line" (or Ctr+Insert) then paste the directory at step 2 there

4. Click OK then it would be finish

thEsp 10-21-2020 17:46

Re: [TUT] Creating AMXX modules (The easiest way)
 
Thanks for the awesome details @Celena Luna! I had in mind to extend this thread for cross-platform purposes recently but unfortunately I didn't have much time. Perhaps I will publish it tomorrow or this weekend.

redivcram 11-09-2020 19:54

Re: [TUT] Creating AMXX modules (VS 2013 - 2019)
 
Why didn't you include all of the prerequisites? Linking the external dependencies (hlsdk/metamod) to your project?


All times are GMT -4. The time now is 21:53.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.