Raised This Month: $ Target: $400
 0% 

help with some dr vip plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-09-2013 , 19:28   Re: help with some dr vip plugin
Reply With Quote #1

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().
__________________

Last edited by Black Rose; 08-09-2013 at 19:52.
Black Rose is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode