Randomized Artillery Bombardment
by Steve Acaster · 03/08/2012 (10:03 am) · 6 comments
A randomized bombardment script for dropping artillery around the player. Perfect for those "storm the beaches" levels.
//-----------------------------------------------------------------------------
// Creating a randomized mortar/artillery barrage
// for those exciting "storm the beaches" levels ...
// no "Ball of Fruity" clone would be complete without it!
//-----------------------------------------------------------------------------
// FIRST UP, CREATE A NEW CS FILE IN SCRIPTS/SERVER FOLDER AND CALL IT
// bombardment.cs
//We only want the bombs to fall within a 100 unit radius of the player
//because the player may not see them if they are further away
//and then you're just wasting resources
function prepareBombardment()
{
//find the playerObject via the client
//we're only doing singleplayer here so we can only have 1 client
//pick the first client
%client = ClientGroup.getObject(0);
//get the client's controlObject - hopefully the player, if not then the camera
%player = %client.getControlObject();
//and the playerObject's location
%pos = %player.getPosition();
startBombardment(%pos);
}
function startBombardment(%centre)
{
//we start with an XYZ
%centreX = firstWord(%centre);
%centreY = getWord(%centre, 1);
echo(%centre);
echo(%centreX);
echo(%centreY);
//and extrapolate our max and min coordinates
%minX = %centreX - 100;
%maxX = %centreX + 100;
echo(%minX);
echo(%maxX);
%minY = %centreY - 100;
%maxY = %centreY + 100;
echo(%maxY);
echo(%minY);
%x = getRandom(%minX, %maxX);
%y = getRandom(%minY, %maxY);
//z will always be high above the terrain
//1024 should be enough to make sure it clears
//dependant on the actual xyz of the terrain and also it's highest point
%z = 1024;
echo(%x SPC %y SPC %z);
%target = %x SPC %y SPC %z;
echo(%target);
completeBombardment(%target);
%random = getRandom(500, 3000);
//and random pause before going back to prepareBombardment
//incase player is dead and we need a new controlObject to target
schedule(%random, 0, "prepareBombardment");
}
function completeBombardment(%start)
{
echo(%start);
//look down and find something below up to 1500 units
//you can probably get away with less but just to be sure
%end = vectorSub(%start, "0 0 1500");
//what we want to hit
%mask = $TypeMasks::TerrainObjectType | $TypeMasks::StaticObjectType;
// debugdraw.togglefreeze();
// debugdraw.drawline(%start, %end, "0 0 1");
%hit = ContainerRayCast(%start, %end, %mask);
if(%hit == 0)
{
echo("c2error: LINE OF SIGHT FOR BOMBARDMENT MISSED!");
//ignore and bail!
return;
}
//get the XYZ of the impact
%xyz = getWords(%hit, 1, 3);
//and spawn the stock grenadelauncher explosion
%blast = new explosion()
{
dataBlock = "GrenadeLauncherExplosion";
position = %xyz;
};
MissionCleanup.add(%blast);
//and roll for damage!
radiusDamage(0, %xyz, 10, 25, "blastDamage", 2000);
//and finally, slap on the stock decal at the impact site
%decalObj = decalManagerAddDecal(%xyz, "0.0 0.0 1.0", 0, 1, "ScorchRXDecal", false);
}
/*
We want to start this all up when the client has actually arrived in the game
So open up scripts/server/gameDM.cs <--- because deathMatch is the stock default gametype
And find onClientEnterGame and add:
[start]
//...
function DeathMatchGame::onClientEnterGame(%game, %client)
{
//echo (%game @"c4 -> "@ %game.class @" -> DeathMatchGame::onClientEnterGame");
schedule(3000, %client, "prepareBombardment");//yorks new!
parent::onClientEnterGame(%game, %client);
}
//...
[/end]
And lastly, we need to exec our new file
Open up scripts/server/scriptExec.cs
And right at the bottom add:
[start]
//...
// Load our gametypes
exec("./gameCore.cs"); // This is the 'core' of the gametype functionality.
exec("./gameDM.cs"); // Overrides GameCore with DeathMatch functionality.
exec("./bombardment.cs"); // yorks new, right at the end
[/end]
*/About the author
One Bloke ... In His Bedroom ... Making Indie Games ...
#2
03/08/2012 (1:18 pm)
Interesting stuff Steve, will come in useful for a project i have in mind
#3
03/09/2012 (5:03 am)
Dammit Steve, stop being so awesome all the time.
#4
03/10/2012 (1:46 am)
Thanks Steve. Very nice resource.
#5
03/10/2012 (8:40 am)
Yeah thanks for this.
#6
03/17/2012 (7:28 am)
Cool stuff. I wonder if it shouldn't "hone in" on the player when they stop. :P 
Torque Owner Donnie Hutson Jr
Highground Out:
FIXED::Ok steve, one quick question??? How can I add a decal for the airstrike bombs??? Never mind I got it and thanks again....