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

Get Cvars Changes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 05-25-2009 , 02:31   Get Cvars Changes
Reply With Quote #1

Only have a little problem with Some Float Returns, Example you put 220.1 the plugin return 220.09999999

PLUGIN:
PHP Code:
// #define USE_FAKEMETA

#include <amxmodx>

#if defined USE_FAKEMETA
#include <fakemeta>
#else
#include <engine>
#endif

new Array:g_CvarHolds
new Array:g_CvarType
new Array:g_CvarFwd
new Array:g_CvarData


public plugin_precache() 
{
    
register_plugin("Cvars Change""1.0""ReymonARG")
    
    
g_CvarHolds ArrayCreate(11)
    
g_CvarType ArrayCreate(11)
    
g_CvarData ArrayCreate(1281)
    
g_CvarFwd ArrayCreate(11)
    
    
#if defined USE_FAKEMETA
    
register_forward(FM_StartFrame"server_frame")
    
#endif
}

public 
plugin_natives()
{
    
register_library("ReymonARG_Cvars")
    
register_native("register_cvar_change""__cvar_change_add")
    
register_native("unregister_cvar_change""__cvar_change_delete")
}

public 
__cvar_change_addiPluginiParams )
{
    if( 
iParams != )
        return 
log_error(AMX_ERR_NATIVE"Invalid Params Nums %d"iParams)
        
    static 
szCvar[64]; get_string(2szCvar63)
    if( !
cvar_exists(szCvar) )
        return 
log_error(AMX_ERR_NATIVE"Cvar: %s No Exists"szCvar)
        
    static 
fwd_idiTypeiType get_param(1)
    static 
szCallBack[32]; get_string(3szCallBack31)
    
    switch( 
iType )
    {
        case 
1fwd_id CreateOneForward(iPluginszCallBackFP_CELLFP_CELLFP_CELL)
        case 
2fwd_id CreateOneForward(iPluginszCallBackFP_CELLFP_FLOATFP_FLOAT)
        case 
3fwd_id CreateOneForward(iPluginszCallBackFP_CELLFP_STRINGFP_STRING)
        default: return 
log_error(AMX_ERR_NATIVE"%d Dont is a Correct Type Cvar"iType)
    }
    
    if( 
fwd_id )
        return 
log_error(AMX_ERR_NATIVE"Correct the CallBack Funcion")
        
    
    static 
pCvarpCvar get_cvar_pointer(szCvar)
    
ArrayPushCell(g_CvarHoldspCvar)
    
ArrayPushCell(g_CvarTypeiType)
    
    switch( 
iType )
    {
        case 
1:
        {
            static 
iResultiResult get_pcvar_num(pCvar)
            
ArrayPushCell(g_CvarDataiResult)
        }
        case 
2:
        {
            static 
Float:fResultfResult get_pcvar_float(pCvar)
            
ArrayPushCell(g_CvarDatafResult)
        }
        case 
3:
        {
            static 
szResult[128]; get_pcvar_string(pCvarszResult127)
            
ArrayPushString(g_CvarDataszResult)
        }
    }
    
    
ArrayPushCell(g_CvarFwdfwd_id)
    return 
fwd_id    
}

public 
__cvar_change_deleteiPluginiParams )
{
    if( 
iParams != )
        return 
log_error(AMX_ERR_NATIVE"Invalid Params Nums %d"iParams)
        
    static 
ifwd_idlenlen ArraySize(g_CvarFwd)
    
fwd_id get_param(1)
    
    for( 
0leni++)
    {
        if( 
ArrayGetCell(g_CvarFwdi) == fwd_id )
        {
            
ArrayDeleteItem(g_CvarHoldsi)
            
ArrayDeleteItem(g_CvarTypei)
            
ArrayDeleteItem(g_CvarDatai)
            
ArrayDeleteItem(g_CvarFwdi)
            
DestroyForward(fwd_id)
            
            return 
1
        
}
    }
    
    return 
0
}

