.:: Bots United ::.  
filebase forums irc server wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps waypoints yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Bot Coding
General Bot Coding See what a pain it is to get those little mechs shooting around

Reply
 
Thread Tools
pfnAddServerCommand
Old
  (#1)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,083
Join Date: Nov 2003
Location: Netherlands
Default pfnAddServerCommand - 24-12-2003

Okay, so i have been diggin into this piece of junk I have this code, and it does not work in CS 1.5 listen server or dedicated server. I issue the command:

rbcm rb_addbot

which should add a bot

ps. do not mind the CVAR_REGISTER function....
Code:
// SERVER Command: RealBot
void rbcm ( void )
{
    const char *pcmd = Cmd_Argv(0);
    const char *arg1 = Cmd_Argv(1);
    const char *arg2 = Cmd_Argv(2);
    const char *arg3 = Cmd_Argv(3);
    const char *arg4 = Cmd_Argv(4);

    edict_t *pEntity = listenserver_edict; //
      
    // Handle command here
    if (FStrEq(pcmd, "rb_addbot"))
    {
        Game.CreateBot( pEntity, arg1, arg2, arg3, arg4 );
        bot_check_time = gpGlobals->time + 5.0;
        return;
    }

    return;
}


void GameDLLInit( void )
{

   CVAR_REGISTER (&sv_bot);

   for (int i=0; i<32; i++)
      clients[i] = NULL;   

   // initialize the bots array of structures...
   memset(bots, 0, sizeof(bots));

   Game.LoadNames();
   Game.LoadChat();
   Game.LoadBuyTable();

   // NodeMachine
   NodeMachine.init(); // INIT on load up
   NodeMachine.init_players();

   // Register server command
   (*g_engfuncs.pfnAddServerCommand)( "rbcm", rbcm ); 

   (*other_gFunctionTable.pfnGameInit)();
}
  
Reply With Quote
Re: pfnAddServerCommand
Old
  (#2)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 4643'60N 043'0W 0.187A
Default Re: pfnAddServerCommand - 24-12-2003

Do NOT use your own (hooked) versions of pfnCmd_Argv and pfnCmd_Argc, instead use the CMD_ARGV and CMD_ARGC macros to the direct engine functions... also notice that if your sv_bot CVAR is called "rbcm", registering a rbcm server command may not work...

Other than that what you have here should work



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: pfnAddServerCommand
Old
  (#3)
botmeister
Ex-Council Member
 
botmeister's Avatar
 
Status: Offline
Posts: 1,090
Join Date: Nov 2003
Location: Canada
Default Re: pfnAddServerCommand - 28-12-2003

I built a general purpose server/client command registration and dispatch system for the mean bot/admin mod, there's a few hundred lines of code which is too much to post in here, but here's some bits which show how I get agruments for custom server and client commands. Each command that is executed, is passed an array of strings "vtxArgList" (in my case using the standard C++ string class, not the C style strings). The nice part about this system is ALL my custom commands use the exact same argument header and dispatch function. In otherwords, I only register one standard dispatch function associated with each command name. When a server command is executed, it calls the dispatch function, the dispatch function then looks up the command in an array of registered commands (which include security settings and other nice things). When a match is found, it gets the arguments and passes it to the custom command function as a standard array of strings. From there, the custom command function simply does whatever it is supposed to do using as its arguments the array of strings. It's VERY simple to use, but was a bit complicated to figure out at first. I've been using it for so long now I've almost forgottem how it works!

Anyway here's the code that gets the arguments, hope you can read the non standard naming convention I've been using

Code:
 int finGetCmdLineArgCount( void )
 { // returns number of command line arguments including the command itself;
  return CMD_ARGC();
 } 
 
 string ftxGetCmdLineArgValue( int pinIdx )
 {
  return CMD_ARGV( pinIdx );
 } 
 
 string ftxGetCmdLineString( void )
 { // returns the command line argument list;
   // does *not* include the command portion;
  return CMD_ARGS( );
 } 
 
 void tclCommand::fvoGetArgs( void )
 {
  vinNumArgs = finGetCmdLineArgCount( );
  if ( vinNumArgs > cinMaxArgs )
  // ensure our buffer does not overflow
   vinNumArgs = cinMaxArgs;
  else
  if ( vinNumArgs < cinMinArgs )
  // ensure our buffer does not overflow
   vinNumArgs = cinMinArgs;
  int vinIdx;
  for ( vinIdx = 0; vinIdx < vinNumArgs; vinIdx++ )
  {
   vtxArgList[ vinIdx ] = ftxGetCmdLineArgValue( vinIdx );
	 fvoToLower( vtxArgList[ vinIdx ] );
  }
  for (; vinIdx <= cinMaxArg_Idx; vinIdx++ )
  {
   vtxArgList[ vinIdx ] = "";
  }
  if ( vinNumArgs > 1 )
  {
   vtxArgString = ftxGetCmdLineString( );
  }
  else
  {
   vtxArgString.erase( );
  }
  
 } // tclCommand::fvoGetArgs


Maker of the (mEAn) Bot.Admin Manager

"In theory, there is no difference between theory and practice. But, in practice, there is." - Jan L.A. van de Snepscheut
  
Reply With Quote
Re: pfnAddServerCommand
Old
  (#4)
Fierce Recon
Guest
 
Status:
Posts: n/a
Default Re: pfnAddServerCommand - 11-01-2004

Code:
const char *pcmd = Cmd_Argv(1); 
const char *arg1 = Cmd_Argv(2); 
const char *arg2 = Cmd_Argv(3); 
const char *arg3 = Cmd_Argv(4); 
const char *arg4 = Cmd_Argv(5);

Hope this helps

P.S. 0th argument is the command name, like rbcm

In your case it'll be: (lets pretend abcde is his name, and 1 is his team)
rbcm rb_addbot abcde 1
Code:
*pcmd = "rb_addbot";
*arg1 = "abcde";
*arg2 = "1";
*arg3 = UNDEFINED; //(DONT EVEN TRY THIS)
*arg4 = UNDEFINED; //(DONT EVEN TRY THIS)
:RTFM:

Last edited by Fierce Recon; 11-01-2004 at 07:07..
  
Reply With Quote
Re: pfnAddServerCommand
Old
  (#5)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 4643'60N 043'0W 0.187A
Default Re: pfnAddServerCommand - 12-01-2004

nonono, if you're using your own registered server command, DON'T use your own Cmd_Argv(), Cmd_Argc() and Cmd_Args(). Use the MACROS which call the direct engine functions, CMD_ARGV(), CMD_ARGC() and CMD_ARGS(). If you don't, your code will work, but NOT if a bot is issuing a Client Command at the same time. You will have unpredictable results if this happens, and it will.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: pfnAddServerCommand
Old
  (#6)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: pfnAddServerCommand - 13-01-2004

Fierce recon is correct about the pcmd you want being the first argument and not the 0th.

If using your own CMD_ARG.. functions they will work ok as long as you dont use metamod since they call the engine function anyway.

If using metamod though you need to call the engine cmd_args functions as your versions of cmd_arg under metamod will probably just do nothing as they RETURN_META.
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com