Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - rogerbacon

Pages: [1] 2 3 ... 8
What determines if a ship shows up for purchase on the regular, military, or black market screens?

Also, I have ship designs in my default_ship_roles.json file. Do I also have to have those specific hull IDs in a blueprint that a fction can make or can ships in the default_ship_Roles.json still show up even of no faction has them listed as known?

General Discussion / Re: Asking ChatGPT things about Starsector
« on: April 25, 2023, 01:22:24 PM »
I posted a thread over in teh modding forum about using ChatGPT for modding with the API. It's good at formulas and boilerplate code but it COMPLETELY makes of methods that are not in the API. After you call it out that there is no such method it will apologize and... make up another method.
I did find it useful for diagnosing a bug I was having. I pasted my code in, gave it the error message and it game me a more human-understandable explanation of the problem.

I've owned the game since near the beginning and I've been launching it every day for the past few months. Why would it ask for the key now? I had a Java update but that's the only thing in common with StarSector that I can think of. Luckily, I had the key.

Is there any way to programmatically change the burst size of a weapon during combat?

How do I add a listener to a projectile?

I want to create a projectile that, if shot down by pd, will spawn an emp arc to the nearest target within range. I've added listeners to ships but I don't see a similar method for projectiles.

you can't add a listener directly to a projectile, but I've got a similar thing that I do this (see below) for.

this method technically has a few pitfalls (particularly if the projectile is spawned using spawnProjectile() without manually calling the onFire for it), but it works well enoughtm for me to not be bothered by it

Thank you. With your help I was able to make what I wanted. Code below.

package data.scripts.weapons;
import com.fs.starfarer.api.combat.*;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.combat.DamagingProjectileAPI;
import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
import com.fs.starfarer.api.combat.OnFireEffectPlugin;
import java.util.Random;
import java.lang.Math;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.combat.*;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.DamageType;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.loading.WeaponSlotAPI;
import com.fs.starfarer.api.combat.GuidedMissileAI;
import com.fs.starfarer.api.util.IntervalUtil;
import org.lazywizard.lazylib.combat.CombatUtils;
import com.fs.starfarer.api.combat.listeners.AdvanceableListener;
import org.lazywizard.lazylib.VectorUtils;
import org.lazywizard.lazylib.MathUtils;
import org.lazywizard.console.Console;
import org.lazywizard.lazylib.CollisionUtils;
import com.fs.starfarer.api.combat.FluxTrackerAPI;
import com.fs.starfarer.api.loading.DamagingExplosionSpec;
import com.fs.starfarer.api.combat.listeners.AdvanceableListener;
// import com.fs.starfarer.api.combat.listeners.DamageDealtModifier;
import java.awt.Color;
import java.util.*;
import org.lwjgl.util.vector.Vector2f;
import static com.fs.starfarer.api.util.Misc.ZERO;

public class SFB_Nuclear_Torpedo_OnFireEffect implements OnFireEffectPlugin {

