You can't retrieve pcvars on plugin_precache() since precache occurs before plugin_init() where the cvars are registred as pcvars. You have to use regular cvars instead of pointers.
Also, there's no reason to use a pointer on a cvar that's used in precache anyway since it's only called once.
If this is a cvar that enables a function that are in need of the precached file MAKE SURE that the file was precached before starting this function or force precache on all files to make it easy. Otherwise you would require a mapchange just to enable any of the cvars. I'll give you some examples in a minute.
Here are some examples:
This is BAD!
This will cause problems:
Code:
#include <amxmodx>
public plugin_init() {
register_plugin("Test Plugin 8", "", "");
register_cvar("test_cvar", "0", ADMIN_ADMIN);
}
public plugin_precache() {
if ( get_cvar_num("test_cvar") == 1 )
precache_generic("generic.file");
}
public whatever_function(id) {
if ( get_cvar_num("test_cvar") == 1 )
whatever_native(id, "generic.file");
}
This is OK if you have a lot of files to precache:
You really have to know what you're doing if you're using this way.
It creates confusion and problems when people try to enable cvars since it requires a mapchange so that the required files can precache.
Code:
#include <amxmodx>
new g_generic_file_was_precached = false;
public plugin_init() {
register_plugin("Test Plugin 8", "", "");
register_cvar("test_cvar", "0", ADMIN_ADMIN);
}
public plugin_precache() {
if ( get_cvar_num("test_cvar") == 1 ) {
g_generic_file_was_precached = true;
precache_generic("generic.file");
}
}
public whatever_function(id) {
if ( get_cvar_num("test_cvar") == 1 && g_generic_file_was_precached )
whatever_native(id, "generic.file");
}
This is good for most ways:
Code:
#include <amxmodx>
public plugin_init() {
register_plugin("Test Plugin 8", "", "");
register_cvar("test_cvar", "0", ADMIN_ADMIN);
}
public plugin_precache() {
precache_generic("generic.file");
}
public whatever_function(id) {
if ( get_cvar_num("test_cvar") == 1 )
whatever_native(id, "generic.file");
}
In the event_deathmsg() the killer and victim are not always players. Therefor you must check if it actually is a player before you use the variables inside function that require players. The easiest way to check this is:
Code:
if ( ! is_user_connected(killer) || ! is_user_connected(victim) )
return;
Same thing goes for Hook_Deathmessage().
__________________