Well, I tried out what you said, and still no dice.
There is however 2 parts to this script. I understand that more than likely the NPC's and the player versions will have different scripts, for the issues you pointed out. So I am first struggling with an NPC version that would remove subentities as needed when some are shot off. I know I can do it by adding them as subentities of subentities like you said in your first post, but doing it by scripting looks cleaner.
The original code I used comes from Eric and I thought with a bit of tinkering, I could get it to work for NPC's just like his works perfectly.
The original code with the switch case comes from his oxp, and basically in the shipdata.plist of that file you will see that the shipentries do not have a script="heregoesmyscript.js" , but the script reference is only in the subentities that can be shot off. A small exerpt of the shipdata.plist goes like this:
the ship:
Code: Select all
"Griff_Krait_Wealthy_green" =
{
like_ship = "griff_krait_wealthy_template";
roles = "pirate(0.2)";
model = "griff_krait_main_hull.dat";
name = "Griff Krait";
materials =
{
"griff_krait_blue_diffuse.png" =
{
diffuse_map = "griff_krait_green_diffuse.png";
specular_color = ( 0.2, 0.2, 0.2 ); // Applies when specular map is not used (no shaders)
shininess = 15;
illumination_map = { name = "griff_krait_effects_illum.png"; extract_channel = "a"; };
illumination_color = (1.0, 1.0, 1.0);
};
};
shaders =
{
"griff_krait_blue_diffuse.png" =
{
vertex_shader = "griff_krait_generic.vertex";
fragment_shader = "griff_krait_hull_fi.fragment";
textures = ("griff_krait_green_diffuse.png", "griff_krait_effects_illum.png");
uniforms =
{
uColorMap = { type = texture; value = 0; };
uEffectsMap = { type = texture; value = 1; };
uTime = "universalTime";
engine_power = "speedFactor";
nearly_dead = "throwingSparks";
hull_heat_level = "hullHeatLevel";
};
};
};
};
as you can see, no reference to a script file here
however, here is one of the subentities in this case the fuel injectors that can be shot off:
Code: Select all
"griff_krait_chrome_fuel_injectors" =
{
ai_type = "nullAI.plist";
auto_ai = "false";
model = "griff_krait_fuel_injectors.dat";
name = "Krait";
roles = "griff_krait_fuel_injectors";
script = "griff_krait_subent.js";
forward_weapon_type = "WEAPON_NONE";
smooth = "true";
materials =
{
"griff_krait_blue_diffuse.png" =
{
specular_color = ( 0.2, 0.2, 0.2 ); // Applies when specular map is not used (no shaders)
shininess = 15;
illumination_map = { name = "griff_krait_effects_illum.png"; extract_channel = "a"; };
illumination_color = (1.0, 1.0, 1.0);
};
};
max_energy = 40;
shaders =
{
"griff_krait_blue_diffuse.png" =
{
vertex_shader = "griff_krait_enviromap.vertex";
fragment_shader = "griff_krait_chrome_hull_fi.fragment";
textures = ("griff_krait_blue_diffuse.png", "griff_krait_effects_illum.png",
{name = "griff_enviromentmap1.png"; repeat_s = "yes"; repeat_t = "yes";});
uniforms =
{
uColorMap = { type = texture; value = 0; };
uEffectsMap = { type = texture; value = 1; };
uEnvMap = { type = texture; value = 2; };
uTime = "universalTime";
engine_power = "speedFactor";
nearly_dead = "throwingSparks";
hull_heat_level = "hullHeatLevel";
};
};
};
};
Here there is a script file in the shipdata.plist entry.
the complete code of his griff_krait_subent.js is this:
Code: Select all
this.name = "griff_krait_subent";
this.author = "griff";
this.copyright = "� 2008 griff.";
this.version = "1.01";
this.shipDied = function ()
{
switch(this.ship.primaryRole)
{
case "griff_krait_ecm":
{
this.ship.owner.commsMessage("There goes my ecm.");
this.ship.owner.removeEquipment("EQ_ECM");
break;
}
case "griff_krait_extra_eu":
{
// npc have no extra_eu, remove booster instead.
// (Or remove the EQ_SHIELD_ENHANCER)
this.ship.owner.commsMessage("There goes my enery unit.");
this.ship.owner.removeEquipment("EQ_SHIELD_BOOSTER");
break;
}
case "griff_krait_fuel_injectors":
{
this.ship.owner.commsMessage("There goes my fuel injector.");
this.ship.owner.removeEquipment("EQ_FUEL_INJECTION");
break;
}
case "griff_krait_fuel_scoop":
{
this.ship.owner.commsMessage("There goes my fuel scoop.");
this.ship.owner.removeEquipment("EQ_FUEL_SCOOPS");
break;
}
case "griff_krait_laser":
{
this.ship.owner.commsMessage("There goes my laser.");
// no need to remove something as this subent realy contains the laser.
break;
}
default: break
}
};
This works perfectly so I thought, hell, why not add a few lines so I can destroy the subents that are part of other subents, and using your code I tried.
No matter what I put in the case switch, it will do everything, except remove the right subentity.
The shipdata.plist script reference however does not work if I attach it to the ship. It works partially by using it in the shipdata.plist of the subents, which is a different oxp folder in my case.
So if I put it like this:
Code: Select all
this.name = "griff_krait_subent";
this.author = "griff";
this.copyright = "griff.";
this.version = "1.01";
this.shipDied = function ()
{
switch(this.ship.dataKey)
{
case "HPC_CO3_LCBhull":
{
this.ship.owner.commsMessage("SYSFAIL - LCB");
this.ship.owner.removeEquipment("EQ_FUEL_INJECTION");
this.ship.spawn("cargopod", (Math.ceil(Math.random() * 6) - 1));
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.
}
var lcblight = this._findSubEntity("HPC_CO3_LCBlights")
if (lcblight)
{
lcblight.remove();
}
break;
}
default: break
}
};
It will give me the message
release the cargopods
and remove the target ships fuel injectors in this case as a test,
the subent lights however are still present:
I will worry about the scripting for the player versions later.
Code: Select all
"oolite_template_cobra3" =
{
like_ship = "HPCcobramk3_sentinel";
};
And last but not least, I used this code so the default cobra mk 3 do not show up ingame anymore, since I removed it I have still some of Griff's versions flying around, is there another way I can remove them without resorting to the code above ?
Thanks