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

On convar change...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AKAYEE
Junior Member
Join Date: Apr 2020
Old 04-22-2020 , 08:20   On convar change...
Reply With Quote #1

Hello, i need some help with scripting.

I have plugin one, lets call it A, and second plugin, lets call it B.

In plugin A i create a convar sm_stoprecord with default value 0, and onMapEnd it changes value from 0 to 1.

In plugin B i want to register that convar from plugin A changed value from 0 to 1 and if that happened execute some code.

I'm relatively new to SourcePawn so I need some help with that, thanks in advance! (Game: CS:GO)
AKAYEE is offline
Balimbanana
Member
Join Date: Jan 2017
Old 04-22-2020 , 12:21   Re: On convar change...
Reply With Quote #2

Plugin A:
Code:
public void OnPluginStart()
{
	Handle cvar = FindConVar("sm_stoprecord");
	if (cvar == INVALID_HANDLE) cvar = CreateConVar("sm_stoprecord", "0", "Description", _, true, 0.0, true, 1.0);
	CloseHandle(cvar);
}

public void OnMapEnd()
{
	Handle cvar = FindConVar("sm_stoprecord");
	if (cvar != INVALID_HANDLE) SetConVarInt(cvar,1,false,false);
	CloseHandle(cvar);
}
Plugin B:
Code:
public void OnAllPluginsLoaded()
{
	Handle cvar = FindConVar("sm_stoprecord");
	if (cvar != INVALID_HANDLE) HookConVarChange(cvar,StopRecordChanged);
	CloseHandle(cvar);
}

public void StopRecordChanged(Handle convar, const char[] oldValue, const char[] newValue)
{
	if (StringToInt(newValue) == 1)
	{
		//stuff
	}
	else
	{
		//stuff
	}
}
You could also set the CVar in plugin A to be a global handle, but it isn't really necessary.
Balimbanana is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 04-22-2020 , 12:29   Re: On convar change...
Reply With Quote #3

You don't need CloseHandle. Those ConVar handles registered globally and can't be closed until server reboot.

FindConVar does not duplicate handle.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 04-22-2020 at 12:31.
Dragokas is offline
AKAYEE
Junior Member
Join Date: Apr 2020
Old 04-22-2020 , 15:11   Re: On convar change...
Reply With Quote #4

Thank you a lot @Balimbanana that's just what I needed.
AKAYEE 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 23:13.


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