Go Back   Steam Users' Forums > Steam Tool Discussions > Source Coding

Thread Tools Display Modes
Old 11-04-2009, 02:18 PM   #1
Posts: n/a
Sending commands from the server to the client?

Is there a way to send a command from the server to the client?

I've set up an entity in Hammer that send a command to the console to change a convar defined in the client. (In short, from a trigger display a custom panel on the screen)

My variable is as this:

cl_showquestionpanel 1

Another variable I would like to set from the server code is that one:

cl_question "what is the question?"

from the console in the game, all of this work. but is it possible to create an entity that would trigger this?

I've tried this "engine->ServerCommand("cl_showquestionpanel 1");

no compile error but it doesnt seem to work. Give me an unknown convar.
Reply With Quote
Old 11-04-2009, 03:19 PM   #2
Join Date: Jun 2009
Reputation: 34
Posts: 101
Well, what did you expected from "ServerCommand" then?

If you looked in the header where ServerCommand is declared you would have seen some comments about what it does...
You likely want to use "ClientCommand" instead.
Sandern is offline   Reply With Quote
Old 11-04-2009, 03:22 PM   #3
Join Date: Jul 2007
Reputation: 84
Posts: 2,170
ClientCommand is client->server, for server->client, in this case, a user message is probably want you want
Winston is offline   Reply With Quote
Old 11-04-2009, 03:39 PM   #4
Posts: n/a
Thanks I'll check into that.

I used the point_clientcommand entity in Hammer, and was able to make the panel appear and set the value.

So the stuff I want to make are in this entity.

Found it in client.cpp
I'll try this code tommorow:
void CPointClientCommand::InputCommand( inputdata_t& inputdata )
    if ( !inputdata.value.String()[0] )
    edict_t *pClient = NULL;
    if ( gpGlobals->maxClients == 1 )
        pClient = engine->PEntityOfEntIndex( 1 );
        // In multiplayer, send it back to the activator
        CBasePlayer *player = dynamic_cast< CBasePlayer * >( inputdata.pActivator );
        if ( player )
            pClient = player->edict();
        if ( IsInCommentaryMode() && !pClient )
             // Commentary is stuffing a command in. We'll pretend it came from the first player.
             pClient = engine->PEntityOfEntIndex( 1 );
    if ( !pClient || !pClient->GetUnknown() )
    engine->ClientCommand( pClient, UTIL_VarArgs( "%s\n", inputdata.value.String() ) );
I will also to check how I can return output on multiple entity instances... but that is another thing. Perhaps the messaging you talked about.

I want to create a RPG type dialog (Neverwinter) for "talking" and giving anwers. Will be used with NPC interactions.


Cool the code works perfect!
The ClientCommand only need that we specify WHAT client.

edict_t *pClient = NULL; // Define the type for pClient
pClient = engine->PEntityOfEntIndex( 1 ); // Select the first player (single player game)
engine->ClientCommand( pClient, UTIL_VarArgs( "cl_question %s\n", m_nQuestion) ); //(send the command to the first player)
Using that I was able to send the defined string inside my question entity to the panel using the console command. Work like a charm!

Last edited by christianclavet: 11-05-2009 at 01:00 PM.
  Reply With Quote

Go Back   Steam Users' Forums > Steam Tool Discussions > Source Coding

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -7. The time now is 10:14 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Site Content Copyright Valve Corporation 1998-2015, All Rights Reserved.