Amxmodx

From hedgefog/amxx-modding-kit · View interactive version

Amxmodx is an AI agent skill from the GitHub repository hedgefog/amxx-modding-kit. Helps with AMX Mod X (Pawn) coding conventions and best practices.

How to use this skill

Skill file

AMX Mod X (Pawn) Code Style Guide

This document provides an overview of coding conventions for AMX Mod X projects. Each topic is covered in detail in its own file.

Core Conventions

| Category | Description |

|----------|-------------|

| Basics | Syntax, basics |

| Code Style | File structure, formatting, braces, spacing, plugin registration |

| Naming Conventions | Hungarian notation, variable prefixes, naming patterns |

| Constants & Enums | Define constants, enums, TASKID constants |

| Macros | Common macros, IS_PLAYER, patterns to avoid |

| Function Declarations | Return types, @ prefix, static variables |

| Validations | FM_NULLENT, entity checks, player validation, early returns |

API Patterns

| Category | Description |

|----------|-------------|

| Hooks | Ham, FakeMeta, ReAPI, Event, Message hooks and handles |

| Forwards | CreateMultiForward, ExecuteForward, pre/post patterns |

| Natives | Native registration and implementation |

| Callbacks | Tasks, SQL queries, CVar queries |

| Menus | Menu creation, callbacks, and patterns |

| Commands | Client, server, and console commands |

| CVars | CVar creation, binding, and change hooks |

Performance & Data

| Category | Description |

|----------|-------------|

| Optimizations | Native call reduction, dynamic hooks, model path caching |

| Data Structures | Arrays, Tries, entity access, strings |


Quick Reference: Best Practices Summary

Code Style

  1. Always use #pragma semicolon 1 at file start
  2. Use Hungarian notation for all variable names
  3. Use K&R brace style (opening brace on same line)
  4. Pass plugin info directly to register_plugin() - avoid macros
  5. Group hooks and functions with section comments

Constants & Validation

  1. Use FM_NULLENT instead of -1 or 0 for null entity checks
  2. Always check FM_NULLENT after entity creation before processing
  3. Return FM_NULLENT not 0 for failures - 0 is worldspawn
  4. Return early for invalid conditions

Macros

  1. Don't redefine macros - use shared definitions from includes
  2. Never use MACRO()_Suffix patterns in code - only in macro definitions

Function Declarations

  1. Use @ prefix only for OOP-like methods: @{EntityName}_{MethodName}
  2. Never add public keyword to @ prefixed functions
  3. Use const prefix for all handle arguments
  4. Use const &this for "this" argument in OOP-like methods
  5. Use static variables in frequently called class methods
  6. Declare and assign static on same line using semicolon separator

Hooks

  1. Ham hooks must return HAM_* constants
  2. FakeMeta hooks must return FMRES_* constants
  3. ReAPI hooks must return HC_* constants
  4. Message hooks must return PLUGIN_* constants
  5. Hook handle variables: g_pfwham (Ham), g_pfwfm (FakeMeta)
  6. Inline get_user_msgid when only used once in register_message

Forwards

  1. Forward names use LibraryName_OnSomething - not Fw_ prefix
  2. Multi-forward handle variables use g_pfw prefix

Natives & Callbacks

  1. Native implementations use Native_ prefix with const for arguments
  2. Task callbacks use Task_ prefix with offset in task ID
  3. SQL callbacks use Callback_SQLQuery_{Name} prefix

Menus

  1. Menu callbacks use Callback_Menu_{Name} prefix
  2. Use enum for menu items to avoid index mistakes
  3. Destroy dynamic menus in callback with menu_destroy

Commands & CVars

  1. Command handlers use Command_ prefix, server commands use ServerCommand_
  2. Use register_concmd for admin commands that should work from RCON
  3. Avoid client_cmd - use engclient_cmd for server-side execution
  4. Use create_cvar instead of deprecated register_cvar
  5. Use bind_pcvar_* instead of get_pcvar_* for cvar access

Optimizations

  1. Minimize native calls in hot paths
  2. Use single global g_pTrace - never create trace handles per-call
  3. Register high-frequency hooks dynamically
  4. Use xs_vec_set instead of xs_vec_copy for vector initialization
  5. Cache model index with static inside function, not in separate global

Naming Conventions

  1. Sound arrays use g_rgsz prefix with g_i*Num counter
  2. Message IDs use gmsg prefix (without underscore)
  3. Player arrays use g_rg*[MAX_PLAYERS + 1] with type prefix
  4. Don't use id for players - use pPlayer
  5. Don't use index for entities - use pEntity

Data Structures

  1. Always free dynamic handles - ArrayDestroy, TrieDestroy in plugin_end()
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.