Cluster Grenade

1/27/1999 Well this is always a fun grenade to make and have in any game. They are very simple to make too! This will show you how vectors work and show that angles are all in radians. Here is a pic of the grenade in action and what to expect when you are done. This grenade will shoot out 4 grenades right when it explodes( okay actually just a little bit before but with lag over the internet you won't be able to tell the difference). Ok first open up mine.cs and put at the bottom this code


	MineData Cluster
	{
		mass = 0.35;
		drag = 1.0;
		density = 2.0;
		elasticity = 0.15;
		friction = 1.0;
		className = "Clustergrenade";
		description = "Handgrenade";
		shapeFile = "grenade";
		shadowDetailMask = 4;
		explosionId = debrisExpSmall;
		explosionRadius = 5.0;
		damageValue = 0.5;
		damageType = $ShrapnelDamageType;
		kickBackStrength = 60;
		triggerRadius = 0.5;
		maxDamage = 0.9;
	};

	function Cluster::onAdd(%this)
	{
		%data = GameBase::getDataName(%this);
		schedule("Mine::Detonate(" @ %this @ ");",0.85,%this);
	}

	
This is the data for the cluster grenade. Now that we have this defined modify the hand grenade so it looks like this.

	MineData Handgrenade
	{
		mass = 0.4;//JR a little heavier(yes I know its not what it should be that weighs too much)
		drag = 1.0;
		density = 2.0;
		elasticity = 0.25;//JR increased it for the hell of it
		friction = 1.0;
		className = "Handgrenade";
		description = "Handgrenade";
		shapeFile = "grenade";
		shadowDetailMask = 4;
		explosionId = debrisExpMedium;//JR different explosion other one too big for this
		explosionRadius = 1.0;//JR shrunk down the radius
		damageValue = 0.5;
		damageType = $ShrapnelDamageType;
		kickBackStrength = 10;//JR not as much kick back
		triggerRadius = 0.5;
		maxDamage = 0.5;//JR less damage 
	};

	
Okay this just sets up the hand grenade so it does less damage and has a different explosion and some misc other things well here is the code that does it all now.

	function ThrowCluster(%this)
	{
		%vect[0]= 0.7853981633974;
		%vect[1]=1.570796326795;
		%vect[2]=- 3.1415926536;
		GameBase::setRotation (%this,%vect[0] @ " " @ %vect[1] @ " " @ %vect[2]);
		%obj = newObject("","Mine","Cluster");
 		addToSet("MissionCleanup", %obj);
		GameBase::throw(%obj,%this,0.6,false);
		%vect[0]= 0.7853981633974;
		%vect[1]=1.570796326795;
		%vect[2]=- 1.570796326795;
		GameBase::setRotation (%this,%vect[0] @ " " @ %vect[1] @ " " @ %vect[2]);
		%obj = newObject("","Mine","Cluster");
 		addToSet("MissionCleanup", %obj);
		GameBase::throw(%obj,%this,0.6,false);
		%vect[0]= 0.7853981633974;
		%vect[1]=1.570796326795;
		%vect[2]= 0;
		GameBase::setRotation (%this,%vect[0] @ " " @ %vect[1] @ " " @%vect[2]);
		%obj = newObject("","Mine","Cluster");
 		addToSet("MissionCleanup", %obj);
		GameBase::throw(%obj,%this,0.6,false);
		%vect[0]= 0.7853981633974;
		%vect[1]=1.570796326795;
		%vect[2]= 1.570796326795;
		GameBase::setRotation (%this,%vect[0] @ " " @ %vect[1] @ " " @ %vect[2]);
		%obj = newObject("","Mine","Cluster");
 		addToSet("MissionCleanup", %obj);
		GameBase::throw(%obj,%this,0.6,false);
	}
	
	
What that code does is throw 4 cluster grenades and rotating the main grenade every time before it so it gets thrown the right direction. As you can see vector our actually a string with 3 floats and spaces inbetween. Set rotation sets up the right angles for each grenade. Now one more line of code needs to be added for it to work.
	
	function Handgrenade::onAdd(%this)
	{
		%data = GameBase::getDataName(%this);
		schedule("ThrowCluster(" @ %this @ ");",1.99,%this);//JR This throws out all the grenades
		schedule("Mine::Detonate(" @ %this @ ");",2.0,%this);
	}

	
Okay all that does is sets it up so it will throw the grenades a 1/100 of a second before the grenade blows up first off not too many people get a 100+ fps so no will likely see them coming out before the explosion. You say why not add them in Mine::Detonate because mines also use it. Which to tell you I hope to have a tutorial tomorrow for team mines. Well that wraps it up pack and go try it out! Email me any tutorials you have written.

Cryect

This is part of the page "The Scripter" please do not copy this data to another webpage without permission