Server Help

Bot Questions - setfreq

Anonymous - Mon Jul 05, 2004 1:10 pm
Post subject: setfreq
How do I code a !setfreq command? Here is my curret code but it is doesn't work at all.

Code: Show/Hide
else if(c->check("setfreq"))
         {
            if (isNumeric(c->final))
            {
               String setship="*setfreq ";
               setfreq+=getInteger(c->final,10);
               for(_listnode <Player> *pl=playerlist->head;pl;pl=pl->next)
               {
                  if(pl->item->freq!=8)
                  {sendPrivate(pl->item,setfreq);}
               }
               sendPrivate(p,"Freq changes Complete");
            }
            else
            {sendPrivate(p,"You must specify a freq number.");}

         }


Then the error is:

c:\documents and settings\....\desktop\src\bot\command.cpp(125) : error C2065: 'setfreq' : undeclared identifier
CypherJF - Mon Jul 05, 2004 1:44 pm
Post subject:
You never defined setfreq icon_smile.gif

unsigned int setfreq = 0; // change.
setfreq+=getInteger(c->final,10);
Solo Ace - Mon Jul 05, 2004 2:14 pm
Post subject:
Ew. new_Eyecrazy.gif
The coding style in that piece of code is even more ugly than Dustpup's style. icon_razz.gif

And Cypher, what you gave him as solution wouldn't work either, he could've used "String setfreq = "*setfreq ";" instead of what he used on that line. icon_biggrin.gif

Me thinks you should use the following.

Code: Show/Hide
else if (c->check("setfreq"))
{
   if (isNumeric(c->final))
   {       
      String setfreq = "*setfreq ";
      setfreq += getInteger(c->final,10);

      _listnode <Player> *parse = playerlist->head;

      while (parse)
      {
         Player *p = parse->item;

         if (p->freq != 8) // Why are you doing this?!? Btw, when I worked with MERV p->team was used for the frequency number, did it get changed!?
            sendPrivate(p, setfreq);

         parse = parse->next;
      }
      sendPrivate(p,"Frequency changes complete.");
   }
   else
      sendPrivate(p, "You must specify a valid frequency number.");
}

Anonymous - Mon Jul 05, 2004 2:23 pm
Post subject:
Yes I know, it's messy. I copied it from a !setship command and I thought it would do the same thing.
Solo Ace - Mon Jul 05, 2004 2:32 pm
Post subject:
Of course checking if the parameter of the command is a valid freq number (0 <= number && number <= 9999) or something, and making sure the number is not the spectator frequency number could both be useful too.

But that's up to you, heh.
CypherJF - Mon Jul 05, 2004 4:11 pm
Post subject:
Oh true lol.. i didnt really pay much attention.. oops :/
Anonymous - Mon Jul 05, 2004 4:14 pm
Post subject:
One more question, how do I make it so that the users cannot switch frequencies/ships? I know you can do it by putting code in under case EVENT_PlayerTeam but I want to know if I can just lock it or something.
Anonymous - Mon Jul 05, 2004 4:23 pm
Post subject:
Sorry, never mind about that top post. Apperently, I didn't know all the things that *lock did.
50% Packetloss - Mon Jul 05, 2004 9:25 pm
Post subject:
Uint16 Freq= getInteger(c->final,10);//you could use this or do it by hand
if(Freq >= 0 && Freq <=9999)
{
char SetMsg[14];
sprintf(SetMsg,"*setfreq %d",Freq);

//then whatever else you want
}


Thing with Strings is that they allocate/deallocate memory everytime they perform a task and they run a bunch of crap code. I used them so i can get bots done quickly, but something small such as the *setfreq command should be put together with the sprintf function
Cyan~Fire - Tue Jul 06, 2004 10:21 am
Post subject:
Actually, for even more speedy-quickness, you don't have to do a negative check (unsigned).
Mine GO BOOM - Tue Jul 06, 2004 11:40 am
Post subject:
Cyan~Fire wrote:
Actually, for even more speedy-quickness, you don't have to do a negative check (unsigned).

A problem with this is that others that may read your code may not notice that, and may assume that there is a sign problem. So leaving it in may make it a bit slower, but better readable. Hopefully, a compiler may notice that its checked if an always positive value is positive, and may reduce that instruction for you, but it may not. Those things have been getting very smart these days.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group