Server Help

Bot Questions - player matching

Anborn - Sun Jan 12, 2003 12:34 pm
Post subject: player matching
I've added the following as a command for the MERV bot. captains[] is an array of *char. where i'm keeping the name of whoever is registered to be a captain. that is being recognized correctly as when a captains uses !remove <playername> it responds into the correct else section and when a non-captain uses the command it indicates as such by saying you don't have access.

Now, when it parses the playerlist to see if the name listed in the command (say for instance !remove Druid)... it will always come back to the "that player is not found" msg... even if the 2 Debug displays are the exact same for one of the players in the player list. Why wouldn't this when displayed the same way in the debug msgs ... kick into the spec command.

The code for the command is as follows... and a sample inzone output follows that.

Any help would be appreciated.



Code: Show/Hide
         else if (c->check("remove")) {
            // if the player isn't a capt
            if(p->name != captains[0] && p->name != captains[1]) {
               sendPrivate(p,"You are not a captain and don't have access to this command");
            }
            else {
               String s;
               s = c->final;
               int found=0;

               _listnode <Player> *parse = playerlist->head;
               while (parse && found==0) {
                  Player *r = parse->item;
                  sendRemotePrivate("Debug",r->name);
                  sendRemotePrivate("Debug",s);
                  if (r->name == s)   {
                     sendPrivate(r,"*setship 0");
                     sendPrivate(r,"*setfreq SPECFREQ");
                     found=1;
                  }
                  parse = parse->next;
               }

               if(found==0) sendPrivate(p,"That player wasn't found");
            }
         }




Anborn+> !remove B.Mccabe #24+
(Anbo)>Anborn+ <--- player in player list
(Anbo)>B.Mccabe #24+ <--- command parameter
(Anbo)>B.Mccabe #24+ <--- player in player list
(Anbo)>B.Mccabe #24+ <--- command parameter
B.Mccabe #> anbo
(Anbo)>Anbo <--- player in player list
(Anbo)>B.Mccabe #24+ <--- command parameter
Anbo> That player wasn't found
SOS - Sun Jan 12, 2003 1:51 pm
Post subject:
Hmm... I would say

if (r->name == s) {

should be

if (s == r->name) {
Anborn - Mon Jan 13, 2003 12:35 am
Post subject:
SOS - thanks... that did it... forgive me as my last programming class was 4 years ago... but why don't they do the same thing?! time to hit the net to figure out stuff I should have actually learned while I was in school icon_smile.gif hehe.
SOS - Mon Jan 13, 2003 7:41 am
Post subject:
The == operator for the left operand is called. Just the way the language works.
In this case, the other way around would just compare the pointer to the char[] with the pointer to the String, which would always be false.
But since String has a == operator to check a char array, it works sa_tongue.gif

BTW, if you're going for faster strings and more features, CString is a much better class to use than Catid's String.
It's in atlstr.h or afxstr.h(I think) if using MFC.
Anborn - Mon Jan 13, 2003 9:21 am
Post subject:
cool thanks SOS... muchos gracias once again icon_smile.gif
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group