Fix: Run time error 10: native error (AMX Mod X)

November 5, 2025 Daemon666 8 min read 221 просмотров

An AMX Mod X plugin logs Run time error 10 and a feature stops working. Error 10 is AMX_ERR_NATIVE — a native function was called and failed inside the engine or module. It is a signal that a plugin passed something invalid to a native, or called a native whose module is not loaded. The number alone is useless; the fix starts with turning on debug so the log names the exact native and line.

1. Read the raw error and enable debug

Undebugged, the entry in addons/amxmodx/logs/ reads:

[AMXX] Run time error 10 (plugin "myplugin.amxx") (native "get_user_name") - debug not enabled!

You already get the native name here — get_user_name — but not the line or the argument that broke it. Add debug after the plugin in plugins.ini:

myplugin.amxx debug

Reload with a map change, reproduce, and the trace now points at the call site. The general procedure is in debugging AMXX plugins.

2. The usual cause: an invalid player index

Most error 10s are a native called on a player who is not there. A handler fires for entity 0 (worldspawn) or a client who just disconnected, and a native like get_user_name or get_user_team rejects the index. The fix is to validate before the call:

if (!is_user_connected(id))
    return PLUGIN_HANDLED

new name[32]
get_user_name(id, name, charsmax(name))

Guard with is_user_connected(id) for anything needing a live client, or is_user_alive(id) where the player must also be alive. An index of 0 passed to a per-player native is the classic trigger.

3. The other cause: a native from an unloaded module

If the failing native belongs to a module that is not loaded, the call cannot resolve and errors. A plugin using cs_get_user_money (cstrike) or a MySQL native without its module will error 10 — or fail to load at all. Confirm the module:

amxx modules

The module the native comes from must read running. Enable it in modules.ini and install it per installing AMXX modules. Match the native to its module — cstrike, fun, engine, fakemeta — and load the one it needs.

4. Bad parameters and empty results

Some natives error when handed an out-of-range value or an empty required argument — a task id that never existed, a cvar pointer that was never registered, an entity that was already removed. Read the native's expected arguments and confirm the plugin is passing a valid, current handle. A get_pcvar_* call on a cvar pointer that is 0 because register_cvar was never run is a common one.

5. When the native is a database or file call

Error 10 from an SQL or file native is a different animal — the native did not get a bad index, it genuinely failed at its job. A threaded query native errors when the connection tuple is wrong; a file-read native errors when the path does not exist or is not readable. In these cases the fix is not an index guard but checking the resource: does the MySQL account connect, does the file exist with read permission for the server user. For SQL specifically, capture and log the error the native hands back rather than letting it bubble up as a bare error 10 — the underlying MySQL message tells you exactly what went wrong. The lesson across all error 10s is the same: the number means "a native said no," and the debug trace plus the native's own error output tell you which one and why.

Common errors

  • Error 10 on a per-player native — the client index is invalid or disconnected. Guard with is_user_connected / is_user_alive.
  • Error 10 the moment the plugin runs — the native's module is not loaded. Check amxx modules and enable it.
  • Only fires on round end or disconnect — a handler runs for a player who is leaving; index goes stale mid-frame. Re-validate at the top of the handler.
  • "debug not enabled!" — you have the native name but not the line. Add debug and reproduce to get the call site.
  • Not error 10 but error 4 — that is an array-bounds fault; see run time error 4.

Verification

Add the index guard or load the missing module, recompile if you changed source, redeploy and change the map. With the plugin still flagged debug, repeat the action that failed — the disconnect, the command, the round transition. A clean log through a full map means the native is now always called with valid arguments on a loaded module. Remove the debug flag afterwards to restore JIT speed. If it still errors, the trace names a different native than you fixed — guard that one too.

Участники: Daemon666 ✦
Поделиться: