Rune Central

The Official Rune Quake Message Board
It is currently Thu Nov 29, 2012 11:03 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [code] Dead player smashed in door - drops out of level
PostPosted: Thu Jul 21, 2005 1:16 am 
Offline
User avatar

Joined: Mon Oct 13, 2003 10:01 pm
Posts: 99
Location: Iowa
Here's a cool little function for preventing players' bodies/heads getting smashed in doors. I tested many doors and it works perfectly everytime, even with platforms.

Just after the if condition: if (self.flags & FL_ONGROUND) in PlayerDeathThink, put:

Code:
   if (pointcontents (self.origin) == CONTENT_SOLID)
   {
      set_safeorigin (self.origin);
      droptofloor (0, 0);
   }


Then, the function:

Code:
// I use setorigin () to continually update
// your origin instead of using "from" the
// whole way through, because I had to use
// droptofloor () (pointcontents doesn't
// always register correctly, Grr Quake C).
void (vector from)
set_safeorigin =
{
   local float p, safe, giveup, type, n;
   local vector oldfrom;
   local entity spot;
   
   p = pointcontents (from);
   
   // Origin is already safe
   if (p != CONTENT_SOLID)
      return;
   
   oldfrom = from + '0 0 20';
   
   while (!giveup && !safe)
   {
      from = oldfrom;
      
      while (n < 50 && !droptofloor (0, 0))
      {
         n = n + 1;
         
              if (type == 0) from_x = from_x + 1;
         else if (type == 1) from_y = from_y + 1;
         else if (type == 2) from_x = from_x - 1;
         else if (type == 3) from_y = from_y - 1;
         
         from_z = from_z + 0.5;
         
         setorigin (self, from);
         p = pointcontents (self.origin);
      }
      
      // This takes care of most (even all?) the
      // problems with 2 shutting doors, instead
      // of the 1 shutting door.  What happens
      // otherwise is it thinks your not in a solid
      // when you're right in the crack of the
      // two doors when shut.
           if (type == 0) from_x = from_x + 2;
      else if (type == 1) from_y = from_y + 2;
      else if (type == 2) from_x = from_x - 2;
      else if (type == 3) from_y = from_y - 2;
      
      setorigin (self, from);
      
      if (pointcontents (self.origin) != CONTENT_SOLID)
         safe = 1;
      else
      {
         type = type + 1;
         n = 0;
      }
      
      // We've tested all 4 directions
      if (type >= 4)
         giveup = 1;
   }
   
   if (self.health < -40)
      setsize (self, '-16 -16 0', '16 16 56');
   else
      setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
   
   // As a last resort...
   if (!safe || giveup)
   {
      spot = SelectSpawnPoint ();
      setorigin (self, spot.origin + '0 0 1');
   }
};


This code could probably be modified to make it even better. It seemed to work nicely though.

EDIT: Lol, I noticed too many things wrong with this function. I had just made it and showed it without looking over it, fixed now. The players' heads may not be moved to the best height, but you could always fix that later :P.

Bam

_________________
BAM!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 6:12 pm 
Offline
Site Admin
User avatar

Joined: Fri Mar 07, 2003 6:41 pm
Posts: 970
Location: New Jersey, USA
Thanks for the code!

_________________
Slot Zero
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group