Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
text
Languages:
Russian
Size:
10K - 100K
Tags:
code
License:
File size: 5,532 Bytes
c2b71e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
CVARs This quick guide will show you what they are and how they behave. Here's a great list of cvars: http://scripting.elxdraco.net/cvarlist/ What are they? You can think of them as global (sort of) variables. You can retrieve their values, set new values, and also create new cvars. They differ from actual global variables, because you can change cvar values from the console. Usage You can store all sorts of stuff in your cvars. Typically, they are used to control plugins, turn them on/off, or to hold data temporarily. You can use the flags listed below to modify the behavior of the cvars. If you will read the cvar value later on in your script, use pointers. Use get_pcvar_flags, get_pcvar_float, get_pcvar_num, or get_pcvar_string. Do not use get_cvar_flags, get_cvar_float, get_cvar_num, or get_cvar_string. Code: register_cvar ( const name[], const string[], flags = 0, Float:fvalue = 0.0 ) I haven't found any examples where fvalue is used, so please post if you know what it's for. Example Usage: Code: new cvar_MyCvar // this is a pointer new cvar_OtherCvar // this is also a pointer public plugin_init() { // this cvar has no flags assigned cvar_MyCvar = register_cvar("amx_mycvar", "0") // this cvar has two flags assigned cvar_OtherCvar = register_cvar("amx_other", "1", FCVAR_SPONLY|FCVAR_UNLOGGED) } public MyFunction() { if(get_pcvar_num(cvar_MyCvar)) return 1 return 0 } How do they behave? 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 } |