[FIX] Cvar scriptcommand


(kamikazee) #1

For those who ever tried the “cvar” script actions: it’s been partially broken ever since the Era of Sock. More specifically: inc allways increases with 1 although it requires a parameter and set, bitset, bitreset and random do not work at all.

Since I intend to use the cvar command to store map-persistant data (usefull for 2 maps “talking” to each other) I wrote a small fix. Beware that this allows a map script to change any cvar to any numeric value it wants. (Though it has allready been possible before to mess with cvars using the “inc” command. For example, cheats can be turned on in W:ET 2.60 from a map script.)

g_script_actions.c @ 4040

	if (!Q_stricmp(lastToken, "inc")) {
		if (!token[0]) {
			G_Error( "G_Scripting: cvar %s requires a parameter
", lastToken );
		}
-		trap_Cvar_Set( cvarName, va("%i", cvarValue+1) );
+		trap_Cvar_Set( cvarName, va( "%i", cvarValue + atoi( token ) ) );
	} else if (!Q_stricmp(lastToken, "abort_if_less_than")) {
		
g_script_actions.c @ 4077

	} else if (!Q_stricmp(lastToken, "bitset")) {
		if (!token[0]) {
			G_Error( "G_Scripting: cvar %s requires a parameter
", lastToken );
		}
		cvarValue |= (1<<atoi(token));
+		trap_Cvar_Set( cvarName, va( "%i", cvarValue ) );
	} else if (!Q_stricmp(lastToken, "bitreset")) {
		if (!token[0]) {
			G_Error( "G_Scripting: cvar %s requires a parameter
", lastToken );
		}
		cvarValue &= ~(1<<atoi(token));
+		trap_Cvar_Set( cvarName, va( "%i", cvarValue ) );
	} else if (!Q_stricmp(lastToken, "abort_if_bitset")) {
	
g_script_actions.c @ 4105

	} else if (!Q_stricmp(lastToken, "set")) {
		if (!token[0]) {
			G_Error( "G_Scripting: cvar %s requires a parameter
", lastToken );
		}
-		cvarValue = atoi(token);
+		trap_Cvar_Set( cvarName, va( "%i", atoi( token ) ) );
	} else if (!Q_stricmp(lastToken, "random")) {
		if (!token[0]) {
			G_Error( "G_Scripting: cvar %s requires a parameter
", lastToken );
		}
		cvarValue = rand() % atoi(token);
+		trap_Cvar_Set( cvarName, va( "%i", cvarValue ) );
	} else if (!Q_stricmp(lastToken, "trigger_if_equal")) {

(SCDS_reyalP) #2

Nice catch. Server admins can cheat in many ways, so fxing this doesn’t change anything in that respect.

It might be interesting to support string values for the set and *if_equal functions.


(kamikazee) #3

I didn’t change those “_equal” commands to keep the changes minimal. Though you are right that it might be interesting to have string compare functionality.

I’ll take a look at it this evening.


(Calzonzin) #4

Thanks! I have applied your fixes to the etpub source code. It should be included in the upcoming 0.7.1 release.


(Ragnar_40k) #5

I don’t know if this is by design, but something like the following doesn’t work:

accum x trigger_if_equal self a_trigger

To make it work you have to replace “self” with the name of the scriptblock.


(kamikazee) #6

The code of “trigger_if_equal” does not check if the entity name is “self” or “global”, so it’s obvious it doesn’t work. (Both for the cvar and accum commands.)

I’m not going to write a fix for it because it is not broken, it merely lacks a feature. Since vanilla W:ET will probably never see a next patch, I think it is also not worth of adding yet another compatibility-breaking feature when you can technically do without.