Scripts/BUS_MegaBat_events.js |
this.name = "BUS_MegaBat_events";
this.author = "Montana05";
this.description = "Event handler for Mega Bat Mark I";
this.version = "0.50";
this.copyright = "2021 Montana05";
this.licence = "CC BY-NC-SA 4.0";
"use strict";
this.shipSpawned = function(ship)
{
this.$BUS_MegaBat_shipType = this.ship.dataKey;
this.$BUS_MegaBat_shipRole = this.ship.primaryRole;
if(this.ship.hasRole("escape-capsule"))
{
var crewName = expandDescription("[nom]");
var crewDescription = "a crew member of an evacuated ship";
var crewRole = "hunter"; // not perfect but somewhere in the middle
var crewRank = "Pilot";
var bhgRank = "Hunter"; // middle rank
var crewRace = expandDescription("[BUS_MegaBat_GalCop_races_scientific]"); // add a race to the crew members
var crewBounty = 0;
var crewInsurance = this.$getRndInteger(90, 450);
// based on an crew of 1 to 2 person
this.$BUS_MegaBat_crew_ranks_array =
["Gunner", "Co-Pilot", "Pilot", "Commander"];
crewRank =
$BUS_MegaBat_crew_ranks_array[Math.floor(Math.random() * $BUS_MegaBat_crew_ranks_array.length)];
// ranks for Bounty Hunter Guild taken from Random Hits OXP, all credits to LittleBear
this.$BUS_MegaBat_bhg_ranks_array =
["Outsider", "Recruit", "Vigilante", "Bailiff", "Deputy", "Tracker", "Hunter", "Sheriff", "Provost", "Marshal", "Enforcer", "Executioner", "Judge"];
bhgRank =
$BUS_MegaBat_bhg_ranks_array[Math.floor(Math.random() * $BUS_MegaBat_bhg_ranks_array.length)];
switch(this.$BUS_MegaBat_shipType)
{
case "BUS_MegaBat_escape_capsule_std":
crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
crewDescription = "a ship crew member";
crewInsurance = crewInsurance;
crewRole = "hunter";
break;
case "BUS_MegaBat_escape_capsule_MT":
crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
crewDescription = "a MT Sec ship crew member";
crewInsurance = (crewInsurance * 1.20); // MT Sec got better insurance conditions
crewRole = "hunter";
break;
case "BUS_MegaBat_escape_capsule_bhg":
crewName = ("the " + crewRace + " " + bhgRank + " " + expandDescription("[nom]"));
crewDescription = "a member of the Bounty Hunter Guild";
crewInsurance = (crewInsurance * 1.10); // BHG got better insurance conditions
crewRole = "hunter";
break;
case "BUS_MegaBat_escape_capsule_pirate":
crewName = ("the " + crewRace + " " + expandDescription("[BUS_MegaBat_pirate_nicknames]") + expandDescription("[nom]"));
crewDescription = "a " + expandDescription("[BUS_MegaBat_criminals]") + "wanted by GalCop police";
crewRole = "pirate";
crewBounty = crewInsurance + (15 * system.government); // stable governments pay extra bonus
crewInsurance = 0;
break;
case "BUS_MegaBat_escape_capsule_MT_pirate":
crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
crewDescription = "a rouge MT Sec ship crew member";
crewBounty = (crewInsurance * 1.20) + (15 * system.government); // stable governments pay extra bonus
crewInsurance = 0;
crewRole = "pirate";
break;
case "BUS_MegaBat_escape_capsule_bhg_pirate":
crewName = ("the " + crewRace + " " + bhgRank + " " + expandDescription("[nom]"));
crewDescription = "a rouge member of the Bounty Hunter Guild";
crewBounty = (crewInsurance * 1.10) + (15 * system.government); // stable governments pay extra bonus
crewInsurance = 0;
crewRole = "pirate";
break;
default:
break;
};
this.ship.setCrew
(
{
name: crewName,
short_description: crewDescription,
role: crewRole,
species: crewRace,
insurance: crewInsurance,
bounty: crewBounty
}
);
// removes individual roles
this.ship.primaryRole = "escape-capsule";
}
else
{
var cargoSpace = this.ship.cargoSpaceCapacity;
var cargoLoad = this.ship.cargoSpaceUsed;
var cargoLeft = cargoSpace - cargoLoad;
// removes individual roles of the ships, this roles will only be called from other OXP's
// adds some cargo to all ships
switch(this.$BUS_MegaBat_shipRole)
{
case "BUS_MegaBat_01":
case "BUS_MegaBat_MT":
this.ship.primaryRole = "escort-medium";
break;
case "BUS_MegaBat_02":
case "BUS_MegaBat_bhg":
case "BUS_MegaBat_bhg_team_01":
this.ship.primaryRole = "hunter-medium";
break;
case "BUS_MegaBat_pirate":
this.ship.primaryRole = "pirate-medium-fighter";
break;
default:
break;
};
if(cargoLeft >= 3)
{
for(var i = this.$getRndInteger(1, 3) - 1 ; i >= 0 ; --i)
{
this.ship.adjustCargo(this.$BUS_MegaBat_space_jockeyCargo(), 1);
};
};
};
};
this.shipDied = function(whom, why)
{
if(this.ship.hasRole("escape-capsule"))
{
return;
}
else
{
// neutral inits first
var podType = "escape-capsule";
var podCount = 1;
var criminalCrew = "N";
var cargoType = "";
var cargoPod = "cargopod";
var cargoCount = 0;
if(this.ship.bounty > 7 || this.$BUS_MegaBat_shipType == "BUS_MegaBat_pirate")
{
criminalCrew = "Y";
};
switch(this.$BUS_MegaBat_shipType)
{
case "BUS_MegaBat_01":
case "BUS_MegaBat_02":
case "BUS_MegaBat_pirate":
if(criminalCrew == "Y")
{
podType = "BUS_MegaBat_escape_capsule_pirate";
}
else
{
podType = "BUS_MegaBat_escape_capsule_std";
};
break;
case "BUS_MegaBat_MT":
if(criminalCrew == "Y")
{
podType = "BUS_MegaBat_escape_capsule_MT_pirate";
}
else
{
podType = "BUS_MegaBat_escape_capsule_MT";
};
break;
case "BUS_MegaBat_bhg":
case "BUS_MegaBat_bhg_team_01":
if(criminalCrew == "Y")
{
podType = "BUS_MegaBat_escape_capsule_bhg_pirate";
}
else
{
podType = "BUS_MegaBat_escape_capsule_bhg";
};
break;
default:
break;
};
// emergency crafts
system.addShips(podType, podCount, this.ship.position);
// cargopods
if(this.ship.cargoSpaceUsed > 0)
{
for(var i = this.ship.cargoList.length - 1 ; i >= 0 ; --i)
{
cargoType = this.ship.cargoList[i].commodity;
cargoPod = ("BUS_MegaBat_cargo_" + cargoType);
cargoCount = this.ship.cargoList[i].quantity;
if(cargoType == "firearms" || cargoType == "food" || cargoType == "liquor_wines" || cargoType == "witchfire_whiskey")
{
system.addShips(cargoPod, cargoCount, this.ship.position);
};
};
};
};
};
// food, booze and guns, what else you need for your trip ? :P
this.$BUS_MegaBat_space_jockeyCargo = function()
{
this.$BUS_MegaBat_space_jockey_cargo_array = ["firearms", "food", "liquor_wines"];
if(worldScripts["witchfire-populator"]) // Darkside Moonshine Distillery OXP
{
this.$BUS_MegaBat_space_jockey_cargo_array.push("witchfire_whiskey");
};
var space_jockey_cargo =
$BUS_MegaBat_space_jockey_cargo_array[Math.floor(Math.random() * $BUS_MegaBat_space_jockey_cargo_array.length)];
return (space_jockey_cargo);
};
this.$getRndInteger = function(min, max)
{
return Math.floor(Math.random() * (max - min + 1) ) + min;
};
|