Raised This Month: $12 Target: $400
 3% 

View Poll Results: How's this thread?
Good 13 65.00%
Bad 1 5.00%
Both / could be better 6 30.00%
Voters: 20. You may not vote on this poll

[TUT] Creating AMXX modules (VS 2013 - 2019)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thEsp
BANNED
Join Date: Aug 2017
Old 08-14-2019 , 18:13   [TUT] Creating AMXX modules (VS 2013 - 2019)
Reply With Quote #1

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.
Click to show


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


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.
Click to show

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

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.).
Click to show


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").
Click to show


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.
Click to show

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.


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.

Last edited by thEsp; 12-03-2021 at 14:48.
thEsp is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 08-15-2019 , 05:24   Re: [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #2

Quote:
Originally Posted by thEsp View Post
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.
TheDS1337 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 08-15-2019 , 05:46   Re: [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #3

Quote:
Originally Posted by TheDS1337 View Post
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.
thEsp is offline
Ali0mer
Senior Member
Join Date: Jan 2016
Location: Iraq
Old 09-15-2019 , 13:40   Re: [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #4

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?
Ali0mer is offline
Send a message via Skype™ to Ali0mer
thEsp
BANNED
Join Date: Aug 2017
Old 09-15-2019 , 13:44   Re: [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #5

Quote:
Originally Posted by Ali0mer View Post
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.

Last edited by thEsp; 09-15-2019 at 13:47.
thEsp is offline
Ali0mer
Senior Member
Join Date: Jan 2016
Location: Iraq
Old 09-15-2019 , 15:23   Re: [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #6

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?
Ali0mer is offline
Send a message via Skype™ to Ali0mer
thEsp
BANNED
Join Date: Aug 2017
Old 09-15-2019 , 16:53   Re: [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #7

Quote:
Originally Posted by Ali0mer View Post
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.

Last edited by thEsp; 09-15-2019 at 18:26.
thEsp is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 10-21-2020 , 05:37   Re: [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #8

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.
Click to show
1. At "New project dialog", at the "Language" column choose "C++" and create an Empty Project

Spoiler


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

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
Spoiler

4. Click OK then it would be finish
__________________
My plugin:

Last edited by Celena Luna; 10-21-2020 at 05:37.
Celena Luna is offline
thEsp
BANNED
Join Date: Aug 2017
Old 10-21-2020 , 17:46   Re: [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #9

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.

Last edited by thEsp; 11-10-2020 at 12:19.
thEsp is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 11-09-2020 , 19:54   Re: [TUT] Creating AMXX modules (VS 2013 - 2019)
Reply With Quote #10

Why didn't you include all of the prerequisites? Linking the external dependencies (hlsdk/metamod) to your project?
redivcram is offline
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

Forum Jump


All times are GMT -4. The time now is 18:32.


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