Custom Cvar In PM_CheckJump (bg_pmove.c)


(the_hat) #1

i made a custom cvar “works” and im try’n to use it in game/bg_pmove.c in “PM_CheckJump”, my code:


static qboolean PM_CheckJump( void ) {
.....
	if ( g_hatstraft.integer == 0 ) {
		if (pm->cmd.serverTime - pm->ps->jumpTime < 850)	// Arnout: NOTE : TEMP DEBUG
		return qfalse;
	}
.....

but i this error:

error C2065: 'g_hatstraft' : undeclared identifier

anyone know a way around this? or correct way?


(digibob) #2

PMove code is shared between client and server, so you can’t just simply use a cvar in there. You’ll need to have the cvar on the server and send it to the client in some way, either thru serverinfo, or another configstring. Next, create another field to the pmove struct, and before calling pmove, set it to the correct paramater on either the server/client. Use this field to do your check instead of the cvar.


(bani) #3

Don’t forget to realign the antimatter injectors and invert the polarity of the containment field.


(digibob) #4

And charge the flux capacitor!


(KillerKind) #5

LMAO!


(the_hat) #6

heh :!

try’n to pass it thru server info,

in cgame/cg_servercmds.c


void CG_ParseServerinfo( void ) {
.......
	int		hatstraft;
.......
	hatstraft = atoi( Info_ValueForKey( info, "g_hatstraft" ) );
	trap_Cvar_Set("g_hatstraft", va("%i", hatstraft));
.......
}

in game/bg_pmove.c


static qboolean PM_CheckJump( void ) {
	char curmap[64];
......
	trap_Cvar_VariableStringBuffer( "g_hatstraft", curmap, 64 );

	if ( curmap == 0 ) {
		if (pm->cmd.serverTime - pm->ps->jumpTime < 850)	// Arnout: NOTE : TEMP DEBUG
		return qfalse;
	}
.........
}

compiles fine, but ingame i change g_hatstraft, reload map, doesnt change anything :! see anything im doing wrong?


(fretn) #7

I think you have to check in g_updatecvars if your cvar is updated or not, if it is, send a configstring to the client


(the_hat) #8

thnx :slight_smile:


(Rain) #9

You should make the cvar on the server side CVAR_SYSTEMINFO–this way, it’ll automatically be sent and set on the client. You should make the cvar on the client CVAR_ROM so that players can’t muck with it (the server’s updates will still work, though.)


(the_hat) #10

Rain, well, thats what im try’n todo, i have the server side cvar set with CVAR_SYSTEMINFO, and then make a client side cvar set to CVAR_ROM, i just donno what todo after that, u said it will auto be sent to client right? how, where? and if so, how could i then use it on/in BG_PMOVE? seeing that its shared betwix both game and cgame. :!


(digibob) #11

Er, curmap will never be 0 :slight_smile: It’s a pointer to an array of chars on the stack, so your check there will never work.

I would also suggest not using trap_Cvar_VariableStringBuffer inside pmove either, add an extra field to the pmove struct as i mentioned, and set it on the server/client before running pmove.


(the_hat) #12

hehe, yeah it is really stupid to use trap_Cvar_VariableStringBuffer inside pmove… donno what i was thinking :stuck_out_tongue:


(Rain) #13

Well, CVAR_SYSTEMINFO cvars are sent to the client, which will automatically set the same cvar to the value the server is using (point being that you won’t have to do it manually.)

As far as using the variable inside of bg_pmove, take a look at how the pmove_fixed cvar is used–passing the var in the pmove struct is cleanest, although you can take the ugly route and use ifdef hell (see the way g_gametype/cg_gametype is used for some parts of pmove.)