@ Eric,
Dank U, maar dit is echt wel chinees voor mij.
I can follow the stuff that Cim pointed out, but this is beyond me. However, I got it to work fairly well like this, using the code that Cim posted, and tried to construct my first function on my own:
Code: Select all
this.name = "landing_gear";
this.author = "griff";
this.copyright = "� 2008 griff.";
this.version = "1.01";
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.
}
this.retractGear = function()
{
this.ship.commsMessage("retracted");
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];
}
}
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];
}
}
this.playerStartedAutoPilot = function() //make LDG visible when pressing autopilot key
{
this.ship.commsMessage("Autopilot ON");
this.ship.commsMessage("GEAR DOWN & LOCKED");
this.retractGear();
this.extendGear();
}
this.shipLaunchedFromStation = function(station) //make LDG invisible during startup sequence
{
this.extendGear();
this.tenSecTimer = new Timer(this, this.retractGear,10);
this.ship.commsMessage("GEAR UP");
}
this.playerCancelledAutoPilot = function()
{
this.extendGear();
this.retractGear();
this.ship.commsMessage("Autopilot OFF");
this.ship.commsMessage("GEAR UP");
this.ship.AIState = "LIGHTS_OFF";
}
this.stationWithdrewDockingClearance = function()
{
this.extendGear();
this.retractGear();
}
this.shipWillLaunchFromStation = function(station)
{
this.retractGear();
this.extendGear();
}
this.shipDockedWithStation = function(station)
{
this.retractGear();
this.extendGear();
}
this.shipApproachingPlanetSurface = function(planet)
{
this.retractGear();
this.extendGear();
this.ship.commsMessage("GEAR DOWN & LOCKED");
}
this.shipLeavingPlanetSurface = function(planet)
{
this.extendGear();
this.tenSecTimer = new Timer(this, this.retractGear,10);
this.ship.commsMessage("GEAR UP");
}
Some bits work, some don't, and I am trying to add code, so a ship will extend its gear as well when it is targeting the main station and a certain distance away from it.
a bit like this, but it doesnt work yet:
Code: Select all
if(this.ship.target == system.mainStation && this.ship.position.distanceTo(this.ship.target) < 11000)
{
this.retractGear();
this.extendGear();
}
At the moment these three work as they should:
this.playerStartedAutoPilot = function()
this.shipLaunchedFromStation = function(station) NPC and Player
this.playerCancelledAutoPilot = function()
I would also like to know how to run a function depending on the ai.plist or even AIstate that the ship has loaded, if that is at all possible. This way I could hide/show the guns and close/open gunbay doors according to tis state.
I am trying to get ships that have this AIState to drop their gear, but it also has an influence on the playership, which I would like to avoid.
Code: Select all
if(this.ship.AIState = "GO_TO_STATION")
{
this.ship.commsMessage("debug message: GEAR DOWN & LOCKED");
this.retractGear();
this.extendGear();
}