Raised This Month: $ Target: $400
 0% 

execute function on changed cvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stupok
Veteran Member
Join Date: Feb 2006
Old 10-05-2006 , 20:55   execute function on changed cvar
Reply With Quote #1

I want a function to be executed when a cvar is changed. This should be possible by some means, since you can notify the players in the server if the cvar has been changed.

Cvar Flags:
#define FCVAR_ARCHIVE 1 /* set to cause it to be saved to vars.rc */
#define FCVAR_USERINFO 2 /* changes the client's info string */
#define FCVAR_SERVER 4 /* notifies players when changed */
#define FCVAR_EXTDLL 8 /* defined by external DLL */
#define FCVAR_CLIENTDLL 16 /* defined by the client dll */
#define FCVAR_PROTECTED 32 /* It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value */
#define FCVAR_SPONLY 64 /* This cvar cannot be changed by clients connected to a multiplayer server. */
#define FCVAR_PRINTABLEONLY 128 /* This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ). */
#define FCVAR_UNLOGGED 256 /* If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log */

EDIT: I found register_logevent(), but do not know how to use it... so I'll play around with it. Please post the proper way to do this.

Last edited by stupok; 10-05-2006 at 21:10.
stupok is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-05-2006 , 22:13   Re: execute function on changed cvar
Reply With Quote #2

From what I've gathered, register_logevent() probably isn't what I need.

And I can't get FCVAR_SERVER to work!

Here:
Code:
public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_cvar("zombiehp", "300", FCVAR_SERVER) }
stupok is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 10-05-2006 , 22:48   Re: execute function on changed cvar
Reply With Quote #3

register_logevent is exactly what you need. You just have to use it correctly.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 10-05-2006 , 23:36   Re: execute function on changed cvar
Reply With Quote #4

Code:
register_logevent("myFunc",4,"0=Server cvar");

I tried different variations of this for half an hour and could not get it to call once. Then I searched the forums for it, and found this topic: http://forums.alliedmods.net/showthread.php?t=5450

PM suggests doing exactly what I did (plus adding an extra argument for specific cvar matching), and EKS reports that it didn't work for him either.

Can logevent actually catch this one? It appears in the server log alright, but it won't call the function.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 10-06-2006 , 00:02   Re: execute function on changed cvar
Reply With Quote #5

I've used it before, and it worked. I think I had the cvar set with a flag or something. I'll have to go and look at what I had before.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
stupok
Veteran Member
Join Date: Feb 2006
Old 10-25-2006 , 19:43   Re: execute function on changed cvar
Reply With Quote #6

I was hoping that you would find the example and post it, but I forgot about this topic and let it sit for a month . I would really appreciate it if you could show me what you did with flagging the cvar or whatever it was.

I can't get register_logevent to call a function upon changing a cvar...
stupok is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-29-2006 , 12:08   Re: execute function on changed cvar
Reply With Quote #7

bump

Xanimos is probably the only one that has a solution to this, but any help would be appreciated.
stupok is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 10-31-2006 , 10:45   Re: execute function on changed cvar
Reply With Quote #8

I do not think you can do it (at least with the current amxx version).
My guess that it could print the line (which isn't hookable via at_logged AlertMessage)
Quote:
Server cvar "cvar_name" = "cvar_value"
via pfnServerPrint, which can't be currently hooked (forward isn't implemented (yet?)).

Last edited by VEN; 10-31-2006 at 10:47.
VEN is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 10-31-2006 , 12:52   Re: execute function on changed cvar
Reply With Quote #9

could you do this?
Code:
register_cvar("test_cvar", "1")   public client_PreThink(id) {     if(get_cvar_num("test_cvar") != 1) {         log_amx("CVAR HAS CHANGED")     }     else {         log_amx("CVAR HASN'T CHANGED")     } }
just using pre_think as an example so it is continuously checked but this may not be what he means...
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 10-31-2006 , 14:27   Re: execute function on changed cvar
Reply With Quote #10

pre/postthink shouldn't be used for non-player issues, it should be checked every server frame or at least with a few time interval.
VEN 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 04:51.


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