home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / exbpk001 / backpack.qc next >
Encoding:
Text File  |  1996-07-26  |  2.7 KB  |  126 lines

  1.  
  2.  
  3. /*
  4. ===============================================================================
  5.  
  6. PLAYER BACKPACKS
  7.  
  8. ===============================================================================
  9. */
  10.  
  11. void() BackpackTouch =
  12. {
  13.     local string    s;
  14.     local    float    best;
  15.     local        entity    stemp;
  16.     
  17.     if (other.classname != "player")
  18.         return;
  19.     if (other.health <= 0)
  20.         return;
  21.         
  22. // if the player was using his best weapon, change up to the new one if better        
  23.     stemp = self;
  24.     self = other;
  25.     best = W_BestWeapon();
  26.     self = stemp;
  27.  
  28. // change weapons
  29.     other.ammo_shells = other.ammo_shells + self.ammo_shells;
  30.     other.ammo_nails = other.ammo_nails + self.ammo_nails;
  31.     other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
  32.     other.ammo_cells = other.ammo_cells + self.ammo_cells;
  33.  
  34.     other.items = other.items | self.items;
  35.  
  36.     bound_other_ammo ();
  37.  
  38.     sprint (other, "You get ");
  39.  
  40.     if (self.ammo_shells)
  41.     {
  42.         s = ftos(self.ammo_shells);
  43.         sprint (other, s);
  44.         sprint (other, " shells  ");
  45.     }
  46.     if (self.ammo_nails)
  47.     {
  48.         s = ftos(self.ammo_nails);
  49.         sprint (other, s);
  50.         sprint (other, " nails ");
  51.     }
  52.     if (self.ammo_rockets)
  53.     {
  54.         s = ftos(self.ammo_rockets);
  55.         sprint (other, s);
  56.         sprint (other, " rockets  ");
  57.     }
  58.     if (self.ammo_cells)
  59.     {
  60.         s = ftos(self.ammo_cells);
  61.         sprint (other, s);
  62.         sprint (other, " cells  ");
  63.     }
  64.     
  65.     sprint (other, "\n");
  66. // backpack touch sound
  67.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  68.     stuffcmd (other, "bf\n");
  69.  
  70. // change to a better weapon if appropriate
  71.     if ( other.weapon == best )
  72.     {
  73.         stemp = self;
  74.         self = other;
  75.         self.weapon = W_BestWeapon();
  76.         self = stemp;
  77.     }
  78.  
  79.     
  80.     remove(self);
  81.     
  82.     self = other;
  83.     W_SetCurrentAmmo ();
  84. };
  85.  
  86. /*
  87. ===============
  88. DropBackpack
  89. ===============
  90. */
  91. void() DropBackpack =
  92. {
  93.     local entity    item;
  94.  
  95.     if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells))
  96.         return;    // nothing in it
  97.  
  98.     item = spawn();
  99.     item.origin = self.origin - '0 0 24';
  100.     
  101.     item.items = self.weapon;
  102.  
  103.     item.ammo_shells = self.ammo_shells;
  104.     item.ammo_nails = self.ammo_nails;
  105.     item.ammo_rockets = self.ammo_rockets;
  106.     item.ammo_cells = self.ammo_cells;
  107.  
  108.     item.velocity_z = 300;
  109.     item.velocity_x = -100 + (random() * 200);
  110.     item.velocity_y = -100 + (random() * 200);
  111.     
  112.     item.flags = FL_ITEM;
  113.         item.solid = SOLID_SLIDEBOX;
  114.     item.movetype = MOVETYPE_TOSS;
  115.     setmodel (item, "progs/backpack.mdl");
  116.     setsize (item, '-16 -16 0', '16 16 56');
  117.     item.touch = BackpackTouch;
  118.         item.health = 30;
  119.         item.th_die = barrel_explode;
  120.  
  121.         item.takedamage = DAMAGE_AIM;
  122.  
  123.     item.nextthink = time + 120;    // remove after 2 minutes
  124.     item.think = SUB_Remove;
  125. };
  126.