this.thargoidCounter is the variable used to count Thargoids as they spawn. It's set to 0 when the game is launched, when the player docks and when the player is about to jump.
The next code block under the this.shipSpawned will run whenever the game engine adds a ship to the ooniverse. If the player's kills are less than 512 it does nothing - return; stops the code running any further. Otherwise it will check to see if a ship added is a thargoid and is so increase the counter by 1.
The next code block under a combined this.shipExitedWitchSpace = this.shipLaunchedFromStation event handler will run just as the player exits witchspace or launches. By this point the game engine should have populated the system and this.thargoidCounter will be more than 0 if any thargoids were spawned. It then adds 1 UFOship for each Thargoid, within 20000m of the player. After adding the right number of UFOships it resets this.thargoidCounter to 0
Code: Select all
// Standard attributes
this.name = "UFOship.js";
this.author = "mandoman";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "1.0.1";
this.description = "Script to spawn equal number of UFOships as number of Thargoid ships if player ship with score 512, or higher exits Witchspace."
//code block to set thargoidCounter to 0 on starting the game, docking and entering witchspace.
this.startUp = this.shipDockedWithStation = this.shipWillEnterWitchspace = function()
{
this.thargoidCounter = 0;
}
// code block that runs when any NPC ship is spawned
this.shipSpawned = function(newship) //newship is now available to the function body
{
if (player.score<512){return;} // do nothing if players kills are too low.
if (newship.isThargoid) {this.thargoidCounter++;} //check if newship is a Thargoid (isThargoid is a property of a ship object), and if so increase this.thargoidCounter by 1
}
// code block which runs just as player exits witchspace tunnel, or just as player launches
this.shipExitedWitchSpace = this.shipLaunchedFromStation = function()
{
if (this.thargoidCounter>0) // check to see if at least one thargoid was spawned
{
system.addShips("UFOship", this.thargoidCounter, player.ship.position, 20000); //add one UFOship for each thargoid spawned.
this.thargoidCounter = 0;// reset the counter after spawning UFOships
}
}
Code: Select all
// Standard attributes
this.name = "UFOship.js";
this.author = "mandoman";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "1.0.1";
this.description = "Script to spawn equal number of UFOships as number of Thargoid ships if player ship with score 512, or higher exits Witchspace."
// will run as player exits witchspace or player launches from station, and after game engine has populated the system
this.shipExitedWitchSpace = this.shipLaunchedFromStation = function()
{
var UFOshipCounter = system.countShipsWithPrimaryRole("UFOship"); // count how may UFO ships are in the system (in case this is a second launch and they have already been spawned.
if (player.score < 512 || UFOshipCounter > 0){return;} // do nothing if player kills is less than 512 or there are already UFOships in the ooniverse.
var thargoidCounter = system.countShipsWithPrimaryRole("thargoid"); // counts how many thargoids there are
if (thargoidCounter> 0) // if more than 0 then spawn equal number of UFOships.
{
system.addShips("UFOship", thargoidCounter, player.ship.position, 20000);
}
}