Raised This Month: $51 Target: $400
 12% 

Hook convar change


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
maningrey
Member
Join Date: Sep 2014
Location: Farswitch Newton 1
Old 03-21-2015 , 23:27   Hook convar change
Reply With Quote #1

Hello, I've just made this and the first part of the code works, it detects the first command, yet, the second not so much. I'm not sure why?

Code:
new Handle:g_Cvar_EndRestart = INVALID_HANDLE;
new Handle:g_Cvar_ChangeLevel = INVALID_HANDLE;

public OnPluginStart() 
{
	g_Cvar_EndRestart = FindConVar("mp_match_end_restart");
	g_Cvar_ChangeLevel = FindConVar("mp_match_end_changelevel");
	HookConVarChange(g_Cvar_EndRestart, ConVarChange_EndRestart);
	HookConVarChange(g_Cvar_ChangeLevel, ConVarChange_ChangeLevel);
}

public ConVarChange_EndRestart(Handle:convar, const String:oldValue[], const String:newValue[])
{
	if (oldValue[0] == newValue[1])
	{
		ServerCommand("mp_match_end_restart 0");
	}
		
	if (oldValue[1] == newValue[1])
	{
		ServerCommand("mp_match_end_restart 0");
	}
		
	if (oldValue[0] == newValue[0])
	{
		return;
	}
	
	if (oldValue[1] == newValue[0])
	{
		return;
	}
		
}

public ConVarChange_ChangeLevel(Handle:convar, const String:oldValue[], const String:newValue[])
{

	if (oldValue[1] == newValue[0])
	{
		ServerCommand("sm_cvar mp_match_end_changelevel 1");
	}

		
	if (oldValue[0] == newValue[0])
	{
		ServerCommand("sm_cvar mp_match_end_changelevel 1");
	}
	
	if (oldValue[0] == newValue[1])
	{
		return;
	}
	
	if (oldValue[1] == newValue[1])
	{
		return;
	}
	
}

Last edited by maningrey; 03-21-2015 at 23:28.
maningrey is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 03-21-2015 , 23:30   Re: Hook convar change
Reply With Quote #2

Your code looks odd, what do you thing this check does?
PHP Code:
if (oldValue[1] == newValue[0]) 
Instead of using ServerCommand you should use this
PHP Code:
SetConVarInt(g_Cvar_EndRestart0); 
You also don't need more than one convar hook function.
__________________

Last edited by Impact123; 03-21-2015 at 23:59.
Impact123 is offline
maningrey
Member
Join Date: Sep 2014
Location: Farswitch Newton 1
Old 03-21-2015 , 23:46   Re: Hook convar change
Reply With Quote #3

Quote:
Originally Posted by Impact123 View Post
Your code looks odd, what do you thing this checks does?
PHP Code:
if (oldValue[1] == newValue[0]) 
Instead of using ServerCommand you should use this
PHP Code:
SetConVarInt(g_Cvar_EndRestart0); 
You also don't need more than one convar hook function.
This was my bad attempt at getting it to check the old value against the new one, so if a plugin changes it from 0 to 1 it changes it back to 0, ect...
maningrey is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 03-21-2015 , 23:52   Re: Hook convar change
Reply With Quote #4

Well, that's not how strings work, you should read this.
That's one way to do what you want.
Spoiler

Feel free to ask about the code, but please don't full quote me again.
__________________

Last edited by Impact123; 03-22-2015 at 00:00.
Impact123 is offline
maningrey
Member
Join Date: Sep 2014
Location: Farswitch Newton 1
Old 03-21-2015 , 23:56   Re: Hook convar change
Reply With Quote #5

GetConVarInt! very cool, thank you!

Edit: Yep, I see what I did wrong, fail logic ;p thank you

Last edited by maningrey; 03-21-2015 at 23:59.
maningrey 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 05:40.


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