text
stringlengths
0
692
Code:
Order of Events:
1.Server is off hlds.exe is not running
2.Server starts
3.plugin_init() cvars are created
4.plugin_cfg()
5.amxx.cfg cvars assigned values from amxx.cfg
6.server.cfg cvars assigned values from server.cfg
7.Server restarts mapchange or 'restart' command
8.plugin_init() cvars are NOT re-created or overwritten; if they exist, only pointers are gathered
9.plugin_cfg()
10.amxx.cfg cvars assigned values from amxx.cfg (server.cfg is not called next)
The functions plugin_init() and plugin_cfg() are called on every map-change, restart, and "fresh" start. ("Fresh" start means the server turned on after being off.) The amxx.cfg file is read on every map-change, restart and "fresh" start. The server.cfg file is only read on "fresh" starts.
When you do register_cvar("cvar_name", "cvar_value"), you are attempting to create a new cvar with a new default value. If this cvar already exists, this function will not overwrite the original value. Instead, it will return a pointer to the existing cvar that you can later access with get_pcvar_flags, get_pcvar_float, get_pcvar_num, or get_pcvar_string.
To get a pointer for a cvar, use get_cvar_pointer("cvarname").
CVAR flags
This is taken directly from amxconst.inc:
FCVAR_ARCHIVE set to cause it to be saved to vars.rc
FCVAR_USERINFO changes the client's info string
FCVAR_SERVER notifies players when changed
FCVAR_EXTDLL defined by external DLL
FCVAR_CLIENTDLL defined by the client dll
FCVAR_PROTECTED It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value
FCVAR_SPONLY This cvar cannot be changed by clients connected to a multiplayer server.
FCVAR_PRINTABLEONLY This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ).
FCVAR_UNLOGGED If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log
Unfortunately, I can't find any examples for the following flags: FCVAR_ARCHIVE, FCVAR_USERINFO, FCVAR_EXTDLL, FCVAR_CLIENTDLL.
So, I'd like to ask anyone who knows about these flags to post.
Example
Here's a simple script that counts how many times a server stops running. If you can understand how this script works, then you probably have a good grip on cvars.
This script should only be used as a demonstration to understand cvars. If you really want to count crashes accurately, I would recommend a different method. Let me know if you're interested.
Code:
#include <amxmodx>
#define PLUGIN "Crash Counter"
#define VERSION "1.0"
#define AUTHOR "stupok"
#define DIR_CRASHLOG "addons\amxmodx\logs\CrashLog"
#define FILE_CRASHMAP "addons\amxmodx\logs\CrashLog\crash_map.txt"
#define FILE_LOG "CrashLog.log" // will be found in addons\amxmodx\logs
new cvar_Crashed
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
cvar_Crashed = register_cvar("server_crashed", "1", FCVAR_SPONLY) // do not let players edit this cvar
if(!dir_exists(DIR_CRASHLOG)) mkdir(DIR_CRASHLOG) // make addons\amxmodx\logs\CrashLog
if(!file_exists(FILE_CRASHMAP)) write_file(FILE_CRASHMAP, "-- Do not edit --", -1) // make crash_map.txt
new szMapName[32]
new iLineLen
read_file(FILE_CRASHMAP, 2, szMapName, charsmax(szMapName), iLineLen) // read previous map from file
if(get_pcvar_num(cvar_Crashed)) // check if server just started, 1 = start, 0 = restart/mapchange
{
if(szMapName[0]) // do we have a map from crash_map.txt?
{
log_to_file(FILE_LOG, "The server exited or crashed on '%s' before this recorded time.", szMapName)
}
set_pcvar_num(cvar_Crashed, 0) // this will be set to 1 again when the server has a "fresh" start (not restart)
}
get_mapname(szMapName, charsmax(szMapName)) // get the name of the current map
write_file(FILE_CRASHMAP, szMapName, 2) // write it to crash_map.txt
}
Message Logging 1.17
by Damaged Soul
AMX Mod X Version: 1.75 and above
Supported Mods: All
Description
This plugin allows for the logging of any or all messages sent by the HL engine or mod (such as DeathMsg, CurWeapon, etc) It also allows these messages to be filtered by entity.
Information that is logged includes:
Message name
Number of message arguments
Message ID
Message destination (i.e. Broadcast, One, All, etc)
Message origin
Entity that received the message
Entity classname
Entity netname
Every argument value and type