Skip to content

Server API

tmp64 edited this page Feb 28, 2021 · 1 revision

Summary

The server exposes an interface (for Metamod or via AMXX module) to request additional information about the game or connected players.

C++ header and AMXX include are well-documented and can be found here (C++) or here (AMXX).

C++ API (Metamod)

To use the API in your Metamod module you need to do the following:

  1. Copy the following files to your module's sources directory:
src/game/shared/ClientSupportsFlags.h
src/game/shared/enum_utils.h
src/game/shared/IBugfixedServer.h
src/game/shared/IGameVersion.h
src/bugfixedapi_amxx/bhl_api.cpp
src/bugfixedapi_amxx/bhl_api.h

optional:
src/game/shared/CGameVersion.cpp
src/game/shared/CGameVersion.h
  1. Check if you already have interface.h and interface.cpp. If not, get them from src/public/vinterface/.
  2. Include bhl_api.h in the main file of your module.
  3. Call bhl::InitServerApi() from module init function. InitServerApi returns E_ApiInitResult. Check bhl_api.h for details. You can find an implementation in src/bugfixedapi_amxx/bugfixedapi_amxx.cpp in OnAmxxAttach.

Warning! Some methods in the interface return a pointer to IGameVersion. You are not allowed to keep this pointer, it is only guaranteed to be valid immediately after calling (until control returns to the engine and server library). Instead you should make a copy of it using CGameVersion.

Warning! The API is not thread-safe. Please, only call it from the main engine thread.

The API can be used using bhl::serverapi() function which returns a pointer to IBugfixedServer.

AMX Mod X API

  1. Copy bugfixedapi.inc from gamedir/addons/amxmodx/scripting/include/bugfixedapi.inc to addons/amxmodx/scripting/include.
  2. Include bugfixedapi.inc in your plugin.
  3. Check the include source code for documentation.