Tremulous Forum

Mods => Modding Center => Topic started by: SPK on November 13, 2010, 03:41:22 pm

Title: Noob question --> setting a client var
Post by: SPK on November 13, 2010, 03:41:22 pm
Well I'm just learning to code basic things in QVMs, the only thing is that I dont know C, just the basic programming syntax...
I want to set a client var, and be able to change it on console by '/var value'

BTW I have this:

In g_local.h:    
---------------------------------------

typedef struct
{
...
lang_t           lang;  
...
}

---------------------------------------



In bg_public.h:
--------------------------------------

typedef enum
{
  LANG_ESP,
  LANG_ENG,
  LANG_DEF
} lang_t;

--------------------------------------


In g_client.c:
--------------------------------------

s = Info_ValueForKey( userinfo, "cl_lang" );

  if( !Q_stricmp( s, "esp" )  )
    client->pers.lang =   LANG_ESP;
  else if( !Q_stricmp( s, "eng" )  )
   client->pers.lang = LANG_ENG;
  else
   client->pers.lang = LANG_DEF;

-------------------------------------


Whats the noob thing I'm missing?
Thanks for reading : /

EDIT: Additional obvious info:
I can compile the qvm and check that the server loads it correctly, so dont think about this
Title: Re: Noob question --> setting a client var
Post by: F50 on November 14, 2010, 01:38:35 am
You're looking in the wrong place, try searching the files for the name of an already existing cvar like "cg_teamOverlayMaxPlayers" perhaps, or "cl_useMumble". It isn't that hard to add, don't try to write much code beyond variable declarations and the definition of the cvar (which gives it an initial value). In total it will be around 3 lines of code in a few different files.
Title: Re: Noob question --> setting a client var
Post by: SPK on November 14, 2010, 10:46:05 am
I dont find any of that vars in any file : /
Title: Re: Noob question --> setting a client var
Post by: F50 on November 17, 2010, 10:40:47 pm
My apologies, cg_* variables aren't in the file I'm thinking of. Here is a section of the diff from my build queue slowdown mod (src/game/g_main.c). Playing around with this should give you most of what you want.

Code: [Select]
Index: src/game/g_main.c
===================================================================
--- src/game/g_main.c   (revision 2048)
+++ src/game/g_main.c   (working copy)
@@ -74,6 +74,8 @@
 vmCvar_t  g_minNameChangePeriod;
 vmCvar_t  g_maxNameChanges;

+vmCvar_t  g_buildQueueSlowdown;
+
 vmCvar_t  g_alienBuildPoints;
 vmCvar_t  g_alienBuildQueueTime;
 vmCvar_t  g_humanBuildPoints;
@@ -196,6 +198,8 @@
   { &pmove_fixed, "pmove_fixed", "0", CVAR_SYSTEMINFO, 0, qfalse},
   { &pmove_msec, "pmove_msec", "8", CVAR_SYSTEMINFO, 0, qfalse},

+  { &g_buildQueueSlowdown, "g_buildQueueSlowdown", DEFAULT_BUILD_QUEUE_SLOWDOWN, 0, 0, qfalse  },
+
   { &g_alienBuildPoints, "g_alienBuildPoints", DEFAULT_ALIEN_BUILDPOINTS, 0, 0, qfalse  },
   { &g_alienBuildQueueTime, "g_alienBuildQueueTime", DEFAULT_ALIEN_QUEUE_TIME, CVAR_ARCHIVE, 0, qfalse  },
   { &g_humanBuildPoints, "g_humanBuildPoints", DEFAULT_HUMAN_BUILDPOINTS, 0, 0, qfalse  },
Title: Re: Noob question --> setting a client var
Post by: David on November 17, 2010, 11:29:24 pm
The client needs to have the cvar with CVAR_USERINFO, either from a custom cgame or the user setting it by setu cl_lang eng
Title: Re: Noob question --> setting a client var
Post by: SPK on November 18, 2010, 10:56:02 am
Thank you guys = )  If I get anything I'll post here

EDIT: David, you mean I cannot do anything just with the qvm code? : /
Title: Re: Noob question --> setting a client var
Post by: David on November 18, 2010, 01:37:11 pm
You can, but the user will need to set it with setu instead of set.