Raised This Month: $68 Target: $400
 17% 

View Poll Results: How's this thread?
Good 4 66.67%
Bad 0 0%
Both / could be better 2 33.33%
Voters: 6. You may not vote on this poll

[TUT] Creating AMXX modules (The easiest way)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thEsp
Veteran Member
Join Date: Aug 2017
Location: Albania
Old 08-14-2019 , 18:13   [TUT] Creating AMXX modules (The easiest way)
Reply With Quote #1

Hello, and welcome to this tutorial about creating AMX Mod X modules!
Althought there are many or few related tutorials, LITERALLY NONE of them are reliable and simple, at least for New-Bs.

First of all, you should have Visual Studio IDE installed. I don't recommend any other IDE since they lack in many aspects.
And above all you SHOULD know C++.
----------------------------------------------------------------------------------------------------------------------------

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


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-mentioned] files into it.

4. Open "moduleconfig.h" and give credentials to module. This includes name, prefix (for debugging) etc.
Click to show

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

Coding the module
Beautiful-izing the code is a positive virtue. We'll do the exact same thing...

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

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

3. A good way of keeping the module beautiful is by organizing the code.
So create a namespace with a proper name and add functions, native infos, etc.
(This obviously should be written into the header.)
PHP Code:
namespace ModTuto_Natives
{
    
//                     native ModTuto_PrintMsg(const Message[], any:...);
    
static cell AMX_NATIVE_CALL ModTuto_PrintMsg(AMXamxcellparams);
    
// This is the way of declaring a function inside of namespace, "(AMX* amx, cell* params)" is necessary since this is how {natives get called, arguments are passed}.
    // Adding a Pawn-native declarement is a good way to keep track of WHAT you ARE coding.
    
    
AMX_NATIVE_INFO ModTuto_NativesInfo[] = 
    {
        
// { "Name", Function }
        
        
"ModTuto_PrintMsg"ModTuto_PrintMsg },

        { 
NULLNULL // Add this in the end.
    
};
}; 
4. Now comes the source/main part. Make sure you have included the main header [of project].
PHP Code:
#include "modtuto.h"

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

void OnAmxxDetach()
{
    
// This function is necessary. Even if you have nothing to declare here.
    // This can be useful for clearing/destroying a handling system.
}

// There is no need to declare the function as static member.
// Just add the namespace and its certain function.
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".

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

    
return 0;
    
// It does not matter what we return, but we should return something.

Bonus
1. If you keep getting error indicating "_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 "_amxx" suffix in order to work properly. You really don't need to include this in project's name.
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 "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. Let's add the native(s) to the 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 custom module.


I've possibly done many spelling mistakes or used bad terms, so correcting me is appreciated. If you got any trouble or need help then ask me here, I'll try my best to help.
__________________
Inactive on this forum due to work and busy personal life. Will definitely miss most of y'all, farewell!

Last edited by thEsp; 08-14-2019 at 18:54.
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
Send a message via MSN to TheDS1337
thEsp
Veteran Member
Join Date: Aug 2017
Location: Albania
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.
__________________
Inactive on this forum due to work and busy personal life. Will definitely miss most of y'all, farewell!
thEsp is offline
Ali0mer
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
Veteran Member
Join Date: Aug 2017
Location: Albania
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.
__________________
Inactive on this forum due to work and busy personal life. Will definitely miss most of y'all, farewell!

Last edited by thEsp; 09-15-2019 at 13:47.
thEsp is offline
Ali0mer
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
Veteran Member
Join Date: Aug 2017
Location: Albania
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.
__________________
Inactive on this forum due to work and busy personal life. Will definitely miss most of y'all, farewell!

Last edited by thEsp; 09-15-2019 at 18:26.
thEsp 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 03:45.


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