Server Help

ASSS Questions - Vehicle module by Bak- Questions

Anonymous - Sat Oct 15, 2011 6:19 am
Post subject: Vehicle module by Bak- Questions
This is the perfect module for the project I am using, but not so perfect in the fact it doesn't work properly.

Wondering if anyone has used it, and had it working.

Issues:

1) Fixed the ship change from being coded on 1.4.4 to compile on 1.5.

2) Errors with the ?in function when you are not near a vehicle in crashes
- Its a problem in the attach funtion
- Commented out the attach function and it works

3) When you enter a vehicle, then go back to where it was when you go in, you can get into it again and then there are 2 vehicles. You can do this once, the second time you try it doesn't work.
Anonymous - Wed Oct 26, 2011 8:35 pm
Post subject:
Here is where the code fails if anyone can see anything obvious, I don't do much work with C.

Code: Show/Hide
local BOOL tryAttach(Player *p, tdvector *tdv)
{
   int x;
   BOOL rv = FALSE;
   printf("[v] looking up players in proximity to %s. %d found\n",p->name,tdv->count);
   for (x = 0; x < tdv->count;++x)
   {      
      Player* mounted = findPlayerWithName(tdv->data[x].name);

      if (mounted)
      {
         printf("[v] checking %s\n",mounted->name);
         int deltaX = p->position.x - mounted->position.x;
         int deltaY = p->position.y - mounted->position.y;
         int radius = getRadius(p->arena->cfg, tdv->data[x].ship) + 16; // plus one tile lee-way

         if (deltaX * deltaX + deltaY * deltaY < radius * radius)
         { // this is our turret!!!

            if (tdv->data[x].state == STATE_OCCUPIED)
            {
               if (strchr(tdv->data[x].disallowAttachShips,'1' + p->p_ship) != 0)
               {
                  chat->SendMessage(p,"%ss are not allowed to attach to that vehicle.", shipNames[p->p_ship]);
               }
               else if (getNumAttached(mounted) >= tdv->data[x].maxTurrets)
               {
                  chat->SendMessage(p,"There are too many turrets attached to %s.",mounted->name);
               }
               else
               {
                  if (p->p_freq != mounted->p_freq && tdv->data[x].disallowEnemyAttach)
                     chat->SendMessage(p,"Enemies are not allowed to attach to that vehicle.", shipNames[p->p_ship]);
                  else
                  {
                     forceAttach(p, mounted);
                     
                     rv = TRUE;
                     break;      
                  }
               }
            }
         }
      }
   }

   return rv;
}


and here is forceAttach where it may or may not also be a problem.

Code: Show/Hide
local void forceAttach(Player *p, Player* mounted)
{
   int pid2 = mounted->pid;

   /* only send it if state has changed */
   if (p->p_attached != pid2)
   {
      struct SimplePacket pkt = { S2C_TURRET, p->pid, pid2 };
      net->SendToArena(p->arena, NULL, (byte*)&pkt, 5, NET_RELIABLE);
      p->p_attached = pid2;

      DO_CBS(CB_ATTACH, p->arena, AttachFunc, (p, mounted));
   }
}

local Player* findPlayerWithName(const char* name)
{
   Player* rv, *p;
   Link* link;
   pd->Lock();

   FOR_EACH_PLAYER(p)
   {
      if (strcmp(p->name, name) == 0)
      {
         rv = p;
         break;
      }
   }

   pd->Unlock();

   return rv;
}

All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group