Right, here's what I've got so far after some spit and polish. Still needs some testing, some things not yet working.
Code: Select all
this.name = "HPC Cobra Mk3 ship scripts";
this.author = "Cim, Dertien";
this.contributors = "Cim, Neelix, Zirael, Eric Walsh";
this.copyright = "Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) http://creativecommons.org/licenses/by-nc-sa/3.0/";
this.version = "1.00";
// Cim: So, what you can do is search through the subentities list until you find the one you want.
this._findSubEntity = function(key)
{
for (var i = this.ship.subEntities.length - 1 ; i >=0 ; --i)
{
if (this.ship.subEntities[i].dataKey == key)
{
return this.ship.subEntities[i];
}
}
return null; // couldn't find it.
}
// reusable function that retracts the gear (not animated yet)
this.retractGear = function()
{
var actuatorsR = this._findSubEntity("HPC_actuatorR");
if (actuatorsR)
{
actuatorsR.position = [0, 6.155206, 2.648078];
}
var actuatorsF = this._findSubEntity("HPC_actuatorF");
if (actuatorsF)
{
actuatorsF.position = [0, 3.80, -21.3];
}
var reargearextendPRT = this._findSubEntity("HPC_reargearPRT");
if (reargearextendPRT)
{
reargearextendPRT.position = [-17.392771, -8.961073, 2.796213];
reargearextendPRT.orientation = [0.9953, 0.0908, 0, 0];
}
var reargearextendSTB = this._findSubEntity("HPC_reargearSTB");
if (reargearextendSTB)
{
reargearextendSTB.position = [17.552752, -8.847222, 3.028129];
reargearextendPRT.orientation = [-0.9953, -0.0908, 0, 0];
}
var frontgearextendPRT = this._findSubEntity("HPC_frontgearPRT");
if (frontgearextendPRT)
{
frontgearextendPRT.position = [-13.038872, -5.954015, 25.049587];
reargearextendPRT.orientation = [0, 0, 0.9959, -0.0905];
}
var frontgearextendSTB = this._findSubEntity("HPC_frontgearSTB");
if (frontgearextendSTB)
{
frontgearextendSTB.position = [13.038872, -5.954015, 25.049587];
reargearextendPRT.orientation = [0.9959, 0.0905, 0, 0];
}
}
// reusable function that extends the gear (not animated yet)
this.extendGear = function()
{
var actuatorsR = this._findSubEntity("HPC_actuatorR");
if (actuatorsR)
{
actuatorsR.position = [0,0,0];
}
var actuatorsF = this._findSubEntity("HPC_actuatorF");
if (actuatorsF)
{
actuatorsF.position = [0,0,0];
}
var reargearextendPRT = this._findSubEntity("HPC_reargearPRT");
if (reargearextendPRT)
{
reargearextendPRT.position = [-17.351349,-17.408951,-3.749173];
}
var reargearextendSTB = this._findSubEntity("HPC_reargearSTB");
if (reargearextendSTB)
{
reargearextendSTB.position = [17.435233,-17.338642,-3.50929];
}
var frontgearextendPRT = this._findSubEntity("HPC_frontgearPRT");
if (frontgearextendPRT)
{
frontgearextendPRT.position = [-12.765342,-11.194131,27.818142];
}
var frontgearextendSTB = this._findSubEntity("HPC_frontgearSTB");
if (frontgearextendSTB)
{
frontgearextendSTB.position = [12.765342,-11.194131,27.818142];
}
}
// functions to switch the navlights on and off
this.switchFlashersOn = function()
{
this.ship.lightsActive = true; // turns flashers on
}
this.switchFlashersOff = function()
{
this.ship.lightsActive = false; // turns flashers off
}
// Function that controls gear, if no autopilot is used.
this.noDockingComputer = function()
{
// OPTION 1
// if target is a station in range lower gear
if (this.ship !== player.ship && this.ship.dockingInstructions)
{
this.extendGear();
this.$dockingTargetChecker.start();
return;
}
// OPTION 2
// if the player's target is a station which is less than 5000 Km away, gear down !
if (this.ship == player.ship && this.ship.target && this.ship.target.isStation && player.ship.position.distanceTo(player.ship.target) < 5000)
{
// player.consoleMessage("station in range - gear is down");
this.extendGear();
this.$dockingTargetChecker.start();
return;
}
// OPTION 2
// if the player's target is a station but is more than 5000 Km, gear up !
if (this.ship == player.ship && this.ship.target && this.ship.target.isStation && player.ship.position.distanceTo(player.ship.target) > 5000)
{
// player.consoleMessage("station too far");
this.retractGear();
this.$dockingTargetChecker.start();
return;
}
// OPTION 3
//if the player's target is not a station retract gear
if (this.ship == player.ship && (!player.ship.target || !player.ship.target.isStation))
{
// player.consoleMessage("Invalid target");
this.retractGear();
return;
}
}
this.shipSpawned = function()
{
//player.consoleMessage("Ship spawned !");
this.$checkvalid = function()
{
//player.consoleMessage("Ship Spawned in range for docking instructions?");
if (this.ship.dockingInstructions && this.ship !== player.ship)
{
this.extendGear();
//player.consoleMessage("SPAWN TESTER");
}
}
}
this.shipEnteredStationAegis = function(station)
{
this.switchFlashersOn();
}
this.shipExitedStationAegis = function(station)
{
this.switchFlashersOff();
}
// if a ship launches (NPC and Player), show gear deployed and automatically retract after 5 seconds
this.shipLaunchedFromStation = function(station)
{
this.extendGear(); // extend gear
this.tenSecTimer = new Timer(this, this.retractGear,5); // retract gear after 5 sec
// player.consoleMessage("Exiting Station");
// player.consoleMessage("GEAR UP in 10 Sec");
this.switchFlashersOn(); //turn on nav lights on wingtips
// since it's not necessary to see NPC's drop their gear when inside station, only trigger when player ship lauches.
if (this.ship == player.ship)
{
this.$dockingTargetChecker = new Timer(this, this.noDockingComputer,6, 2);
this.$spawnchecker = new Timer(this, this.$checkvalid,1, 5);
}
}
// when player hits C key with docking computers installed gear drops
this.playerStartedAutoPilot = function()
{
player.consoleMessage("Docking sequence started");
player.consoleMessage("GEAR DOWN & LOCKED");
this.switchFlashersOn(); // to turn them on outside of aegis ex. constore docking
this.extendGear();
if(this.$dockingTargetChecker) {
this.$dockingTargetChecker.stop();
delete this.$dockingTargetChecker;
}
}
// if player cancels docking computers, gear retracts
this.playerCancelledAutoPilot = function()
{
player.consoleMessage("Docking sequence aborted");
player.consoleMessage("GEAR UP");
this.retractGear();
this.$dockingTargetChecker = new Timer(this, this.noDockingComputer,1, 2);
}
// about same as shipLaunchedFromStation function
this.shipLeavingPlanetSurface = function(planet)
{
//player.consoleMessage("Ship Departing");
//player.consoleMessage("Exiting Atmosphere");
this.extendGear();
this.tenSecTimer = new Timer(this, this.retractGear,10);
if (this.ship == player.ship)
{
this.$dockingTargetChecker = new Timer(this, this.noDockingComputer,12, 2);
this.$spawnchecker = new Timer(this, this.$checkvalid,1, 5);
}
this.ship.commsMessage("GEAR UP 10 Seconds");
}
// if player exits witchspace, start both timers.
this.shipWillExitWitchspace = function()
{
this.switchFlashersOff();
if (this.ship == player.ship)
{
this.$dockingTargetChecker = new Timer(this, this.noDockingComputer,12, 2);
this.$spawnchecker = new Timer(this, this.$checkvalid,1, 5);
}
}
// ship NPC and Player drops gear before planetary landing
this.shipApproachingPlanetSurface = function(planet)
{
this.extendGear();
// Player ship landed on surface, no need for timer or flashers.
if (this.ship == player.ship)
{
player.consoleMessage("SHIP LANDING !");
this.switchFlashersOff();
this.extendGear();
this.$cleanupTimers();
}
}
this.shipWillEnterWitchspace = function()
{
this.switchFlashersOff();
this.$cleanupTimers();
}
this.stationWithdrewDockingClearance = function()
{
this.retractGear();
if(this.$dockingTargetChecker) {
this.$dockingTargetChecker.start();
}
}
this.shipWillLaunchFromStation = function(station)
{
this.extendGear();
}
this.shipDockedWithStation = function(station)
{
if (this.ship == player.ship)
{
player.consoleMessage("SHIP DOCKED !");
this.switchFlashersOff();
this.extendGear();
this.$cleanupTimers();
}
}
this.$cleanupTimers = function()
{
if(this.$dockingTargetChecker) {
this.$dockingTargetChecker.stop();
delete this.$dockingTargetChecker;
}
if(this.$spawnchecker) {
this.$spawnchecker.stop();
delete this.$spawnchecker;
}
}
this.entityDestroyed = function ()
{
this.$cleanupTimers();
}
Will look at it tomorrow.