Raised This Month: $ Target: $400
 0% 

Stack error with hook_cvar_change


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
luxor
Member
Join Date: Jan 2014
Old 12-27-2015 , 19:51   Re: Stack error with hook_cvar_change
Reply With Quote #1

Quote:
Originally Posted by PartialCloning View Post
I didn't expect it to not work with PLUGIN_HANDLED; I edited it now, it should work. I know you already found your own solution, but:

1. The code above might be simpler if you used a different method.
2. You did not share your solution, meaning if someone looks up a similar problem they won't know how to fix it, now they know.
Code:
#include <amxmisc>

#if AMXX_VERSION_NUM < 183 
    #assert AMX Mod X v1.8.3 or later library required!
#endif

new RconPasswordValue[64];

public plugin_init()
{
	register_plugin
	(
		.plugin_name = "Block changing rcon_password",
		.version     = "1.0",
		.author      = "lüxor"
	);
	new RconPasswordCvarPointer = get_cvar_pointer("rcon_password");
	get_pcvar_string(RconPasswordCvarPointer, RconPasswordValue, charsmax(RconPasswordValue));
	hook_cvar_change(RconPasswordCvarPointer, "setDefaultValue");
}

public setDefaultValue(PointerCvar, const OldValue[], const NewValue[])
{
	if ( !equal(NewValue, RconPasswordValue, charsmax(RconPasswordValue)) )
	{
		set_pcvar_string(PointerCvar, OldValue);
	}
}
luxor is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 12-27-2015 , 20:52   Re: Stack error with hook_cvar_change
Reply With Quote #2

Quote:
Originally Posted by luxor View Post
Code:
#include <amxmisc>

#if AMXX_VERSION_NUM < 183 
    #assert AMX Mod X v1.8.3 or later library required!
#endif

new RconPasswordValue[64];

public plugin_init()
{
	register_plugin
	(
		.plugin_name = "Block changing rcon_password",
		.version     = "1.0",
		.author      = "lüxor"
	);
	new RconPasswordCvarPointer = get_cvar_pointer("rcon_password");
	get_pcvar_string(RconPasswordCvarPointer, RconPasswordValue, charsmax(RconPasswordValue));
	hook_cvar_change(RconPasswordCvarPointer, "setDefaultValue");
}

public setDefaultValue(PointerCvar, const OldValue[], const NewValue[])
{
	if ( !equal(NewValue, RconPasswordValue, charsmax(RconPasswordValue)) )
	{
		set_pcvar_string(PointerCvar, OldValue);
	}
}
That is a sane solution in my opinion.

Last edited by WildCard65; 12-27-2015 at 20:53.
WildCard65 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 17:52.


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