Server Help

Bot Questions - player name help

Anonymous - Tue Jul 20, 2004 11:02 pm
Post subject: player name help
Ok, I am making a command: !makeguesser [name]. I put the things for input in commands.cpp but now I need to know how to make it so that the name specified will be changed to a certain frequency and ship. Help?
Underlord - Tue Jul 20, 2004 11:43 pm
Post subject:
Code: Show/Hide

if (c->check("makeguesser"))
{
     if(*c->final != NULL)
     {
         _listnode <Player> *parse = playerlist->head;

         Player *p = parse->item;

         while (parse)
         {
            if (strcmp(p->name,c->final)==0)
            {
                sendPrivate(p,"*setfreq 100");  // replace 100 with freq
                sendPrivate(p,"*setship 1");  // replace 1 with ship
                break;
            }

            parse = parse->next;
         }
     }
}

Anonymous - Wed Jul 21, 2004 1:32 am
Post subject:
It says "strcmp" is has an undeclared identifier. How do I declare it?
Mr Ekted - Wed Jul 21, 2004 2:35 am
Post subject:
#include "string.h"
Doggeti - Wed Jul 21, 2004 5:21 am
Post subject:
Isn't it dangerous to declare a second Player *p. The function botInfo::gotCommand allready has a parameter Player *p.
50% Packetloss - Wed Jul 21, 2004 7:39 am
Post subject:
depends on your compiler, it will spit out an error if it has a problem. Else it is fine. You could also do parse->item->name, no need for a pointer
Solo Ace - Wed Jul 21, 2004 7:43 am
Post subject:
It looks better to do "p = parse->item", though; How do you code, 50%?
Without code?
Mr Ekted - Wed Jul 21, 2004 10:37 am
Post subject:
While I think it's bad style, declaring a variable of the same name inside any braces creates a new "version" that is locally scoped. As soon as you leave the braces, the higher level one "exists" again. This is a C standard.
Underlord - Wed Jul 21, 2004 12:15 pm
Post subject:
Code: Show/Hide

#include <string.h>

if (c->check("makeguesser"))
{
     if(*c->final != NULL)
     {
         _listnode <Player> *parse = playerlist->head;

         while (parse)
         {
            if (strcasecmp(parse->item->name,c->final)==0)
            {
                sendPrivate(parse->item,"*setfreq 100");  // replace 100 with freq
                sendPrivate(parse->item,"*setship 1");  // replace 1 with ship
                break;
            }

            parse = parse->next;
         }
     }
}


Jag, if you just google "c++ strcmp", you can instantly find what library you need
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group