ServerCmd(): Difference between revisions
Jump to navigation
Jump to search
Tip:You can also trigger a
Warning:Since
TomEdwards (talk | contribs) (can trigger a console command) |
TomEdwards (talk | contribs) mNo edit summary |
||
| Line 1: | Line 1: | ||
'''<code>ServerCmd()</code>''' is a quick and easy method for passing user input to the server available through <code>[[cbase.h]]</code>. It uploads an [[Wikipedia:ASCII|ASCII]] string, including with it information about which connected client sent it. The received strings are processed in <code>ClientCommand()</code> as a <code>[[CCommand]]</code> (i.e. a string array where 0 is the command itself and 1+ are parameters). | '''<code>ServerCmd()</code>''' is a quick and easy method for passing user input to the server available through <code>[[cbase.h]]</code>. It uploads an [[Wikipedia:ASCII|ASCII]] string, including with it information about which connected client sent it. The received strings are processed in <code>ClientCommand()</code> as a <code>[[CCommand]]</code> (i.e. a string array where 0 is the command itself and 1+ are parameters). | ||
{{tip|You can also trigger a <code>[[ | {{tip|You can also trigger a <code>[[Developer_Console_Control#Using_the_ConCommand_class|ConCommand]]</code> if the client's arguemnt matches its name.}} | ||
{{warning|Since <code>ServerCmd()</code> passes a full string value, it is NOT suitable for commands that will be sent frequently. You might get away with it in single-player, '''but a multi-player mod must use the [[Usercmd]]'''.}} | {{warning|Since <code>ServerCmd()</code> passes a full string value, it is NOT suitable for commands that will be sent frequently. You might get away with it in single-player, '''but a multi-player mod must use the [[Usercmd]]'''.}} | ||
Revision as of 10:24, 25 August 2008
ServerCmd() is a quick and easy method for passing user input to the server available through cbase.h. It uploads an ASCII string, including with it information about which connected client sent it. The received strings are processed in ClientCommand() as a CCommand (i.e. a string array where 0 is the command itself and 1+ are parameters).
ConCommand if the client's arguemnt matches its name.ServerCmd() passes a full string value, it is NOT suitable for commands that will be sent frequently. You might get away with it in single-player, but a multi-player mod must use the Usercmd.Example
client: engine->ServerCmd( VarArgs("MyCommand %i", m_iMyNumber) ); // No variables? Pass the command as a simple string. server: bool CBasePlayer::ClientCommand( const CCommand &args ) { if ( !V_stricmp( args[0], "MyCommand" ) ) { Msg( "MyCommand received! Value: %i\n", atoi(args[1]) ); return true; } }