Forum

Game freezes when I return my team's flag

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Game freezes when I return my team's flag

Postby Orion » Thu Apr 08, 2010 1:28 pm

Hi, I'm working on a TF-style mod, and I done the flag's code from scratch. But there's a little problem -- when someone from the enemy team drops my team's flag, when I or another teammate touches it to return it to base, the game freezes. I'll post my flag_touch() function here, because I have no idea why the hell that happens.

Code: Select all
void() flag_touch =
{
   local entity plr, old;
   local string ss;
   
   if (other.classname != "player" && other.classname != "bot")
      return;
   if (other.health <= 0)
      return;
   if (self.touch_time > time)
      return;
   
   if (other.team_no == self.team_no)
   {
      if (!self.inbase)
      {
         self.inbase = TRUE;
         bprint (other.netname);
         if (self.team_no == 1)
            bprint (" returned the blue flag!\n");
         if (self.team_no == 2)
            bprint (" returned the red flag!\n");
         other.frags = other.frags + 1;
         UpdateFrags (other);
         sound (other, CHAN_AUTO, "doors/runetry.wav", 1, ATTN_NONE);
         self.velocity = '0 0 0';
         self.think = SUB_Null;
         setorigin (self, self.real_origin);
         self.angles_y = self.old_yaw;
         self.angles_z = 0;
         droptofloor(0, 0);
         sound (self, CHAN_VOICE, "items/itembk2.wav", 1, ATTN_NORM);
      }
      else if (other.has_flag)
      {
         if (self.team_no == 1)
            b_score = b_score + 1;
         if (self.team_no == 2)
            r_score = r_score + 1;
         
         other.has_flag = FALSE;
         other.status_time = time + 3;
         centerprint (other, "You \bCAPTURED\b the \bENEMY\b flag!");
         bprint (other.netname);
         if (self.team_no == 1)
            bprint (" \bcaptured red's flag.\b\nBlue ");
         if (self.team_no == 2)
            bprint (" \bcaptured blue's flag.\b\nBlue ");
         ss = ftos(b_score);
         bprint (ss);
         bprint (" x ");
         ss = ftos(r_score);
         bprint (ss);
         bprint (" Red\n");
         
         other.frags = other.frags + 15;
         UpdateFrags (other);
         
         plr = find(world, classname, "player");
         while (plr)
         {
            plr.status_time = time + 3;
            if (plr.team_no != self.team_no)
               centerprint (plr, "All your base are belong to us!");
            if (plr.team_no == self.team_no && plr != other)
               centerprint (plr, "All their base are belong to us!");
            if (plr.team_no == self.team_no && plr != other)
               plr.frags = plr.frags + 10;
            stuffcmd (plr, "bf\n");
            plr = find(plr, classname, "player");
         }
         
         plr = find(world, classname, "bot");
         while (plr)
         {
            if (plr != other)
            {
               if (plr.team_no == self.team_no)
               {
                  plr.frags = plr.frags + 10;
                  UpdateFrags (plr);
                  plr.b_topic = 6;
                  plr.talk_time = time + 2 + 2*random();
               }
               else
               {
                  plr.b_topic = 5;
                  plr.talk_time = time + 2 + 2*random();
               }
            }
            plr = find(plr, classname, "bot");
         }
         
         sound (other, CHAN_ITEM, "doors/meduse.wav", 1, ATTN_NORM);
         other.flag.inbase = TRUE;
         other.flag.nextthink = time + 1;
         other.flag.think = apply_touch;
         other.flag.movetype = MOVETYPE_TOSS;
         setorigin (other.flag, other.flag.real_origin);
         other.flag.angles_y = other.flag.old_yaw;
         other.flag.angles_z = 0;
         
         old = self;
         self = other.flag;
         droptofloor(0, 0);
         self = old;
         
         sound (other.flag, CHAN_VOICE, "items/itembk2.wav", 1, ATTN_NORM);
      }
   }
   
   if (other.team_no != self.team_no)
   {
      other.status_time = time + 3;
      centerprint (other, "You have the \bENEMY\b flag!");
      
      plr = find(world, classname, "player");
      while (plr)
      {
         plr.status_time = time + 3;
         if (plr.team_no == self.team_no)
            centerprint (plr, "Somebody get up us the flag!");
         if (plr.team_no != self.team_no && plr != other)
            centerprint (plr, "Somebody get up them the flag!");
         stuffcmd (plr, "bf\n");
         plr = find(plr, classname, "player");
      }
      
      bprint (other.netname);
      if (self.team_no == 1)
         bprint (" \bgot blue's flag.\n");
      if (self.team_no == 2)
         bprint (" \bgot red's flag.\n");
      sound (other, CHAN_ITEM, "items/flagget.wav", 1, ATTN_NORM);
      other.has_flag = TRUE;
      self.carrier = other;
      other.flag = self;
      self.inbase = FALSE;
      self.touch = SUB_Null;
      self.movetype = MOVETYPE_NONE;
      self.origin = other.origin;
      self.angles_y = other.angles_y;
      self.angles_z = -30;
      self.nextthink = time;
      self.think = flag_follow;
   }
};


Is there something wrong with the code? Because I tried to change some lines - no luck. :(
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby c0burn » Thu Apr 08, 2010 2:58 pm

Do you get an error in the console? Or does it actually lock up?
c0burn
 
Posts: 208
Joined: Fri Nov 05, 2004 12:48 pm
Location: Liverpool, England

Postby Orion » Thu Apr 08, 2010 3:12 pm

It locks up, I need to close the game by ctrl+alt+del.
Also, it doesn't occur in DarkPlaces or when I connect to a DP dedicated server with a regular client. Neither does happen in FTE.


EDIT: Aww crap! *facepalm*
I just made the flag return 1/10 second after being touched, that fixed the problem! :lol:
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby Supa » Thu Apr 08, 2010 6:19 pm

SV_TouchLinks is a mean spirited cur.

As you've found out, don't remove or move a touched entity during a frame it was touched in, do it in the next frame with .nextthink = time and you should be fine. :)
User avatar
Supa
 
Posts: 164
Joined: Tue Oct 26, 2004 8:10 am


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest