[Image]

 Created By:                                  Rebel
 eMail                                        xrebelx@pipeline.com
 Difficulty Scale                             Medium

 [Image]Step 1
        This simple tutorial will help you create a mirv grenade that when thrown, will split up into eight
        different grenades. Similar to what you find in TF. First, fire up that text editor and scroll down to
        the part where it says:

        /*
        ================
        W_FireGrenade
        ================
        */

        Just before that (or just after) put in the following code.

        void() MirvExplode =
        {
                local float mirv = 0;   //Create a variable called mirv that equals zero
                local entity missile;   //Create an entity called missile

                while (mirv < 8)                //While mirv is less than eight
                {
                mirv = mirv + 1;                //add another to mirv

                missile = spawn();                              //Spawn a missile
                missile.owner = self;                           //The missile's owner is player
                missile.movetype = MOVETYPE_BOUNCE;             //The missile bounces
                missile.solid = SOLID_BBOX;                     //The missile is solid
                missile.classname = "grenade";          //Names the missile a grenade

        //set missile speed

                missile.velocity_z = 500;
                missile.velocity_x = -100 + (random()* 200);
                missile.velocity_y = -100 + (random()* 200);
                missile.avelocity = '300 300 300';
                missile.angles = vectoangles (missile.velocity);

        //set missile duration


                missile.nextthink = time + 2.5;         //Sets time before it explodes
                missile.think = GrenadeExplode;         //What to do after 2.5 seconds
                missile.touch = GrenadeTouch;                   //What to do if touched
                setmodel (missile, "progs/grenade.mdl");        //Use grenade model
                setsize (missile, '0 0 0', '0 0 0');    //Set size for grenade
                setorigin (missile, self.origin);               //Where the grenade will spawn
                }

                WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);      //This will make the first grenade explode
                WriteByte (MSG_BROADCAST, TE_EXPLOSION);
                WriteCoord (MSG_BROADCAST, self.origin_x);
                WriteCoord (MSG_BROADCAST, self.origin_y);
                WriteCoord (MSG_BROADCAST, self.origin_z);

                BecomeExplosion();
        };

        void() MirvTouch =                              //Just slightly modified the GrenadeTouch
        {
                if (other == self.owner)
                        return;         // don't explode on owner
                if (other.takedamage == DAMAGE_AIM)
                {
                        MirvExplode();
                        return;
                }
                sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
                if (self.velocity == '0 0 0')
                        self.avelocity = '0 0 0';
        };

        void() W_FireMirv =
        {
                if (self.ammo_rockets >= 8)             //If you have eight rockets or more
                {
                local   entity missile, mpuff;          //Create entity

                self.currentammo = self.ammo_rockets = self.ammo_rockets - 8;   //Take away 8 rockets

                sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM); //Use grenade sound

                self.punchangle_x = -2;

                missile = spawn ();                             //Spawn missile
                missile.owner = self;                           //The missile's owner is player
                missile.movetype = MOVETYPE_BOUNCE;             //The missile bounces
                missile.solid = SOLID_BBOX;                     //The missile is solid
                missile.classname = "grenade";          //Names the missile a grenade

        // set missile speed

                makevectors (self.v_angle);

                if (self.v_angle_x)
                        missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
                else
                {
                        missile.velocity = aim(self, 10000);
                        missile.velocity = missile.velocity * 600;
                        missile.velocity_z = 200;
                }

                missile.avelocity = '300 300 300';

                missile.angles = vectoangles(missile.velocity);

                missile.touch = MirvTouch;

        // set missile duration
                missile.nextthink = time + 2.5;                 //Sets time before it explodes
                missile.think = MirvExplode;                            //What to do after 2.5 seconds

                setmodel (missile, "progs/grenade.mdl");                //Use grenade model
                setsize (missile, '0 0 0', '0 0 0');            //Set grenade size
                setorigin (missile, self.origin);                       //Where grenade will spawn
                }

                else            //If player doesn't have eight or more rockets...

                {
                sprint (self, "Not enough ammo.\n");    //Tell player Not enough ammo.
                return;                                         //Return to game
                }
        };

 [Image]Step 2
        Next, you need an impulse to throw the grenade so scroll down near the bottom to the
        section:

        /*
        ============
        ImpulseCommands

        ============
        */
        void() ImpulseCommands =
        {
                if (self.impulse >= 1 && self.impulse <= 8)
                        W_ChangeWeapon ();

                if (self.impulse == 9)
                        CheatCommand ();
                if (self.impulse == 10)
                        CycleWeaponCommand ();
                if (self.impulse == 11)
                        ServerflagsCommand ();
                if (self.impulse == 12)
                        CycleWeaponReverseCommand ();
                if (self.impulse == 100)                        //Add this, if impulse is 100
                        W_FireMirv();                           //Throw mirv grenade

 [Image]Step 3
        Your done. Compile, run it, and have fun with your new toy. If you type
        impulse 100 at the console you will now throw a mirv grenade if you have at
        least eight rockets. It would be helpful to bind a key to impulse 100.
        Example: bind a "impulse 100". Some credit goes to Smoke2Much since I stole,
        err, borrowed some code from his Cluster Bomb tutorial. =)
