amxx模块开发官方文档阅读理解4-Porting AMX Mod Modules
条评论New Include/Base Structure
Instead of including <modules.h>, you should now include <amxxmodule.h> and add the M/SDK to your project (get the MDK from CVS or the packaged source code).
Then you should make the necessary moduleconfig.h configuration changes listed in the module writing guide to enable Metamod hooks, Native hooks, and your module’s “personal” information struct.
You should remove any .def files, and also remove any Metamod or AMX Mod hooks, such as Meta_Attach() or Amx_Attach(). Instead, uncomment the appropriate hooks in moduleconfig.h - such as OnAmxxAttach for natives and OnPluginsLoaded for forwards. For Metamod, remove all of the engine hook sets and uncomment the appropriate hooks in moduleconfig.h. For example, if your old AMX Mod module had this:
1 | C_DLLEXPORT int AMX_Attach(pfnamx_engine_g* amxeng,pfnmodule_engine_g* meng) { |
This would simply become:
1 | void OnAmxxAttach() |
Likewise:
1 | enginefuncs_t meta_engfuncs; |
Is simply deleted, and #define FM_TraceLine is uncommented from moduleconfig.h.
Easy, huh? Other things, like global/external pointers used for MM/AMX should be removed. These are handled by the M/SDK.
New API
You should familiarize yourself with the new module functions available.
Here are some quick changes. The parameter count is listed as well. A * indicates the parameters changed.
- ADD_AMXNATIVES(2) -> MF_AddNatives(1*)
- AMX_RAISEERROR(2) -> MF_RaiseAmxError(2) or MF_LogError(…*)
- GET_AMXADDR(2) -> MF_GetAmxAddr(2)
- SET_AMXSTRING(4) -> MF_SetAmxString(4)
- GET_AMXSTRING(4) -> MF_GetAmxString(4*)
New Forward/Callback System
AMX Mod modules are responsible for handling forwards their own way - in AMX Mod X the core does it for you.
Take this example from VexD, the way to manage a forward was:
1 | struct AmxCall { |
Rather than using the new API functions (MF_AmxFindPublic, MF_AmxExec), let’s try using the new Forward system.
1 | int TouchForward = -1; |
Simple, clean, efficient. Have fun!
总结
简单的说,这篇文章就是介绍了老版本的amx和新版本的amxx在编写module时,代码风格和编写方式的不同,新版本的amxx可以说是更加简洁、更加方便了。