Inside3D!
     

Game freezes when I return my team's flag

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Orion



Joined: 12 Jan 2007
Posts: 413
Location: Brazil

PostPosted: Thu Apr 08, 2010 1:28 pm    Post subject: Game freezes when I return my team's flag Reply with quote

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:

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. Sad
_________________
There's no signature here. Stop looking for one.
Back to top
View user's profile Send private message
c0burn



Joined: 05 Nov 2004
Posts: 158
Location: Liverpool, England

PostPosted: Thu Apr 08, 2010 2:58 pm    Post subject: Reply with quote

Do you get an error in the console? Or does it actually lock up?
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Orion



Joined: 12 Jan 2007
Posts: 413
Location: Brazil

PostPosted: Thu Apr 08, 2010 3:12 pm    Post subject: Reply with quote

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! Laughing
_________________
There's no signature here. Stop looking for one.
Back to top
View user's profile Send private message
Supa



Joined: 26 Oct 2004
Posts: 122

PostPosted: Thu Apr 08, 2010 6:19 pm    Post subject: Reply with quote

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. :)
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group