custom enetity question


(ACROBAT) #1

I kind of want a custom entity so that you can toggle the \pmove_fixed command on and off. It’s a serverside command.

What would this entail? Just a custom entity but u need to know C++ to do it?

Any ideas how I could get this done?

Any ideas who could help me with this or point be to the best tutorials to learn it?


(ACROBAT) #2

bump bump bump up


(Nail) #3

possibly lua ?


(C) #4

There is this script-command to set a cvar:
cvar <cvarName> set <value>

Possible implementation:

  • create a trigger_multiple,

  • give it a scriptname & targetname: pmove_toggle

  • give the trigger_multiple a key/value: wait = 5

  • create some mapscript for the trigger:

// accum 0 = (0=pmove off, 1=pmove on)
pmove_toggle
{
    spawn
    {
        accum 0 set 0
    }
    activate
    {
        trigger self on
        trigger self off
    }
    trigger on
    {
        accum 0 abort_if_equal 1
        accum 0 set 1
        cvar pmove_fixed set 1
    }
    trigger off
    {
        accum 0 abort_if_equal 0
        accum 0 set 0
        cvar pmove_fixed set 0
    }
}

If You walk in the trigger, the pmove_fixed value will be toggled on/off…
You can do that every 5 seconds… If You keep standing in the trigger, it keeps toggling.
Possibly use some other implementation, this is just an example.


(TomTom7777) #5

[QUOTE=C;191213]There is this script-command to set a cvar:
cvar <cvarName> set <value>

…[/QUOTE]

Be forewarned the map script commands for cvars are bugged non-functional in original ET, so cvar <cvarName> set <value> will only work in a major mod that implements the required bug fixes. The only thing you can do to change a cvar in the map script universally is increment it by 1, so you could toggle pmove_fixed once (if initialy zero) but not back with this command in plain ET.


(ACROBAT) #6

You can change pmove_fixed on the client side but it won’t help you jump better so it needs to be done on the server side.

Is it possible for a player in game to alter that?


(C) #7

i used a CVAR before in some mapscript, and it worked perfectly…
But, i must say that, it was a custom CVAR,… i just made one up because i needed one value stored…
It could be different than a regular ET CVAR… i do not know. i take Your word for it.

And if it would be so, that one can only “inc” a CVAR, then inc “-1” could possibly also work, and a toggle-function can still be made…
Test it, and You know it.


(TomTom7777) #8

[QUOTE=C;191222]i used a CVAR before in some mapscript, and it worked perfectly…
But, i must say that, it was a custom CVAR,… i just made one up because i needed one value stored…
It could be different than a regular ET CVAR… i do not know. i take Your word for it.

And if it would be so, that one can only “inc” a CVAR, then inc “-1” could possibly also work, and a toggle-function can still be made…
Test it, and You know it.[/QUOTE]

Here’s the problem code in g_script_actions.c (2.55 and 2.60) with respect to “inc” (with my comments added in CAPS)

/*
===================
G_ScriptAction_Cvar

  syntax: cvar <cvarName> <operation> <value>
===================
*/
[B]//FUNCTION IS CALLED AFTER A CALLING ROUTINE SEES THE WORD "cvar"[/B]
qboolean G_ScriptAction_Cvar( gentity_t *ent, char *params )
{
	char *pString, *token, lastToken[MAX_QPATH], name[MAX_QPATH], cvarName[MAX_QPATH];
	int cvarValue;
	qboolean terminate, found;

	pString = params;
[B]//CODE STARTS HERE...[/B]
[B]//CHECK FIRST WORD AFTER "cvar" i.e get name of cvar[/B]
	token = COM_ParseExt( &pString, qfalse );
	if (!token[0]) {
		G_Error( "G_Scripting: cvar without a cvar name
" );
	}
	Q_strncpyz( cvarName, token, sizeof( cvarName ) );
[B]//GET VALUE OF SPECIFIED PREEXISTING CVAR, or get 0 otherwise[/B]
	cvarValue = trap_Cvar_VariableIntegerValue( cvarName );
[B]//CHECK FOR SECOND WORD AFTER "cvar" i.e. the command <operation>[/B]
	token = COM_ParseExt( &pString, qfalse );
	if (!token[0]) {
		G_Error( "G_Scripting: cvar without a command
" );
	}

	Q_strncpyz( lastToken, token, sizeof(lastToken) );
[B]//AND GET THE VALUE AND PUT IT IN token[/B]
	token = COM_ParseExt( &pString, qfalse );
[B]//AND IF THE COMMAND IS TO INCREMENT i.e. "inc"[/B]
	if (!Q_stricmp(lastToken, "inc")) {
		if (!token[0]) {
			G_Error( "G_Scripting: cvar %s requires a parameter
", lastToken );
		}
[B]//HERE IS THE BUG FOR "inc"[/B]
		trap_Cvar_Set( cvarName, va("%i", [B]cvarValue+1[/B]) );
	}
[B]//CODE CONTINUES FOR OTHER COMMANDS...[/B]

So the problem code is cvarValue+1 instead of adding the numeric value of token to cvarValue. Basically it always adds 1 ignoring the value specified.
The same function fails to use the trap_Cvar_set call for set, bitset and bitreset so it does not change the specified cvar for those commands. As I said this bug is well know so at least one of the major mods includes a fix for it.