View Single Post
Author Message
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 07-19-2018 , 14:14   Pass ConVar value to other plugins
Reply With Quote #1

I will work on a "master/core" plugin with some Cvars(8+).
I need to pass the values of these Cvars to other "slave plugins/modules".
The values are planned to read only once by the "slaves/modules" during OnConfigsExecuted().
There will be 10+ "slaves/modules" that need these values.

What is the "best", less expensive &/or smartest way?

FindConVar or native or even a forward? and why?
Or is there a better/other way I'm missing?


"FindConVar"-Way
Quote:
Core plugin
PHP Code:
public void OnPluginStart()
{
    
gc_sName CreateConVar("plugin_name""Name""");
    
gc_iTime CreateConVar("plugin_time""10.0""");

Less code on core.
Least code at all.

ok to make it foolproof I should hook convar change too.

this way many plugins call the same convars from convar-cache(?)

Module plugin
PHP Code:
public void OnConfigsExecuted()
{
    
ConVar cBuffer FindConVar("plugin_name");
    
cBuffer.GetString(g_sNamesizeof(g_sName));

    
cBuffer FindConVar("plugin_time");
    
g_fTime cBuffer.FloatValue;



"Native"-Way
Quote:
Core plugin
PHP Code:
public void OnPluginStart()
{
    
gc_sName CreateConVar("myplugin_name""Name""");
    
gc_fTime CreateConVar("myplugin_time""10.0""");
}

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
CreateNative("MyPlugin_Name"Native_Name);
    
CreateNative("MyPlugin_Time"Native_Time);

    
RegPluginLibrary("myplugin");
}

public 
int Native_Name(Handle pluginint args)
{
    
char sName[32];
    
gc_sName.GetString(sNamesizeof(sName));
    
SetNativeString(1sNamesizeof(sName));
}

public 
int Native_Time(Handle pluginint args)
{
    return 
gc_fTime.FloatValue;

more code on core - less work on modules

This way many api calls to the core module(?)

Module plugin
PHP Code:
#include myplugin

public void OnConfigsExecuted()
{
    
MyPlugin_Name(g_sName);

    
g_fTime MyPlugin_Time();



"Forward"-Way
Quote:
Core plugin
PHP Code:
public void OnPluginStart()
{
    
gc_sName CreateConVar("plugin_name""Name""");
    
gc_iTime CreateConVar("plugin_time""10.0""");
}

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
g_hSendConfig CreateGlobalForward("MyPlugin_Config"ET_IgnoreParam_StringParam_Cell);

    
RegPluginLibrary("myplugin");
}

public 
int OnConfigsExecuted()
{
    
char sName[32];
    
gc_sName.GetString(sNamesizeof(sName));

    
Call_StartForward(g_hSendConfig);
    
Call_PushString(sName);
    
Call_PushFloat(gc_fTime.FloatValue);
    
Call_Finish();

more code on core - less work on modules

This way the forward will only called once and all plugins will recieve the values.
I assume this is the less expensive way.

Module plugin
PHP Code:
#include myplugin

public void MyPlugin_Config(char[] namefloat time)
{
    
Format(g_sNamesizeof(g_sName), name);
    
g_fTime time;

I know there are maybe some missing lines, missing var declartions or rather HookConVarChanges.
These example codes are just for better visualization of the question.

From the point of writing new modules I would prefer natives or forwards.
My gut tells me to use forwards.

What do you think? Thanks for reading!
__________________
coding & free software

Last edited by shanapu; 07-21-2018 at 15:26.
shanapu is offline