public 
server_frame()
{
    static 
itypeidCvariReturnlenlen ArraySize(g_CvarFwd)
    static 
iResult[2], Float:fResult[2], szResult[2][128]
    
    for( 
0leni++)
    {
        
type ArrayGetCell(g_CvarTypei)
        
idCvar ArrayGetCell(g_CvarHoldsi)
        switch( 
type )
        {
            case 
1:
            {
                
iResult[0] = ArrayGetCell(g_CvarDatai)
                
iResult[1] = get_pcvar_num(idCvar)
                if( 
iResult[0] != iResult[1] )
                {
                    static 
idid ArrayGetCell(g_CvarFwdi)
                    
ExecuteForward(idiReturnidiResult[0], iResult[1])
                    
                    if( 
iReturn )
                    {
                        
set_pcvar_num(idCvariResult[0])
                        
iReturn 0
                    
}
                    else
                    {
                        
ArraySetCell(g_CvarDataiiResult[1])
                    }
                }
            }
            case 
2:
            {
                
fResult[0] = ArrayGetCell(g_CvarDatai)
                
fResult[1] = get_pcvar_float(idCvar)
                if( 
fResult[0] != fResult[1] )
                {
                    static 
idid ArrayGetCell(g_CvarFwdi)
                    
ExecuteForward(idiReturnidfResult[0], fResult[1])
                    
                    if( 
iReturn )
                    {
                        
set_pcvar_float(idCvarfResult[0])
                        
iReturn 0
                    
}
                    else
                    {
                        
ArraySetCell(g_CvarDataifResult[1])
                    }
                }
            }
            case 
3:
            {
                
ArrayGetString(g_CvarDataiszResult[0], 127)
                
get_pcvar_string(idCvarszResult[1], 127)
                if( !
equal(szResult[0], szResult[1]) )
                {
                    static 
idid ArrayGetCell(g_CvarFwdi)
                    
ExecuteForward(idiReturnidszResult[0], szResult[1])
                    
                    if( 
iReturn )
                    {
                        
set_pcvar_string(idCvarszResult[0])
                        
iReturn 0
                    
}
                    else
                    {
                        
ArraySetString(g_CvarDataiszResult[1])
                    }
                }
            }
        }            
    }

INC:
PHP Code:
#if defined _cvarchange_included
  #endinput
#endif
#define _cvarchange_included

#if AMXX_VERSION_NUM >= 175
 #pragma reqlib ReymonARG_Cvars
 #if !defined AMXMODX_NOAUTOLOAD
  #pragma loadlib ReymonARG_Cvars
 #endif
#else
 #pragma library ReymonARG_Cvars
#endif

enum Type
{
    
cvarINT 1,
    
cvarFL 2,
    
cvarSZ 3
}

native register_cvar_change(Type:type, const Cvar[], const CallBack[])
native unregister_cvar_change(fwd_id
EXAMPLE:
PHP Code:
#include <amxmodx>
#include <cvarchange>

#define PLUGIN "Cvar xD"
#define VERSION "1.0"
#define AUTHOR "ReymonARG"


public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_cvar_change(cvarINT"mp_friendlyfire""ffback")
    
register_cvar_change(cvarFL"kz_min_lj""ljmin")
    
register_cvar_change(cvarSZ"amx_nextmap""nextmap")
}

public 
ffbackidprepost)
{
    
server_print("%d %d %d"idprepost)
    return 
1
}

public 
ljminidFloat:preFloat:post)
{
    
server_print("%d %f %f"idprepost)
}