    public void onFire(final DamagingProjectileAPI projectile, final WeaponAPI weapon, final CombatEngineAPI engine) {

if (weapon.getShip() != null) {

if (!weapon.getShip().hasListenerOfClass(nuclearListener.class)) {
            weapon.getShip().addListener(new nuclearListener(weapon.getShip()));
SFB_Nuclear_Torpedo_OnFireEffect.nuclearListener listener = getFirstListenerOfClass(weapon.getShip(), SFB_Nuclear_Torpedo_OnFireEffect.nuclearListener.class);



public static nuclearListener getFirstListenerOfClass(ShipAPI ship, Class listenerClass) {

        if (!ship.hasListenerOfClass(listenerClass)) {
            return null;
        nuclearListener listener = (nuclearListener)ship.getListeners(listenerClass).get(0);
        return  listener;

public static class nuclearListener implements AdvanceableListener /*, DamageDealtModifier */ {

        protected final ShipAPI ship;
        private final ArrayList<DamagingProjectileAPI> projs = new ArrayList<DamagingProjectileAPI>();
private final ArrayList<DamagingProjectileAPI> deadProjs = new ArrayList<DamagingProjectileAPI>();

private static final Color ARC_FRINGE_COLOR = new Color(85, 60, 205, 225);
private static final Color ARC_CORE_COLOR = new Color(235, 175, 235, 255);
private static final int NUM_ARCS = 3f;

        public nuclearListener(ShipAPI ship) {
            this.ship = ship;

        public void addProj(DamagingProjectileAPI proj) {

public boolean isHarmless(MissileAPI m) {
        return m.isFizzling() || m.isExpired() || m.isFading();

        public void advance(float amount) {

            Iterator<DamagingProjectileAPI> iter = projs.iterator();
while (iter.hasNext()) {
CombatEngineAPI engine = Global.getCombatEngine();
if (engine.isPaused() ) {

DamagingProjectileAPI proj = (DamagingProjectileAPI);

if ( isHarmless((MissileAPI)proj) || proj.didDamage() ) {

if (proj.getHitpoints() > 300 ) {

java.lang.Object missileAI = proj.getAI();
if (missileAI == null ) {

CombatEntityAPI target = ((GuidedMissileAI)missileAI).getTarget();

//CombatEntityAPI target = proj.getDamageTarget(); // wrong. This is what it damaged
if (target == null) {

Vector2f projPos = proj.getLocation();
Vector2f targetPos = target.getLocation();
float distance = MathUtils.getDistanceSquared(projPos, targetPos) ;
if (distance > 250000f) { // range 500 = 250000

// At this point the projectile should have zero hp, not have done damage, and be within range.

SpawnEMP(target, proj);
Console.showMessage("proj in arraylist " + projs.size());
// clear out dead missles. Need a better way.
if (!deadProjs.contains(proj)){


for (DamagingProjectileAPI deadProjectile : deadProjs) {
if (projs.contains(deadProjectile)) {



public void SpawnEMP(CombatEntityAPI target, DamagingProjectileAPI proj) {
//Console.showMessage( proj.getHitpoints() + " hp" + " Boom!");
CombatEngineAPI engine = Global.getCombatEngine();
for (int x = 0 ; x < NUM_ARCS; x++) {
0f, // damage
750f, // emp damage
500f, // range
"shock_repeater_emp_impact", // sound
8f, // thickness
ARC_CORE_COLOR // core color



One difference from yours is that I iterate through the original arraylist instead  of creating a copy inside the advance() method. Isn't creating a copy of the arraylist expensive? Sinec advance runs every frame I'm concerned about performance.

I want to remove the dead projectiles but, like you said, doing so causes an error within the loop. The sources say it should work this way but it gave an error. Anyway, since I don't expect to spam thousands of missiles in a given battle I can live with this. Thanks again.

How do I add a listener to a projectile?

I want to create a projectile that, if shot down by pd, will spawn an emp arc to the nearest target within range. I've added listeners to ships but I don't see a similar method for projectiles.

Is ther eany way in campaign to tell when a ship was built? I.e. The year, month and day in-game when a ship was created? Is there any interaction between game date and ships that I could see as an example?

A couple of things I'd like to do:
I'd like to prevent certain weapons being added before a certain game year.
Have a ship suffer accelerated CR decline if it's older than X years.

Where do I change the color od the damage numbers for Hull and armor? I have difficulty distinguishing between teh green and red. I'd like to change one to yellow.

I wanted to try this mod but it crashes on loading with the following message:

88494 [Thread-3] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.RuntimeException: Error loading [data.scripts.HIVERmodPlugin]
java.lang.RuntimeException: Error loading [data.scripts.HIVERmodPlugin]
at com.fs.starfarer.loading.scripts.ScriptStore$ Source)
at Source)
Caused by: java.lang.ClassNotFoundException: File 'data/scripts/', Line 445, Column 0: Non-abstract class "starship_legends.Util$1" must implement method "public abstract int, java.lang.Object)"
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(
at org.codehaus.janino.JavaSourceClassLoader.findClass(
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Caused by: org.codehaus.commons.compiler.CompileException: File 'data/scripts/', Line 445, Column 0: Non-abstract class "starship_legends.Util$1" must implement method "public abstract int, java.lang.Object)"
at org.codehaus.janino.UnitCompiler.compileError(
at org.codehaus.janino.UnitCompiler.compile2(
at org.codehaus.janino.UnitCompiler.compile2(
at org.codehaus.janino.UnitCompiler.compile2(
at org.codehaus.janino.UnitCompiler.access$200(
at org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(
at org.codehaus.janino.Java$AnonymousClassDeclaration.accept(

It says the problem is in data/scripts/ but i don't even have that file. Very strange.

Mods / Re: [0.9.0a] Fleet Tester 1.0 (2019/02/25)
« on: April 15, 2023, 11:08:17 AM »
Is there a planned update to make this compatible with 0.95.1a?
Does it currently work with 0.95.1a despite being marked in red on the index?

I tested it today and it works perfectly with the current version of the game. It is a great addition to the game.

Modding / Re: [0.95.1a] Particle Engine (4/11/23)
« on: April 13, 2023, 03:51:19 PM »
This is going to be a great addition to the game. I'm going to try it this weekend.

What's the import line look like? I'm writing my classes in Notepad++ and there is no intellisense.

Also, is it possible to atach the emitter to an object in teh game, liek a projectile, to make the particles move with it? What event did you place your code in fro the trail emitter?

Modding / Re: Bounty rewards?
« on: April 09, 2023, 07:31:18 AM »
In my experience the reason for fighting bounties is just for a challenge when you have an uber-fleet. By that point you usually have money in the millions anyway so money is not the draw.

I just had a null reference exception crash. line 97
if(ship.getSystem() != null) {

I don't know how that line could give a null exception unless ship was null but it's passed in as a parameter. I was in dock scrolling through the hull mods.

Modding / Re: Monno’s Mod
« on: April 03, 2023, 07:57:35 AM »
Looks good. Reading the descriptions I really wasn't sure if I world use any of those on my ships. That's a good indication that they are well balanced.

I made a missile with the tag PD_ONLY but it still fires at ships when the enemy ship launches missiles (and also fires at the missiles like I want it to). Is there something else I need to set up so that they only target other missiles?

Pages: [1] 2 3 ... 8