Server Help

Bot Questions - Double check still no effect.

Anonymous - Sat May 14, 2005 3:13 pm
Post subject: Double check still no effect.
Hey there,

I made a bot, and if a player comes in a "box" it will be warped to a turretpoint. I made a feature that if there is already a person at the turretpoint, the next person entering the warp box will be warped to the alternative turretpoint. Though the bot doesn't agree with me and keeps warping him to the same turretpoint. Who wants to help me?

-Arctica

PS: the code:

Quote:
case EVENT_Tick:
{
for (int i = 0; i < 4; ++i)
--countdown[i];
Player *p = (Player*)event.p[0];
turrpoint1=0;
_listnode <Player> *parse2 = playerlist->head;

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

if(level == 0)
{
if(p->tile.x >= 89 && p->tile.x <= 91 && p->tile.y >= 18 && p->tile.y <= 20)
{
turpoint1++;
}
}
parse2 = parse->next;
}


Then later:

case EVENT_PlayerMove:
{
Player *p = (Player*)event.p[0];
if(p->tile.x >= 502 && p->tile.x <= 503 && p->tile.y >= 512 && p->tile.y <= 513)
{
if(level == 0 && turpoint1 == 0)
{
sendPrivate(p, "*warpto 90 19");
sendPrivate(p, "You are warped to turretpoint 1.");
}
}
if(p->tile.x >= 502 && p->tile.x <= 503 && p->tile.y >= 512 && p->tile.y <= 513)
{
if(level == 0 && turpoint1 != 0)
{
sendPrivate(p, "*warpto 90 24");
sendPrivate(p, "Turrentpoint occupied, alternative warping..");
}

Anonymous - Sat May 14, 2005 3:16 pm
Post subject:
lol ops, used quote instead of code ;/
Solo Ace - Sat May 14, 2005 3:50 pm
Post subject:
I find your code pretty disturbing, but whatever, I'm not in the mood to fix that for you.

Maybe a quote from a post I made in some thread can help you.

Solo Ace wrote:
I think you should learn how to debug your plugins for MERVbot.
Not sure if you have MS VC++, but this is how you debug your MERV plugins:

  1. Open up the MERVbot's core project and rebuild the MERVbot in Debug mode;
  2. In the MERV's settings make sure the plugin you want to debug gets loaded (to do this you'll have to make sure the plugin you wish to debug is in the project directory of the loaded MERV, of course);
  3. In Windows, drag & drop the code file (spawn.cpp) you wish to debug to the MERVBot project into the IDE;
  4. Place breakpoints in the code you wish to debug, the debugger will pause execution of the program there when it reaches the code;
  5. Run the MERV from the project, attempt to get the code where you put your breakpoint(s) executed (in your case, generate the event EVENT_PlayerMove, by moving your ship?).

After doing this you can see values of variables (by adding a watch or by just hovering over it with your mouse), and you can step through the code using F10 (step over) and F11 (step into).
By doing this you can see which, how and when the code is being executed.

This information may not be useful to you, but maybe someone else can use it.


Quoted from this thread.
Cyan~Fire - Sat May 14, 2005 3:52 pm
Post subject:
Code: Show/Hide
case EVENT_Tick:
      {
         for (int i = 0; i < 4; ++i)
            --countdown[i];
         Player *p = (Player*)event.p[0];
                                                turrpoint1=0;
                                               _listnode <Player> *parse2 = playerlist->head;

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

            if(level == 0)
            {
               if(p->tile.x >= 89 && p->tile.x <= 91 && p->tile.y >= 18 && p->tile.y <= 20)
               {
                  turpoint1++;
               }
            }
                                                                parse2 = parse->next;
         }


Then later:

case EVENT_PlayerMove:
      {
         Player *p = (Player*)event.p[0];
         if(p->tile.x >= 502 && p->tile.x <= 503 && p->tile.y >= 512 && p->tile.y <= 513)
         {
            if(level == 0 && turpoint1 == 0)
            {
               sendPrivate(p, "*warpto 90 19");
               sendPrivate(p, "You are warped to turretpoint 1.");
            }
         }
         if(p->tile.x >= 502 && p->tile.x <= 503 && p->tile.y >= 512 && p->tile.y <= 513)
         {
            if(level == 0 && turpoint1 != 0)
            {
               sendPrivate(p, "*warpto 90 24");
               sendPrivate(p, "Turrentpoint occupied, alternative warping..");
            }

That is so much easier to read, you shoulda re-posted.

First of all, the two if statements at the bottom (if(p->tile.x >= 502 && p->tile.x <= 503 && p->tile.y >= 512 && p->tile.y <= 513)) should be combined, as they both have the same condition.

Second, can people get to the turretpoint other than by warping? If not, you should just have a boolean that you set when you warp them, and then check that boolean instead of cycling through all the players. Even if they can get there otherwise, don't do it every tick. That's far too slow and also there will be some players that haven't moved so it will be pointless to check them. Check to see if anyone's at the turretpoint on EVENT_PlayerMove.

And this is just my preference, but I think it's easier for the coder and for people reading the code just to make a sort of macro, something like:
Code: Show/Hide
#define LIMIT(value, left, right) \
   (value >= left && value <= left)


It will make the code much easier to read.
The Arctica - Sat May 14, 2005 4:10 pm
Post subject:
sorry bout the code, and that guest was me, anyways, it can leave also and then the bool will be still at true/false so it wouldnt change.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group