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

Reply
 
Thread Tools Display Modes
Old 11-04-2009, 01:18 PM   #1
christianclavet
 
Guest
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, 02:19 PM   #2
Sandern
 
 
 
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, 02:22 PM   #3
Winston
 
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, 02:39 PM   #4
christianclavet
 
Guest
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:
Code:
 
void CPointClientCommand::InputCommand( inputdata_t& inputdata )
{
    if ( !inputdata.value.String()[0] )
    return;
    edict_t *pClient = NULL;
    if ( gpGlobals->maxClients == 1 )
    {
        pClient = engine->PEntityOfEntIndex( 1 );
    }
    else
   {
        // 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() )
    return;
    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.

EDIT:

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

Code:
 
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 12:00 PM.
  Reply With Quote
Reply

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 11:00 PM.


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