public 
nextmap(id, const pre[], const post[])
{
    
server_print("%d %s %s"idprepost)

Thanks, Correct me if I do something wrong
Attached Files
File Type: sma Get Plugin or Get Source (cvar_change.sma - 880 views - 4.3 KB)
File Type: inc cvarchange.inc (450 Bytes, 196 views)
File Type: sma Get Plugin or Get Source (cvar_change_test.sma - 846 views - 395 Bytes)
__________________

Last edited by AntiBots; 05-25-2009 at 02:48.
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-25-2009 , 05:11   Re: Get Cvars Changes
Reply With Quote #2

Using such forward which called very often + using dynamic array which are slow + comparing like that, it should eat a lot of cpu for nothing. I don't think it's a good solution, AntiBots. I still prefer to use directly a command if you want to detect a change.

Last edited by Arkshine; 05-25-2009 at 05:15.
Arkshine is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 05-25-2009 , 08:07   Re: Get Cvars Changes
Reply With Quote #3

arkshine is right!
I think that it is better to create a menu that allow you to manipulate cvars.
You can take a look at the code of this plugin.
http://forums.alliedmods.net/showthread.php?p=651444

Btw. Are these forwards good?
Code:
	FM_CVarGetFloat,		// float )	(const szCvar[])
	FM_CVarGetString,		// char )	(const szCvar[])
	FM_CVarSetFloat,		// void )	(const szCvar[], Float:fValue)
	FM_CVarSetString,		// void )	(const szCvar[], szValue[])
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 05-25-2009 , 11:23   Re: Get Cvars Changes
Reply With Quote #4

Quote:
Originally Posted by AntiBots View Post
Only have a little problem with Some Float Returns, Example you put 220.1 the plugin return 220.09999999
Same problem =\
http://forums.alliedmods.net/showthread.php?t=92964
__________________
xPaw is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 05-25-2009 , 14:44   Re: Get Cvars Changes
Reply With Quote #5

This is a solution for the problem but a bad one and I fear you won't find a better one. This is basically the one thing I'm so awesomely jealous of SourceMod - ConVar Handles.
__________________
In Flames we trust!
Nextra is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-25-2009 , 14:50   Re: Get Cvars Changes
Reply With Quote #6

Quote:
Originally Posted by Nextra View Post
This is a solution for the problem but a bad one and I fear you won't find a better one. This is basically the one thing I'm so awesomely jealous of SourceMod - ConVar Handles.
Yes, you can find a better one, but it has to be made.
Forwards can be made with a module, or with an update to the current amxmodx module.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 05-26-2009 , 07:48   Re: Get Cvars Changes
Reply With Quote #7

Quote:
Originally Posted by ot_207 View Post
arkshine is right!
I think that it is better to create a menu that allow you to manipulate cvars.
You can take a look at the code of this plugin.
http://forums.alliedmods.net/showthread.php?p=651444

Btw. Are these forwards good?
Code:
    FM_CVarGetFloat,        // float )    (const szCvar[])
    FM_CVarGetString,        // char )    (const szCvar[])
    FM_CVarSetFloat,        // void )    (const szCvar[], Float:fValue)
    FM_CVarSetString,        // void )    (const szCvar[], szValue[])
those forwards wont work, the CVarGet fwds are called when the engine tries to get a cvar (sv_clientrace and sv_aim will spam the console on debug) and the set forwards when the engine sets some cvar. they seem to do not support cvars which are created through amxx.
__________________
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 05-26-2009 , 08:09   Re: Get Cvars Changes
Reply With Quote #8

Quote:
Originally Posted by SchlumPF* View Post
those forwards wont work, the CVarGet fwds are called when the engine tries to get a cvar (sv_clientrace and sv_aim will spam the console on debug) and the set forwards when the engine sets some cvar. they seem to do not support cvars which are created through amxx.
Ok
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 05-29-2009 , 07:48   Re: Get Cvars Changes
Reply With Quote #9

Quote:
Originally Posted by Exolent[jNr] View Post
Yes, you can find a better one, but it has to be made.
Forwards can be made with a module, or with an update to the current amxmodx module.
I was thinking of this excerpt from the DevLog:

Quote:
The other major difference is that HL2 engine passes ConVar changes through a callback. Thus, you can detect changes without making a secondary console command. This was not possible in HL1. Although you could hook SET_CVAR_FLOAT, it was not virtual, and thus internal or plugin usage of it would not be caught. Also, the change callbacks are per-ConVar; HL1’s is global, and thus a bit less optimized.
http://www.sourcemod.net/devlog/?p=131
__________________
In Flames we trust!
Nextra is offline
vittu
SuperHero Moderator
Join Date: Oct 2004
Location: L.A. County, CA
Old 06-03-2009 , 03:18   Re: Get Cvars Changes
Reply With Quote #10

Quote:
Originally Posted by AntiBots View Post
Only have a little problem with Some Float Returns, Example you put 220.1 the plugin return 220.09999999
adding a 0 to the end should fix that, ie 220.10

Last edited by vittu; 06-03-2009 at 03:24.
vittu is offline
Send a message via AIM to vittu Send a message via MSN to vittu Send a message via Yahoo to vittu
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 20:53.


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