Forum

quakec cvar change

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Postby mh » Tue Mar 01, 2011 9:13 pm

Spike wrote:stuffcmd(foo, "sv_foo\n");

forgive me while I vomit....

*vomits*

try localcmd("sv_foo\n"); instead. It'll probably work more reliably.

Won't silence the prints though.
You should use grep/find-in-files for that instead. "'%s' changed to '%s'\n" will probably turf something up.

<rant>
It always bemuses me why "stuffcmd" is seen as being the way to do anything through QC. There's already a perfectly good "cvar_set" builtin; you don't need stuffcmd at all here. True, it'll only work on the server, but this is a server cvar anyway.
Code: Select all
cvar_set ("sv_maxspeed", "250");

There's also a perfectly good "cvar" builtin that you can use to get the original value, so that you can restore it properly when you're finished having your evil ways with it.

Would people please stop recommending "stuffcmd" unless you're absolutely certain that it's the only way?
</rant>
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby behind_you » Tue Mar 01, 2011 9:20 pm

mh wrote:In the Cvar_Set function, this is the block of code that you need to remove:
Code: Select all
 if (var->server && changed)
 {
  if (sv.active)
   SV_BroadcastPrintf (""%s" changed to "%s"\n", var->name, var->string);
 }


Thanks a million. Compiling code now.

Btw stuffcmd and localcmd. Is the dfference that local affects only the client who changed the cvar and stuff affects everyone no matter what? Correct me if im mistaken
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby behind_you » Tue Mar 01, 2011 9:36 pm

mh wrote:<rant>
It always bemuses me why "stuffcmd" is seen as being the way to do anything through QC. There's already a perfectly good "cvar_set" builtin; you don't need stuffcmd at all here. True, it'll only work on the server, but this is a server cvar anyway.
Code: Select all
cvar_set ("sv_maxspeed", "250");

There's also a perfectly good "cvar" builtin that you can use to get the original value, so that you can restore it properly when you're finished having your evil ways with it.

Would people please stop recommending "stuffcmd" unless you're absolutely certain that it's the only way?
</rant>


Hold the phone. Used cvar_set and got a warning: 'type mismatch on parm 0. Expected string, found entity'. Never got this with stuff cmd. Localcmd gave me 4 warnings similar to cvar_set.
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby mh » Tue Mar 01, 2011 9:38 pm

stuffcmd lets you specify a specific client to send the command to whereas localcmd executes the command locally on the server (Quake has a client/server architecture which you'd need to become familiar with for anything more detailed to make sense). The differences really only apply to multiplayer games, but you should be aware of them.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby mh » Tue Mar 01, 2011 9:41 pm

behind_you wrote:
mh wrote:<rant>
It always bemuses me why "stuffcmd" is seen as being the way to do anything through QC. There's already a perfectly good "cvar_set" builtin; you don't need stuffcmd at all here. True, it'll only work on the server, but this is a server cvar anyway.
Code: Select all
cvar_set ("sv_maxspeed", "250");

There's also a perfectly good "cvar" builtin that you can use to get the original value, so that you can restore it properly when you're finished having your evil ways with it.

Would people please stop recommending "stuffcmd" unless you're absolutely certain that it's the only way?
</rant>


Hold the phone. Used cvar_set and got a warning: 'type mismatch on parm 0. Expected string, found entity'. Never got this with stuff cmd. Localcmd gave me 4 warnings similar to cvar_set.

That's likely because you just replaced the text "stuffcmd" with "cvar_set", as in:
Code: Select all
cvar_set (self, "sv_maxspeed 250\n");

It doesn't work that way; if you want to set the value of sv_maxspeed to 250 you need this:
Code: Select all
cvar_set ("sv_maxspeed", "250");

Don't worry that 250 is a string here, the engine will convert it behind the scenes.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby behind_you » Tue Mar 01, 2011 9:44 pm

hahahahaa......oops
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby mh » Tue Mar 01, 2011 9:50 pm

You should see some of the mistakes I've made in the past... :lol:
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby behind_you » Tue Mar 01, 2011 11:45 pm

mh wrote:You should see some of the mistakes I've made in the past... :lol:


Probably not as bad as i am now! Im a mess...
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby Ranger366 » Wed Mar 02, 2011 5:56 am

mh wrote:stuffcmd lets you specify a specific client to send the command to whereas localcmd executes the command locally on the server (Quake has a client/server architecture which you'd need to become familiar with for anything more detailed to make sense). The differences really only apply to multiplayer games, but you should be aware of them.


Whoa, sorry forgot that its serverside urgh.
Im feeling bad now. :(
I apologise for that.

I thought he could use stuffcmd because he is doing a SinglePlayer shooter.
User avatar
Ranger366
 
Posts: 203
Joined: Thu Mar 18, 2010 5:51 pm

Postby mh » Wed Mar 02, 2011 10:10 am

Ranger366 wrote:I thought he could use stuffcmd because he is doing a SinglePlayer shooter.

Well he can, but he really should use cvar_set to set a cvar. :wink:
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Ranger366 » Wed Mar 02, 2011 10:43 am

Anyway, he learned 3 more commands!
Congratulations! :)
User avatar
Ranger366
 
Posts: 203
Joined: Thu Mar 18, 2010 5:51 pm

Postby behind_you » Wed Mar 02, 2011 11:56 am

well, did some comparison testing

Theyre the same, but cvar_set takes effect a tiny bit faster than the others. Im now making the player slow down when crouched. I tried rapidly ducking and 'un'ducking and stuffcmd didnt restore the speed AKA i was standing but moving at crouching speed. Cvar_set didnt do this. But its a very small time difference. Thank u very much!!!
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby Spike » Wed Mar 02, 2011 2:36 pm

is there no .float maxspeed; field?... or is that my imagination?
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Previous

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest