|
|
#1 |
|
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. |
|
|
|
#2 |
![]() Join Date: Jun 2009
Reputation: 34
Posts: 85
|
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. |
|
|
|
|
|
#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
|
|
|
|
|
|
#4 |
|
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 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)
Last edited by christianclavet: 11-05-2009 at 12:00 PM. |
|
![]() |
|
||||||
| Thread Tools | |
| Display Modes | |
|
|