Scripts/emergency_docking.js |
"use strict";
this.name = "Emergency Docking Clearance";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "Override docking delays";
this.version = "1.1";
this.$waitingLimit = 15; // max 15 min
this.shipWillLaunchFromStation = this.shipEnteredStationAegis = function()
{
if(system.isInterstellarSpace || !system.mainStation.isValid)
{ return; }
system.mainStation.requiresDockingClearance = true;
this.$waitingCounter = 0;
this.$waitingTime = this.$waitingLimit;
}
this.shipWillDockWithStation = this.shipWillEnterWitchspace = this.shipExitedStationAegis = function()
{
this.shipDied();
}
this.$setClearance = function()
{
if(!system.mainStation || player.dockingClearanceStatus == "DOCKING_CLEARANCE_STATUS_GRANTED")
{
this.shipDied();
return;
}
this.$waitingCounter += 1;
var message;
if (this.$waitingCounter >= 60)
{
if (system.mainStation.alertCondition == 3)
{
message = "Emergency docking frozen";
}
else
{
this.$waitingTime -= 1;
if (this.$waitingTime > 0 && player.ship.aftShield >= 0.1 * player.ship.maxAftShield)
{
message = "Emergency docking in " + this.$waitingTime + " min";
}
else
{
system.mainStation.requiresDockingClearance = false;
message = "Emergency docking allowed";
}
}
player.consoleMessage("\n\n\n\n\n\n\n\n\n\n Docking clearance status: " + message,5);
this.$waitingCounter -= 60;
}
}
this.shipDied = function()
{
if(this.$dockTimer)
{
this.$dockTimer.stop();
delete this.$dockTimer;
}
}
this.playerRequestedDockingClearance = function(message)
{
if (player.ship.target != system.mainStation || player.bounty > 50 || system.mainStation.alertCondition == 3)
{ return; }
if (player.ship.aftShield < 0.1 * player.ship.maxAftShield) // shields possibly shut down
{
system.mainStation.requiresDockingClearance = false;
}
else
{
if (!this.$dockTimer)
{
this.$dockTimer = new Timer(this, this.$setClearance, 0, 1);
}
}
} |
Scripts/traffic_lights.js |
"use strict";
this.name = "Traffic Lights";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "Indicates docking clearance status";
this.version = "1.1";
// this script is partially based on Neo-Dock Lights OXP by Thargoid
this.startUp = function ()
{
this.$lightsStatus = "BLUE";
this.$lightsTimer = new Timer(this, this.$setLights, 0, 1);
this.$lightsTimer.stop();
}
this.shipWillLaunchFromStation = this.shipEnteredStationAegis = function()
{
if(system.isInterstellarSpace || !system.mainStation || !system.mainStation.isValid)
{ return; }
this.$lightsPosition = system.mainStation.position.add(system.mainStation.vectorForward.multiply(10000));
this.$lights = system.addVisualEffect("dockLights_blue", this.$lightsPosition);
this.$lights.orientation = system.mainStation.orientation;
this.$lightsTimer.start();
}
this.shipWillDockWithStation = this.shipWillEnterWitchspace = this.shipExitedStationAegis = function()
{
this.shipDied();
}
this.$setLights = function()
{
if(!system.mainStation)
{
this.shipDied();
return;
}
function dockingShips(entity) {return entity.isShip && !entity.isPlayer && !entity.hasRole("buoy") && ((entity.position.distanceTo(system.mainStation.position) + entity.position.distanceTo(this.$lights.position)) < 10100)}
var incomingArray = system.filteredEntities(this, dockingShips, system.mainStation, 10000);
this.$lightsPosition = system.mainStation.position.add(system.mainStation.vectorForward.multiply(10000));
if(player.dockingClearanceStatus == "DOCKING_CLEARANCE_STATUS_GRANTED" || !system.mainStation.requiresDockingClearance)
{
this.$dockingStatus = "GREEN";
}
else
{
if(player.dockingClearanceStatus == "DOCKING_CLEARANCE_STATUS_TIMING_OUT")
{
this.$dockingStatus = "YELLOW";
}
else
{
if(player.dockingClearanceStatus == "DOCKING_CLEARANCE_STATUS_REQUESTED")
{
this.$dockingStatus = "RED";
}
else
{
this.$dockingStatus = "BLUE";
}
}
}
// condition RED
if(this.$dockingStatus == "RED" && this.$lightsStatus != "RED")
{
this.$removeLights();
this.$lights = system.addVisualEffect("dockLights_red", this.$lightsPosition);
this.$lights.orientation = system.mainStation.orientation;
this.$lightsStatus = "RED";
return;
}
// condition YELLOW
if((this.$dockingStatus == "YELLOW" || (this.$dockingStatus == "GREEN" && incomingArray.length > 0)) && this.$lightsStatus != "YELLOW")
{
this.$removeLights();
this.$lights = system.addVisualEffect("dockLights_yellow", this.$lightsPosition);
this.$lights.orientation = system.mainStation.orientation;
this.$lightsStatus = "YELLOW";
return;
}
// condition GREEN
if(this.$dockingStatus == "GREEN" && incomingArray.length == 0 && this.$lightsStatus != "GREEN")
{
this.$removeLights();
this.$lights = system.addVisualEffect("dockLights_green", this.$lightsPosition);
this.$lights.orientation = system.mainStation.orientation;
this.$lightsStatus = "GREEN";
return;
}
// condition BLUE
if(this.$dockingStatus == "BLUE" && this.$lightsStatus != "BLUE")
{
this.$removeLights();
this.$lights = system.addVisualEffect("dockLights_blue", this.$lightsPosition);
this.$lights.orientation = system.mainStation.orientation;
this.$lightsStatus = "BLUE";
return;
}
}
this.shipDied = this.shipWillEnterWitchspace = this.shipExitedStationAegis = function()
{
this.$lightsTimer.stop();
this.$removeLights();
this.$lightsStatus = "BLUE";
}
this.$removeLights = function()
{
var count = system.allVisualEffects.length;
if(count === 0) { return; }
for (var i=count-1; i>=0; i--)
{
if(system.allVisualEffects[i].dataKey === "dockLights_green" || system.allVisualEffects[i].dataKey === "dockLights_yellow" || system.allVisualEffects[i].dataKey === "dockLights_red" || system.allVisualEffects[i].dataKey === "dockLights_blue")
{ system.allVisualEffects[i].remove(); }
}
} |