There are 3 basic mechanisms by which Admin Mod and your plugin interact - events, registered commands and native functions.
Admin Mod interacts with your plugin by calling a set of Small functions that you can write in your plugin that have special names when specific events on the server occur. The list of such event handler functions is as follows:
| Event | Function Called | Notes |
|---|---|---|
| Server starts | plugin_init | You must implement this function. When the server is first launched, this event doesn't happen until the first player connects. After a map change, it happens immediately. |
| A player joins the server | plugin_connect plugin_info |
The two functions are called in this order. plugin_info may be called more than once after plugin_connect - usually 3 times. |
| A player changes their name or model | plugin_info | |
| A player leaves the server | plugin_disconnect | |
| A timer your plugin started is triggered | <user specified> | You specify the name of the timer handler function when creating the timer. |
| A vote your plugin started completes | <user specified> | You specify the name of the vote handler function when starting the vote. |
If your plugin is not interested in knowing about a particular event, then it need not implement the event handler function. The exception is plugin_init, which every plugin must implement as this is called by Admin Mod when the server is started, and it is where your plugin registers commands.
Your plugin can register handlers for specific commands. Commands are issued:
Some commands are handled entirely within the client - e.g. +forward or +attack; it is not possible for your plugin to register handlers for these. However, most commands are passed to the server, including anything half-life itself does not recognise as a command. Examples of commands that are passed to the server are say,admin_map, sv_gravity 800,admin_mypluginscommand. It is this second set of commands that your plugin can intercept by registering command handler functions.
When you register a command handler, you tell Admin Mod that you want a particular function in your plugin called when that command issued. You can also specify the level of access necessary for the command handler to be called - e.g. ACCESS_MAP.
Your plugin can interact with Admin Mod by calling a number of "native" functions to perform specific tasks. Native functions do anything from joining two strings together to banning a player from the server. The reference section of this manual contains a list of all available native functions, and explains the purpose of each one.
The table below shows an example of the process that takes place when you start a server with your plugin installed.
| Half-life Server | Admin Mod | Your plugin |
|---|---|---|
| Server starts and Metamod loads Admin Mod | ||
| Admin Mod loads your plugin and runs the plugin_init function. | ||
| Your plugin_init function tells Admin Mod the plugin's name, description and version. | ||
| Your plugin_init function
tells Admin Mod which "commands"
it wishes to register. These may be bespoke commands for your plugin - e.g. "admin_mycommand", or existing half-life commands - e.g. "say". |
||
| A player joins the server | ||
| Admin Mod calls your plugin_connect function, if you have written one. | ||
| Your plugin_connect function performs any actions it needs to due to the player connecting. | ||
| A player issues a command, either by typing it in the console, or by pressing a key bound to it. e.g. sending a chat message will issue the "say" command. | ||
| Admin Mod checks each plugin in the order
listed in plugin.ini to see if the plugin
has registered the command. If it has, and the calling user has the required access level, Admin Mod calls the function in the plugin that the plugin told it to when it registered the command. | ||
| Your command handler function takes whatever actions are necessary in order to implement the command. In this example, it calls a native Admin Mod function - e.g. centresay() | ||
| The Admin Mod DLL runs its centersay() function, and returns to your registered command handler. | ||
| Your function returns a value to Admin Mod letting it know if it should pass the command to other plugins. | ||
| If your function allowed the command to pass to other plugins, Admin Mod repeats this process with each other plugin that has registered a handler for the command. | ||
| If no plugins have swallowed the command, Admin Mod passes the command back to Metamod, and if no other Metamod plugins swallow it, it is passed back to the server. | ||
| The server performs the default action for the command, if there is one - e.g. for a say command it will display the message on each players screen in the lower right corner. |