home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / jteam092 / items.qc < prev    next >
Encoding:
Text File  |  1996-08-16  |  28.7 KB  |  1,358 lines

  1. void() W_SetCurrentAmmo;
  2. /* ALL LIGHTS SHOULD BE 0 1 0 IN COLOR ALL OTHER ITEMS SHOULD
  3. BE .8 .3 .4 IN COLOR */
  4.  
  5.  
  6. void() SUB_regen =
  7. {
  8.     self.model = self.mdl;        // restore original model
  9.     self.solid = SOLID_TRIGGER;    // allow it to be touched again
  10.     sound (self, CHAN_VOICE, "items/itembk2.wav", 1, ATTN_NORM);    // play respawn sound
  11.     setorigin (self, self.origin);
  12. };
  13.  
  14.  
  15.  
  16. /*QUAKED noclass (0 0 0) (-8 -8 -8) (8 8 8)
  17. prints a warning message when spawned
  18. */
  19. void() noclass =
  20. {
  21.     dprint ("noclass spawned at");
  22.     dprint (vtos(self.origin));
  23.     dprint ("\n");
  24.     remove (self);
  25. };
  26.  
  27.  
  28.  
  29. /*
  30. ============
  31. PlaceItem
  32.  
  33. plants the object on the floor
  34. ============
  35. */
  36. void() PlaceItem =
  37. {
  38.     local float    oldz;
  39.  
  40.     self.mdl = self.model;        // so it can be restored on respawn
  41.     self.flags = FL_ITEM;        // make extra wide
  42.     self.solid = SOLID_TRIGGER;
  43.     self.movetype = MOVETYPE_TOSS;    
  44.     self.velocity = '0 0 0';
  45.     self.origin_z = self.origin_z + 6;
  46.     oldz = self.origin_z;
  47.     if (!droptofloor())
  48.     {
  49.         dprint ("Bonus item fell out of level at ");
  50.         dprint (vtos(self.origin));
  51.         dprint ("\n");
  52.         remove(self);
  53.         return;
  54.     }
  55. };
  56.  
  57. /*
  58. ============
  59. StartItem
  60.  
  61. Sets the clipping size and plants the object on the floor
  62. ============
  63. */
  64. void() StartItem =
  65. {
  66.     self.nextthink = time + 0.2;    // items start after other solids
  67.     self.think = PlaceItem;
  68. };
  69.  
  70. /*
  71. =========================================================================
  72.  
  73. HEALTH BOX
  74.  
  75. =========================================================================
  76. */
  77. //
  78. // T_Heal: add health to an entity, limiting health to max_health
  79. // "ignore" will ignore max_health limit
  80. //
  81. float (entity e, float healamount, float ignore) T_Heal =
  82. {
  83.     if (e.health <= 0)
  84.         return 0;
  85.     if ((!ignore) && (e.health >= other.max_health))
  86.         return 0;
  87.     healamount = ceil(healamount);
  88.  
  89.     e.health = e.health + healamount;
  90.     if ((!ignore) && (e.health >= other.max_health))
  91.         e.health = other.max_health;
  92.         
  93.     if (e.health > 250)
  94.         e.health = 250;
  95.     return 1;
  96. };
  97.  
  98. /*QUAKED item_health (.3 .3 1) (0 0 0) (32 32 32) rotten megahealth
  99. Health box. Normally gives 25 points.
  100. Rotten box heals 5-10 points,
  101. megahealth will add 100 health, then 
  102. rot you down to your maximum health limit, 
  103. one point per second.
  104. */
  105.  
  106. float    H_ROTTEN = 1;
  107. float    H_MEGA = 2;
  108. .float    healamount, healtype;
  109. void() health_touch;
  110. void() item_megahealth_rot;
  111.  
  112. void() item_health =
  113. {    
  114.     self.touch = health_touch;
  115.  
  116.     if (self.spawnflags & H_ROTTEN)
  117.     {
  118.         precache_model("maps/b_bh10.bsp");
  119.  
  120.         precache_sound("items/r_item1.wav");
  121.         setmodel(self, "maps/b_bh10.bsp");
  122.         self.noise = "items/r_item1.wav";
  123.         self.healamount = 15;
  124.         self.healtype = 0;
  125.     }
  126.     else
  127.     if (self.spawnflags & H_MEGA)
  128.     {
  129.         precache_model("maps/b_bh100.bsp");
  130.         precache_sound("items/r_item2.wav");
  131.         setmodel(self, "maps/b_bh100.bsp");
  132.         self.noise = "items/r_item2.wav";
  133.         self.healamount = 100;
  134.         self.healtype = 2;
  135.     }
  136.     else
  137.     {
  138.         precache_model("maps/b_bh25.bsp");
  139.         precache_sound("items/health1.wav");
  140.         setmodel(self, "maps/b_bh25.bsp");
  141.         self.noise = "items/health1.wav";
  142.         self.healamount = 25;
  143.         self.healtype = 1;
  144.     }
  145.     setsize (self, '0 0 0', '32 32 56');
  146.     StartItem ();
  147. };
  148.  
  149.  
  150. void() health_touch =
  151. {
  152.     local    float amount;
  153.     local    string    s;
  154.     
  155.     if (other.classname != "player")
  156.         return;
  157.     
  158.     if (self.healtype == 2) // Megahealth?  Ignore max_health...
  159.     {
  160.         if (other.health >= 250)
  161.             return;
  162.         if (!T_Heal(other, self.healamount, 1))
  163.             return;
  164.     }
  165.     else
  166.     {
  167.         if (!T_Heal(other, self.healamount, 0))
  168.             return;
  169.     }
  170.     
  171.     sprint(other, "You receive ");
  172.     s = ftos(self.healamount);
  173.     sprint(other, s);
  174.     sprint(other, " health\n");
  175.     
  176. // health touch sound
  177.     sound(other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  178.  
  179.     stuffcmd (other, "bf\n");
  180.     
  181.     self.model = string_null;
  182.     self.solid = SOLID_NOT;
  183.  
  184.     // Megahealth = rot down the player's super health
  185.     if (self.healtype == 2)
  186.     {
  187.         other.items = other.items | IT_SUPERHEALTH;
  188.         self.nextthink = time + 5;
  189.         self.think = item_megahealth_rot;
  190.         self.owner = other;
  191.     }
  192.     else
  193.     {
  194.         if (deathmatch != 2)        // deathmatch 2 is the silly old rules
  195.         {
  196.             if (deathmatch)
  197.                 self.nextthink = time + 20;
  198.             self.think = SUB_regen;
  199.                 }
  200.     }
  201.     
  202.     activator = other;
  203.     SUB_UseTargets();                // fire all targets / killtargets
  204. };    
  205.  
  206. void() item_megahealth_rot =
  207. {
  208.     other = self.owner;
  209.     
  210.     if (other.health > other.max_health)
  211.     {
  212.         other.health = other.health - 1;
  213.         self.nextthink = time + 1;
  214.         return;
  215.     }
  216.  
  217. // it is possible for a player to die and respawn between rots, so don't
  218. // just blindly subtract the flag off
  219.     other.items = other.items - (other.items & IT_SUPERHEALTH);
  220.     
  221.     if (deathmatch == 1)    // deathmatch 2 is silly old rules
  222.     {
  223.         self.nextthink = time + 20;
  224.         self.think = SUB_regen;
  225.     }
  226. };
  227.  
  228. /*
  229. ===============================================================================
  230.  
  231. ARMOR
  232.  
  233. ===============================================================================
  234. */
  235.  
  236. void() armor_touch;
  237.  
  238. void() armor_touch =
  239. {
  240.     local    float    type, value, bit;
  241.     
  242.     if (other.health <= 0)
  243.         return;
  244.     if (other.classname != "player")
  245.         return;
  246.  
  247.     if (self.classname == "item_armor1")
  248.     {
  249.         type = 0.3;
  250.         value = 100;
  251.         bit = IT_ARMOR1;
  252.     }
  253.     if (self.classname == "item_armor2")
  254.     {
  255.         type = 0.6;
  256.         value = 150;
  257.         bit = IT_ARMOR2;
  258.     }
  259.     if (self.classname == "item_armorInv")
  260.     {
  261.         type = 0.8;
  262.         value = 200;
  263.         bit = IT_ARMOR3;
  264.     }
  265.     if (other.armortype*other.armorvalue >= type*value)
  266.         return;
  267.         
  268.     other.armortype = type;
  269.     other.armorvalue = value;
  270.     other.items = other.items - (other.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) + bit;
  271.  
  272.     self.solid = SOLID_NOT;
  273.     self.model = string_null;
  274.     if (deathmatch == 1)
  275.         self.nextthink = time + 20;
  276.     self.think = SUB_regen;
  277.  
  278.     sprint(other, "You got armor\n");
  279. // armor touch sound
  280.     sound(other, CHAN_ITEM, "items/armor1.wav", 1, ATTN_NORM);
  281.     stuffcmd (other, "bf\n");
  282.     
  283.     activator = other;
  284.     SUB_UseTargets();                // fire all targets / killtargets
  285. };
  286.  
  287.  
  288. /*QUAKED item_armor1 (0 .5 .8) (-16 -16 0) (16 16 32)
  289. */
  290.  
  291. void() item_armor1 =
  292. {
  293.     self.touch = armor_touch;
  294.     precache_model ("progs/armor.mdl");
  295.     setmodel (self, "progs/armor.mdl");
  296.     self.skin = 0;
  297.     setsize (self, '-16 -16 0', '16 16 56');
  298.     StartItem ();
  299. };
  300.  
  301. /*QUAKED item_armor2 (0 .5 .8) (-16 -16 0) (16 16 32)
  302. */
  303.  
  304. void() item_armor2 =
  305. {
  306.     self.touch = armor_touch;
  307.     precache_model ("progs/armor.mdl");
  308.     setmodel (self, "progs/armor.mdl");
  309.     self.skin = 1;
  310.     setsize (self, '-16 -16 0', '16 16 56');
  311.     StartItem ();
  312. };
  313.  
  314. /*QUAKED item_armorInv (0 .5 .8) (-16 -16 0) (16 16 32)
  315. */
  316.  
  317. void() item_armorInv =
  318. {
  319.     self.touch = armor_touch;
  320.     precache_model ("progs/armor.mdl");
  321.     setmodel (self, "progs/armor.mdl");
  322.     self.skin = 2;
  323.     setsize (self, '-16 -16 0', '16 16 56');
  324.     StartItem ();
  325. };
  326.  
  327. /*
  328. ===============================================================================
  329.  
  330. WEAPONS
  331.  
  332. ===============================================================================
  333. */
  334.  
  335. void() bound_other_ammo =
  336. {
  337.     if (other.ammo_shells > 100)
  338.         other.ammo_shells = 100;
  339.     if (other.ammo_nails > 200)
  340.         other.ammo_nails = 200;
  341.     if (other.ammo_rockets > 100)
  342.         other.ammo_rockets = 100;        
  343.     if (other.ammo_cells > 100)
  344.         other.ammo_cells = 100;        
  345. };
  346.  
  347.  
  348. float(float w) RankForWeapon =
  349. {
  350.     if (w == IT_LIGHTNING)
  351.         return 1;
  352.     if (w == IT_ROCKET_LAUNCHER)
  353.         return 2;
  354.     if (w == IT_SUPER_NAILGUN)
  355.         return 3;
  356.     if (w == IT_GRENADE_LAUNCHER)
  357.         return 4;
  358.     if (w == IT_SUPER_SHOTGUN)
  359.         return 5;
  360.     if (w == IT_NAILGUN)
  361.         return 6;
  362.     return 7;
  363. };
  364.  
  365. /*
  366. =============
  367. Deathmatch_Weapon
  368.  
  369. Deathmatch weapon change rules for picking up a weapon
  370.  
  371. .float        ammo_shells, ammo_nails, ammo_rockets, ammo_cells;
  372. =============
  373. */
  374. void(float old, float new) Deathmatch_Weapon =
  375. {
  376.     local float or, nr;
  377.  
  378. // change self.weapon if desired
  379.     or = RankForWeapon (self.weapon);
  380.     nr = RankForWeapon (new);
  381.     if ( nr < or )
  382.         self.weapon = new;
  383. };
  384.  
  385. /*
  386. =============
  387. weapon_touch
  388. =============
  389. */
  390. float() W_BestWeapon;
  391.  
  392. void() weapon_touch =
  393. {
  394.     local    float    hadammo, best, new, old;
  395.     local    entity    stemp;
  396.     local    float    leave;
  397.  
  398.     if (!(other.flags & FL_CLIENT))
  399.         return;
  400.  
  401. // if the player was using his best weapon, change up to the new one if better        
  402.     stemp = self;
  403.     self = other;
  404.     best = W_BestWeapon();
  405.     self = stemp;
  406.  
  407.     if (deathmatch == 2 || coop)
  408.         leave = 1;
  409.     else
  410.         leave = 0;
  411.     
  412.     if (self.classname == "weapon_nailgun")
  413.     {
  414.         if (leave && (other.items & IT_NAILGUN) )
  415.             return;
  416.         hadammo = other.ammo_nails;            
  417.         new = IT_NAILGUN;
  418. // *TEAMPLAY*
  419.         if ( !( coop && (teamplay & TEAM_DROP_ITEMS) ) )
  420.             other.ammo_nails = other.ammo_nails + 30;
  421.     }
  422.     else if (self.classname == "weapon_supernailgun")
  423.     {
  424.         if (leave && (other.items & IT_SUPER_NAILGUN) )
  425.             return;
  426.         hadammo = other.ammo_rockets;            
  427.         new = IT_SUPER_NAILGUN;
  428. // *TEAMPLAY*
  429.         if ( !( coop && (teamplay & TEAM_DROP_ITEMS) ) )
  430.             other.ammo_nails = other.ammo_nails + 30;
  431.     }
  432.     else if (self.classname == "weapon_supershotgun")
  433.     {
  434.         if (leave && (other.items & IT_SUPER_SHOTGUN) )
  435.             return;
  436.         hadammo = other.ammo_rockets;            
  437.         new = IT_SUPER_SHOTGUN;
  438. // *TEAMPLAY*
  439.         if ( !( coop && (teamplay & TEAM_DROP_ITEMS) ) )
  440.             other.ammo_shells = other.ammo_shells + 5;
  441.     }
  442.     else if (self.classname == "weapon_rocketlauncher")
  443.     {
  444.         if (leave && (other.items & IT_ROCKET_LAUNCHER) )
  445.             return;
  446.         hadammo = other.ammo_rockets;            
  447.         new = IT_ROCKET_LAUNCHER;
  448. // *TEAMPLAY*
  449.         if ( !( coop && (teamplay & TEAM_DROP_ITEMS) ) )
  450.             other.ammo_rockets = other.ammo_rockets + 5;
  451.     }
  452.     else if (self.classname == "weapon_grenadelauncher")
  453.     {
  454.         if (leave && (other.items & IT_GRENADE_LAUNCHER) )
  455.             return;
  456.         hadammo = other.ammo_rockets;            
  457.         new = IT_GRENADE_LAUNCHER;
  458. // *TEAMPLAY*
  459.         if ( !( coop && (teamplay & TEAM_DROP_ITEMS) ) )
  460.             other.ammo_rockets = other.ammo_rockets + 5;
  461.     }
  462.     else if (self.classname == "weapon_lightning")
  463.     {
  464.         if (leave && (other.items & IT_LIGHTNING) )
  465.             return;
  466.         hadammo = other.ammo_rockets;            
  467.         new = IT_LIGHTNING;
  468. // *TEAMPLAY*
  469.         if ( !( coop && (teamplay & TEAM_DROP_ITEMS) ) )
  470.             other.ammo_cells = other.ammo_cells + 15;
  471.     }
  472.     else
  473.         objerror ("weapon_touch: unknown classname");
  474.  
  475.     sprint (other, "You got the ");
  476.     sprint (other, self.netname);
  477.     sprint (other, "\n");
  478. // weapon touch sound
  479.     sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
  480.     stuffcmd (other, "bf\n");
  481.  
  482.     bound_other_ammo ();
  483.  
  484. // change to the weapon
  485.     old = other.items;
  486.     other.items = other.items | new;
  487.     
  488.     stemp = self;
  489.     self = other;
  490.  
  491.     if (!deathmatch)
  492.         self.weapon = new;
  493.     else
  494.         Deathmatch_Weapon (old, new);
  495.  
  496.     W_SetCurrentAmmo();
  497.  
  498.     self = stemp;
  499.  
  500.     if (leave)
  501.         return;
  502.  
  503. // remove it in single player, or setup for respawning in deathmatch
  504.     self.model = string_null;
  505.     self.solid = SOLID_NOT;
  506.     if (deathmatch == 1)
  507.         self.nextthink = time + 30;
  508.     self.think = SUB_regen;
  509.     
  510.     activator = other;
  511.     SUB_UseTargets();                // fire all targets / killtargets
  512. };
  513.  
  514.  
  515. /*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32)
  516. */
  517.  
  518. void() weapon_supershotgun =
  519. {
  520.     precache_model ("progs/g_shot.mdl");
  521.     setmodel (self, "progs/g_shot.mdl");
  522.     self.weapon = IT_SUPER_SHOTGUN;
  523.     self.netname = "Double-barrelled Shotgun";
  524.     self.touch = weapon_touch;
  525.     setsize (self, '-16 -16 0', '16 16 56');
  526.     StartItem ();
  527. };
  528.  
  529. /*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  530. */
  531.  
  532. void() weapon_nailgun =
  533. {
  534.     precache_model ("progs/g_nail.mdl");
  535.     setmodel (self, "progs/g_nail.mdl");
  536.     self.weapon = IT_NAILGUN;
  537.     self.netname = "nailgun";
  538.     self.touch = weapon_touch;
  539.     setsize (self, '-16 -16 0', '16 16 56');
  540.     StartItem ();
  541. };
  542.  
  543. /*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  544. */
  545.  
  546. void() weapon_supernailgun =
  547. {
  548.     precache_model ("progs/g_nail2.mdl");
  549.     setmodel (self, "progs/g_nail2.mdl");
  550.     self.weapon = IT_SUPER_NAILGUN;
  551.     self.netname = "Super Nailgun";
  552.     self.touch = weapon_touch;
  553.     setsize (self, '-16 -16 0', '16 16 56');
  554.     StartItem ();
  555. };
  556.  
  557. /*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  558. */
  559.  
  560. void() weapon_grenadelauncher =
  561. {
  562.     precache_model ("progs/g_rock.mdl");
  563.     setmodel (self, "progs/g_rock.mdl");
  564.     self.weapon = 3;
  565.     self.netname = "Grenade Launcher";
  566.     self.touch = weapon_touch;
  567.     setsize (self, '-16 -16 0', '16 16 56');
  568.     StartItem ();
  569. };
  570.  
  571. /*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  572. */
  573.  
  574. void() weapon_rocketlauncher =
  575. {
  576.     precache_model ("progs/g_rock2.mdl");
  577.     setmodel (self, "progs/g_rock2.mdl");
  578.     self.weapon = 3;
  579.     self.netname = "Rocket Launcher";
  580.     self.touch = weapon_touch;
  581.     setsize (self, '-16 -16 0', '16 16 56');
  582.     StartItem ();
  583. };
  584.  
  585.  
  586. /*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32)
  587. */
  588.  
  589. void() weapon_lightning =
  590. {
  591.     precache_model ("progs/g_light.mdl");
  592.     setmodel (self, "progs/g_light.mdl");
  593.     self.weapon = 3;
  594.     self.netname = "Thunderbolt";
  595.     self.touch = weapon_touch;
  596.     setsize (self, '-16 -16 0', '16 16 56');
  597.     StartItem ();
  598. };
  599.  
  600.  
  601. /*
  602. ===============================================================================
  603.  
  604. AMMO
  605.  
  606. ===============================================================================
  607. */
  608.  
  609. void() ammo_touch =
  610. {
  611. local entity    stemp;
  612. local float        best;
  613.  
  614.     if (other.classname != "player")
  615.         return;
  616.     if (other.health <= 0)
  617.         return;
  618.  
  619. // if the player was using his best weapon, change up to the new one if better        
  620.     stemp = self;
  621.     self = other;
  622.     best = W_BestWeapon();
  623.     self = stemp;
  624.  
  625.  
  626. // shotgun
  627.     if (self.weapon == 1)
  628.     {
  629.         if (other.ammo_shells >= 100)
  630.             return;
  631.         other.ammo_shells = other.ammo_shells + self.aflag;
  632.     }
  633.  
  634. // spikes
  635.     if (self.weapon == 2)
  636.     {
  637.         if (other.ammo_nails >= 200)
  638.             return;
  639.         other.ammo_nails = other.ammo_nails + self.aflag;
  640.     }
  641.  
  642. //    rockets
  643.     if (self.weapon == 3)
  644.     {
  645.         if (other.ammo_rockets >= 100)
  646.             return;
  647.         other.ammo_rockets = other.ammo_rockets + self.aflag;
  648.     }
  649.  
  650. //    cells
  651.     if (self.weapon == 4)
  652.     {
  653.         if (other.ammo_cells >= 200)
  654.             return;
  655.         other.ammo_cells = other.ammo_cells + self.aflag;
  656.     }
  657.  
  658.     bound_other_ammo ();
  659.     
  660.     sprint (other, "You got the ");
  661.     sprint (other, self.netname);
  662.     sprint (other, "\n");
  663. // ammo touch sound
  664.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  665.     stuffcmd (other, "bf\n");
  666.  
  667. // change to a better weapon if appropriate
  668.  
  669.     if ( other.weapon == best )
  670.     {
  671.         stemp = self;
  672.         self = other;
  673.         self.weapon = W_BestWeapon();
  674.         W_SetCurrentAmmo ();
  675.         self = stemp;
  676.     }
  677.  
  678. // if changed current ammo, update it
  679.     stemp = self;
  680.     self = other;
  681.     W_SetCurrentAmmo();
  682.     self = stemp;
  683.  
  684. // remove it in single player, or setup for respawning in deathmatch
  685.     self.model = string_null;
  686.     self.solid = SOLID_NOT;
  687.     if (deathmatch == 1)
  688.         self.nextthink = time + 30;
  689.     
  690.     self.think = SUB_regen;
  691.  
  692.     activator = other;
  693.     SUB_UseTargets();                // fire all targets / killtargets
  694. };
  695.  
  696.  
  697.  
  698.  
  699. float WEAPON_BIG2 = 1;
  700.  
  701. /*QUAKED item_shells (0 .5 .8) (0 0 0) (32 32 32) big
  702. */
  703.  
  704. void() item_shells =
  705. {
  706.     self.touch = ammo_touch;
  707.  
  708.     if (self.spawnflags & WEAPON_BIG2)
  709.     {
  710.         precache_model ("maps/b_shell1.bsp");
  711.         setmodel (self, "maps/b_shell1.bsp");
  712.         self.aflag = 40;
  713.     }
  714.     else
  715.     {
  716.         precache_model ("maps/b_shell0.bsp");
  717.         setmodel (self, "maps/b_shell0.bsp");
  718.         self.aflag = 20;
  719.     }
  720.     self.weapon = 1;
  721.     self.netname = "shells";
  722.     setsize (self, '0 0 0', '32 32 56');
  723.     StartItem ();
  724. };
  725.  
  726. /*QUAKED item_spikes (0 .5 .8) (0 0 0) (32 32 32) big
  727. */
  728.  
  729. void() item_spikes =
  730. {
  731.     self.touch = ammo_touch;
  732.  
  733.     if (self.spawnflags & WEAPON_BIG2)
  734.     {
  735.         precache_model ("maps/b_nail1.bsp");
  736.         setmodel (self, "maps/b_nail1.bsp");
  737.         self.aflag = 50;
  738.     }
  739.     else
  740.     {
  741.         precache_model ("maps/b_nail0.bsp");
  742.         setmodel (self, "maps/b_nail0.bsp");
  743.         self.aflag = 25;
  744.     }
  745.     self.weapon = 2;
  746.     self.netname = "nails";
  747.     setsize (self, '0 0 0', '32 32 56');
  748.     StartItem ();
  749. };
  750.  
  751. /*QUAKED item_rockets (0 .5 .8) (0 0 0) (32 32 32) big
  752. */
  753.  
  754. void() item_rockets =
  755. {
  756.     self.touch = ammo_touch;
  757.  
  758.     if (self.spawnflags & WEAPON_BIG2)
  759.     {
  760.         precache_model ("maps/b_rock1.bsp");
  761.         setmodel (self, "maps/b_rock1.bsp");
  762.         self.aflag = 10;
  763.     }
  764.     else
  765.     {
  766.         precache_model ("maps/b_rock0.bsp");
  767.         setmodel (self, "maps/b_rock0.bsp");
  768.         self.aflag = 5;
  769.     }
  770.     self.weapon = 3;
  771.     self.netname = "rockets";
  772.     setsize (self, '0 0 0', '32 32 56');
  773.     StartItem ();
  774. };
  775.  
  776.  
  777. /*QUAKED item_cells (0 .5 .8) (0 0 0) (32 32 32) big
  778. */
  779.  
  780. void() item_cells =
  781. {
  782.     self.touch = ammo_touch;
  783.  
  784.     if (self.spawnflags & WEAPON_BIG2)
  785.     {
  786.         precache_model ("maps/b_batt1.bsp");
  787.         setmodel (self, "maps/b_batt1.bsp");
  788.         self.aflag = 12;
  789.     }
  790.     else
  791.     {
  792.         precache_model ("maps/b_batt0.bsp");
  793.         setmodel (self, "maps/b_batt0.bsp");
  794.         self.aflag = 6;
  795.     }
  796.     self.weapon = 4;
  797.     self.netname = "cells";
  798.     setsize (self, '0 0 0', '32 32 56');
  799.     StartItem ();
  800. };
  801.  
  802.  
  803. /*QUAKED item_weapon (0 .5 .8) (0 0 0) (32 32 32) shotgun rocket spikes big
  804. DO NOT USE THIS!!!! IT WILL BE REMOVED!
  805. */
  806.  
  807. float WEAPON_SHOTGUN = 1;
  808. float WEAPON_ROCKET = 2;
  809. float WEAPON_SPIKES = 4;
  810. float WEAPON_BIG = 8;
  811. void() item_weapon =
  812. {
  813.     self.touch = ammo_touch;
  814.  
  815.     if (self.spawnflags & WEAPON_SHOTGUN)
  816.     {
  817.         if (self.spawnflags & WEAPON_BIG)
  818.         {
  819.             precache_model ("maps/b_shell1.bsp");
  820.             setmodel (self, "maps/b_shell1.bsp");
  821.             self.aflag = 40;
  822.         }
  823.         else
  824.         {
  825.             precache_model ("maps/b_shell0.bsp");
  826.             setmodel (self, "maps/b_shell0.bsp");
  827.             self.aflag = 20;
  828.         }
  829.         self.weapon = 1;
  830.         self.netname = "shells";
  831.     }
  832.  
  833.     if (self.spawnflags & WEAPON_SPIKES)
  834.     {
  835.         if (self.spawnflags & WEAPON_BIG)
  836.         {
  837.             precache_model ("maps/b_nail1.bsp");
  838.             setmodel (self, "maps/b_nail1.bsp");
  839.             self.aflag = 40;
  840.         }
  841.         else
  842.         {
  843.             precache_model ("maps/b_nail0.bsp");
  844.             setmodel (self, "maps/b_nail0.bsp");
  845.             self.aflag = 20;
  846.         }
  847.         self.weapon = 2;
  848.         self.netname = "spikes";
  849.     }
  850.  
  851.     if (self.spawnflags & WEAPON_ROCKET)
  852.     {
  853.         if (self.spawnflags & WEAPON_BIG)
  854.         {
  855.             precache_model ("maps/b_rock1.bsp");
  856.             setmodel (self, "maps/b_rock1.bsp");
  857.             self.aflag = 10;
  858.         }
  859.         else
  860.         {
  861.             precache_model ("maps/b_rock0.bsp");
  862.             setmodel (self, "maps/b_rock0.bsp");
  863.             self.aflag = 5;
  864.         }
  865.         self.weapon = 3;
  866.         self.netname = "rockets";
  867.     }
  868.     
  869.     setsize (self, '0 0 0', '32 32 56');
  870.     StartItem ();
  871. };
  872.  
  873.  
  874. /*
  875. ===============================================================================
  876.  
  877. KEYS
  878.  
  879. ===============================================================================
  880. */
  881.  
  882. void() key_touch =
  883. {
  884. local entity    stemp;
  885. local float        best;
  886.  
  887.     if (other.classname != "player")
  888.         return;
  889.     if (other.health <= 0)
  890.         return;
  891.     if (other.items & self.items)
  892.         return;
  893.  
  894.     sprint (other, "You got the ");
  895.     sprint (other, self.netname);
  896.     sprint (other,"\n");
  897.  
  898.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  899.     stuffcmd (other, "bf\n");
  900.     other.items = other.items | self.items;
  901.  
  902.     if (!coop)
  903.     {    
  904.         self.solid = SOLID_NOT;
  905.         self.model = string_null;
  906.     }
  907.  
  908.     activator = other;
  909.     SUB_UseTargets();                // fire all targets / killtargets
  910. };
  911.  
  912.  
  913. void() key_setsounds =
  914. {
  915.     if (world.worldtype == 0)
  916.     {
  917.         precache_sound ("misc/medkey.wav");
  918.         self.noise = "misc/medkey.wav";
  919.     }
  920.     if (world.worldtype == 1)
  921.     {
  922.         precache_sound ("misc/runekey.wav");
  923.         self.noise = "misc/runekey.wav";
  924.     }
  925.     if (world.worldtype == 2)
  926.     {
  927.         precache_sound2 ("misc/basekey.wav");
  928.         self.noise = "misc/basekey.wav";
  929.     }
  930. };
  931.  
  932. /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32)
  933. SILVER key
  934. In order for keys to work
  935. you MUST set your maps
  936. worldtype to one of the
  937. following:
  938. 0: medieval
  939. 1: metal
  940. 2: base
  941. */
  942.  
  943. void() item_key1 =
  944. {
  945.     if (world.worldtype == 0)
  946.     {
  947.         precache_model ("progs/w_s_key.mdl");
  948.         setmodel (self, "progs/w_s_key.mdl");
  949.         self.netname = "silver key";
  950.     }
  951.     else if (world.worldtype == 1)
  952.     {
  953.         precache_model ("progs/m_s_key.mdl");
  954.         setmodel (self, "progs/m_s_key.mdl");
  955.         self.netname = "silver runekey";
  956.     }
  957.     else if (world.worldtype == 2)
  958.     {
  959.         precache_model2 ("progs/b_s_key.mdl");
  960.         setmodel (self, "progs/b_s_key.mdl");
  961.         self.netname = "silver keycard";
  962.     }
  963.     key_setsounds();
  964.     self.touch = key_touch;
  965.     self.items = IT_KEY1;
  966.     setsize (self, '-16 -16 -24', '16 16 32');
  967.     StartItem ();
  968. };
  969.  
  970. /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32)
  971. GOLD key
  972. In order for keys to work
  973. you MUST set your maps
  974. worldtype to one of the
  975. following:
  976. 0: medieval
  977. 1: metal
  978. 2: base
  979. */
  980.  
  981. void() item_key2 =
  982. {
  983.     if (world.worldtype == 0)
  984.     {
  985.         precache_model ("progs/w_g_key.mdl");
  986.         setmodel (self, "progs/w_g_key.mdl");
  987.         self.netname = "gold key";
  988.     }
  989.     if (world.worldtype == 1)
  990.     {
  991.         precache_model ("progs/m_g_key.mdl");
  992.         setmodel (self, "progs/m_g_key.mdl");
  993.         self.netname = "gold runekey";
  994.     }
  995.     if (world.worldtype == 2)
  996.     {
  997.         precache_model2 ("progs/b_g_key.mdl");
  998.         setmodel (self, "progs/b_g_key.mdl");
  999.         self.netname = "gold keycard";
  1000.     }
  1001.     key_setsounds();
  1002.     self.touch = key_touch;
  1003.     self.items = IT_KEY2;
  1004.     setsize (self, '-16 -16 -24', '16 16 32');
  1005.     StartItem ();
  1006. };
  1007.  
  1008.  
  1009.  
  1010. /*
  1011. ===============================================================================
  1012.  
  1013. END OF LEVEL RUNES
  1014.  
  1015. ===============================================================================
  1016. */
  1017.  
  1018. void() sigil_touch =
  1019. {
  1020. local entity    stemp;
  1021. local float        best;
  1022.  
  1023.     if (other.classname != "player")
  1024.         return;
  1025.     if (other.health <= 0)
  1026.         return;
  1027.  
  1028.     centerprint (other, "You got the rune!");
  1029.  
  1030.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  1031.     stuffcmd (other, "bf\n");
  1032.     self.solid = SOLID_NOT;
  1033.     self.model = string_null;
  1034.     serverflags = serverflags | (self.spawnflags & 15);
  1035.     self.classname = "";        // so rune doors won't find it
  1036.     
  1037.     activator = other;
  1038.     SUB_UseTargets();                // fire all targets / killtargets
  1039. };
  1040.  
  1041.  
  1042. /*QUAKED item_sigil (0 .5 .8) (-16 -16 -24) (16 16 32) E1 E2 E3 E4
  1043. End of level sigil, pick up to end episode and return to jrstart.
  1044. */
  1045.  
  1046. void() item_sigil =
  1047. {
  1048.     if (!self.spawnflags)
  1049.         objerror ("no spawnflags");
  1050.  
  1051.     precache_sound ("misc/runekey.wav");
  1052.     self.noise = "misc/runekey.wav";
  1053.  
  1054.     if (self.spawnflags & 1)
  1055.     {
  1056.         precache_model ("progs/end1.mdl");
  1057.         setmodel (self, "progs/end1.mdl");
  1058.     }
  1059.     if (self.spawnflags & 2)
  1060.     {
  1061.         precache_model2 ("progs/end2.mdl");
  1062.         setmodel (self, "progs/end2.mdl");
  1063.     }
  1064.     if (self.spawnflags & 4)
  1065.     {
  1066.         precache_model2 ("progs/end3.mdl");
  1067.         setmodel (self, "progs/end3.mdl");
  1068.     }
  1069.     if (self.spawnflags & 8)
  1070.     {
  1071.         precache_model2 ("progs/end4.mdl");
  1072.         setmodel (self, "progs/end4.mdl");
  1073.     }
  1074.     
  1075.     self.touch = sigil_touch;
  1076.     setsize (self, '-16 -16 -24', '16 16 32');
  1077.     StartItem ();
  1078. };
  1079.  
  1080. /*
  1081. ===============================================================================
  1082.  
  1083. POWERUPS
  1084.  
  1085. ===============================================================================
  1086. */
  1087.  
  1088. void() powerup_touch;
  1089.  
  1090.  
  1091. void() powerup_touch =
  1092. {
  1093. local entity    stemp;
  1094. local float        best;
  1095.  
  1096.     if (other.classname != "player")
  1097.         return;
  1098.     if (other.health <= 0)
  1099.         return;
  1100.  
  1101.     sprint (other, "You got the ");
  1102.     sprint (other, self.netname);
  1103.     sprint (other,"\n");
  1104.  
  1105.     if (deathmatch)
  1106.     {
  1107.         self.mdl = self.model;
  1108.         
  1109.         if ((self.classname == "item_artifact_invulnerability") ||
  1110.             (self.classname == "item_artifact_invisibility"))
  1111.             self.nextthink = time + 60*5;
  1112.         else
  1113.             self.nextthink = time + 60;
  1114.         
  1115.         self.think = SUB_regen;
  1116.     }    
  1117.  
  1118.     sound (other, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  1119.     stuffcmd (other, "bf\n");
  1120.     self.solid = SOLID_NOT;
  1121.     other.items = other.items | self.items;
  1122.     self.model = string_null;
  1123.  
  1124. // do the apropriate action
  1125.     if (self.classname == "item_artifact_envirosuit")
  1126.     {
  1127.         other.rad_time = 1;
  1128.         other.radsuit_finished = time + 30;
  1129.     }
  1130.     
  1131.     if (self.classname == "item_artifact_invulnerability")
  1132.     {
  1133.         other.invincible_time = 1;
  1134.         other.invincible_finished = time + 30;
  1135.     }
  1136.     
  1137.     if (self.classname == "item_artifact_invisibility")
  1138.     {
  1139.         other.invisible_time = 1;
  1140.         other.invisible_finished = time + 30;
  1141.     }
  1142.  
  1143.     if (self.classname == "item_artifact_super_damage")
  1144.     {
  1145.         other.super_time = 1;
  1146.         other.super_damage_finished = time + 30;
  1147.     }    
  1148.  
  1149.     activator = other;
  1150.     SUB_UseTargets();                // fire all targets / killtargets
  1151. };
  1152.  
  1153.  
  1154.  
  1155. /*QUAKED item_artifact_invulnerability (0 .5 .8) (-16 -16 -24) (16 16 32)
  1156. Player is invulnerable for 30 seconds
  1157. */
  1158. void() item_artifact_invulnerability =
  1159. {
  1160.     self.touch = powerup_touch;
  1161.  
  1162.     precache_model ("progs/invulner.mdl");
  1163.     precache_sound ("items/protect.wav");
  1164.     precache_sound ("items/protect2.wav");
  1165.     precache_sound ("items/protect3.wav");
  1166.     self.noise = "items/protect.wav";
  1167.     setmodel (self, "progs/invulner.mdl");
  1168.     self.netname = "Pentagram of Protection";
  1169.     self.items = IT_INVULNERABILITY;
  1170.     setsize (self, '-16 -16 -24', '16 16 32');
  1171.     StartItem ();
  1172. };
  1173.  
  1174. /*QUAKED item_artifact_envirosuit (0 .5 .8) (-16 -16 -24) (16 16 32)
  1175. Player takes no damage from water or slime for 30 seconds
  1176. */
  1177. void() item_artifact_envirosuit =
  1178. {
  1179.     self.touch = powerup_touch;
  1180.  
  1181.     precache_model ("progs/suit.mdl");
  1182.     precache_sound ("items/suit.wav");
  1183.     precache_sound ("items/suit2.wav");
  1184.     self.noise = "items/suit.wav";
  1185.     setmodel (self, "progs/suit.mdl");
  1186.     self.netname = "Biosuit";
  1187.     self.items = IT_SUIT;
  1188.     setsize (self, '-16 -16 -24', '16 16 32');
  1189.     StartItem ();
  1190. };
  1191.  
  1192.  
  1193. /*QUAKED item_artifact_invisibility (0 .5 .8) (-16 -16 -24) (16 16 32)
  1194. Player is invisible for 30 seconds
  1195. */
  1196. void() item_artifact_invisibility =
  1197. {
  1198.     self.touch = powerup_touch;
  1199.  
  1200.     precache_model ("progs/invisibl.mdl");
  1201.     precache_sound ("items/inv1.wav");
  1202.     precache_sound ("items/inv2.wav");
  1203.     precache_sound ("items/inv3.wav");
  1204.     self.noise = "items/inv1.wav";
  1205.     setmodel (self, "progs/invisibl.mdl");
  1206.     self.netname = "Ring of Shadows";
  1207.     self.items = IT_INVISIBILITY;
  1208.     setsize (self, '-16 -16 -24', '16 16 32');
  1209.     StartItem ();
  1210. };
  1211.  
  1212.  
  1213. /*QUAKED item_artifact_super_damage (0 .5 .8) (-16 -16 -24) (16 16 32)
  1214. The next attack from the player will do 4x damage
  1215. */
  1216. void() item_artifact_super_damage =
  1217. {
  1218.     self.touch = powerup_touch;
  1219.  
  1220.     precache_model ("progs/quaddama.mdl");
  1221.     precache_sound ("items/damage.wav");
  1222.     precache_sound ("items/damage2.wav");
  1223.     precache_sound ("items/damage3.wav");
  1224.     self.noise = "items/damage.wav";
  1225.     setmodel (self, "progs/quaddama.mdl");
  1226.     self.netname = "Quad Damage";
  1227.     self.items = IT_QUAD;
  1228.     setsize (self, '-16 -16 -24', '16 16 32');
  1229.     StartItem ();
  1230. };
  1231.  
  1232.  
  1233.  
  1234. /*
  1235. ===============================================================================
  1236.  
  1237. PLAYER BACKPACKS
  1238.  
  1239. ===============================================================================
  1240. */
  1241.  
  1242. void() BackpackTouch =
  1243. {
  1244.     local string    s;
  1245.     local    float    best;
  1246.     local        entity    stemp;
  1247.     
  1248.     if (other.classname != "player")
  1249.         return;
  1250.     if (other.health <= 0)
  1251.         return;
  1252.  
  1253. // *TEAMPLAY*
  1254. // Don't let the owner pick up his own backpack for one second.
  1255.         if ( (other == self.owner) && ( (self.nextthink - time) > 119 ) )
  1256.                 return;
  1257.         
  1258. // if the player was using his best weapon, change up to the new one if better        
  1259.     stemp = self;
  1260.     self = other;
  1261.     best = W_BestWeapon();
  1262.     self = stemp;
  1263.  
  1264. // change weapons
  1265.     other.ammo_shells = other.ammo_shells + self.ammo_shells;
  1266.     other.ammo_nails = other.ammo_nails + self.ammo_nails;
  1267.     other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
  1268.     other.ammo_cells = other.ammo_cells + self.ammo_cells;
  1269.  
  1270.     other.items = other.items | self.items;
  1271.     
  1272.     bound_other_ammo ();
  1273.  
  1274.     sprint (other, "You get ");
  1275.  
  1276.     if (self.ammo_shells)
  1277.     {
  1278.         s = ftos(self.ammo_shells);
  1279.         sprint (other, s);
  1280.         sprint (other, " shells  ");
  1281.     }
  1282.     if (self.ammo_nails)
  1283.     {
  1284.         s = ftos(self.ammo_nails);
  1285.         sprint (other, s);
  1286.         sprint (other, " nails ");
  1287.     }
  1288.     if (self.ammo_rockets)
  1289.     {
  1290.         s = ftos(self.ammo_rockets);
  1291.         sprint (other, s);
  1292.         sprint (other, " rockets  ");
  1293.     }
  1294.     if (self.ammo_cells)
  1295.     {
  1296.         s = ftos(self.ammo_cells);
  1297.         sprint (other, s);
  1298.         sprint (other, " cells  ");
  1299.     }
  1300.     
  1301.     sprint (other, "\n");
  1302. // backpack touch sound
  1303.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  1304.     stuffcmd (other, "bf\n");
  1305.  
  1306. // change to a better weapon if appropriate
  1307.     if ( other.weapon == best )
  1308.     {
  1309.         stemp = self;
  1310.         self = other;
  1311.         self.weapon = W_BestWeapon();
  1312.         self = stemp;
  1313.     }
  1314.  
  1315.     
  1316.     remove(self);
  1317.     
  1318.     self = other;
  1319.     W_SetCurrentAmmo ();
  1320. };
  1321.  
  1322. /*
  1323. ===============
  1324. DropBackpack
  1325. ===============
  1326. */
  1327. void() DropBackpack =
  1328. {
  1329.     local entity    item;
  1330.  
  1331.     if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells))
  1332.         return;    // nothing in it
  1333.  
  1334.     item = spawn();
  1335.     item.origin = self.origin - '0 0 24';
  1336.     
  1337.     item.items = self.weapon;
  1338.  
  1339.     item.ammo_shells = self.ammo_shells;
  1340.     item.ammo_nails = self.ammo_nails;
  1341.     item.ammo_rockets = self.ammo_rockets;
  1342.     item.ammo_cells = self.ammo_cells;
  1343.  
  1344.     item.velocity_z = 300;
  1345.     item.velocity_x = -100 + (random() * 200);
  1346.     item.velocity_y = -100 + (random() * 200);
  1347.     
  1348.     item.flags = FL_ITEM;
  1349.     item.solid = SOLID_TRIGGER;
  1350.     item.movetype = MOVETYPE_TOSS;
  1351.     setmodel (item, "progs/backpack.mdl");
  1352.     setsize (item, '-16 -16 0', '16 16 56');
  1353.     item.touch = BackpackTouch;
  1354.     
  1355.     item.nextthink = time + 120;    // remove after 2 minutes
  1356.     item.think = SUB_Remove;
  1357. };
  1358.