Scripts/Breakable_HUD_IFF_Scanner.js |
this.name = "Breakable_HUD_IFF_Scanner";
this.author = "capt murphy";
this.copyright = "2011 capt murphy";
this.licence = "CC BY-NC-SA 3.0"; // see http://creativecommons.org/licenses/by-nc-sa/3.0/ for more info.
this.description = "Script to simulate combat damage to the HUD/IFF Scanner.";
this.version = "1.2";
// event handler driven function for functions at startup - awards equipment to existing ship if first run with OXP.
this.startUp = function()
{
this.bis_warning = new SoundSource;
this.bis_warning.sound = "warning.ogg";
if (!missionVariables.bis_scannerstatus)
{
missionVariables.bis_scannerstatus = "OK";
}
this.bis_scannerstatus = missionVariables.bis_scannerstatus;
if (player.ship.equipmentStatus("EQ_BREAKABLE_HUD_IFF_SCANNER") != "EQUIPMENT_OK" && this.bis_scannerstatus == "OK")
{
player.ship.awardEquipment("EQ_BREAKABLE_HUD_IFF_SCANNER");
}
}
// event handler driven function to fit equipment to newly purchased ship.
this.playerBoughtNewShip = function()
{
player.ship.awardEquipment("EQ_BREAKABLE_HUD_IFF_SCANNER");
this.bis_scannerstatus = "OK";
}
// event handler driven function to control actions if equipment damaged in combat.
this.equipmentDamaged = this.equipmentDestroyed = function(equipment)
{
if (this.shipRestore && equipment === "EQ_BREAKABLE_HUD_IFF_SCANNER") {this.bis_scannerstatus = "DAMAGED"; return;}
if (equipment == "EQ_BREAKABLE_HUD_IFF_SCANNER")
{
this.bis_scannerstatus = "DAMAGED";
this.bis_setuptimer();
}
}
// event handler driven function for actions on launching and exiting witchspace.
this.shipLaunchedFromStation = this.shipExitedWitchspace = function()
{
if (player.ship.equipmentStatus("EQ_BREAKABLE_HUD_IFF_SCANNER") == "EQUIPMENT_OK" && this.bis_scannerstatus != "OK")
{
this.bis_resetscanner();
}
if (this.bis_scannerstatus != "OK")
{
this.bis_setuptimer();
}
}
// event handler driven function to stop timer on docking or on player death.
this.shipWillDockWithStation = this.shipDied = function()
{
if (this.bis_updatescannerTimer && this.bis_updatescannerTimer.isRunning)
{
this.bis_updatescannerTimer.stop();
delete this.bis_updatescannerTimer;
player.ship.hudHidden = null;
}
if (this.bis_warningTimer && this.bis_warningTimer.isRunning)
{
this.bis_warningTimer.stop();
delete this.bis_warningTimer;
}
}
// event handler driven function for actions on save game.
this.playerWillSaveGame = function()
{
missionVariables.bis_scannerstatus = this.bis_scannerstatus;
}
// creates timers if not already in existance otherwise restarts existing timers.
this.bis_setuptimer = function()
{
if (!this.bis_updatescannerTimer)
{
this.bis_updatescannerTimer = new Timer(this, this.bis_updatescanner, 0, 0.25);
}
else
{
this.bis_updatescannerTimer.start();
}
if (!this.bis_warningTimer)
{
this.bis_warningTimer = new Timer(this,this.bis_warningsound,0,10);
}
else
{
this.bis_warningTimer.start();
}
}
// called by timer every 0.25 seconds when player is in flight to hide the HUD to simulate HUD/scanner damage.
this.bis_updatescanner = function()
{
if (player.ship.equipmentStatus("EQ_BREAKABLE_HUD_IFF_SCANNER") == "EQUIPMENT_OK") // check to see if something has repaired the scanner on the fly e.g. Thargoid's Repair Bots OXP.
{
this.bis_resetscanner();
return;
}
if (Math.random() < 0.66)
{
player.ship.hudHidden = "True";
}
else
{
player.ship.hudHidden = null;
}
}
// called by timer every 10 seconds when player in flight to give warning noise whilst HUD/Scanner is damaged.
this.bis_warningsound = function()
{
this.bis_warning.play(1);
player.consoleMessage("HUD and IFF Scanner Damaged!", 2);
}
// function to reset the scanner.
this.bis_resetscanner = function()
{
this.bis_scannerstatus = "OK";
if (this.bis_updatescannerTimer && this.bis_updatescannerTimer.isRunning)
{
this.bis_updatescannerTimer.stop();
delete this.bis_updatescannerTimer;
}
player.ship.hudHidden = null;
if (this.bis_warningTimer && this.bis_warningTimer.isRunning)
{
this.bis_warningTimer.stop();
delete this.bis_warningTimer;
}
} |