Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  


Starsector 0.96a is out! (05/05/23)

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.

Topics - rogerbacon

Pages: [1] 2 3
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.

Modding / ChatGPT understands StarSector's API
« on: March 28, 2023, 05:01:36 PM »

Alex may not have to answer so many questions in the future.

Modding / Help wityh phasor effect please
« on: February 18, 2023, 07:49:40 PM »
Hello all. I've made a phasor effect that when applied to a limited duration beam like the phase lance or similar weapons causes the beam to 'move' from the point of aim off to the left or right up to 10 degrees. So it strafes over the target (and some of it probably misses).
It works by changing the weapon offset when it fires so the beam moves from initial position to the new offset. After it fires I reset the offset so it's ready to fire again.
The problem occurs if the battle ends before the weapons finishes firing (including the cooldown time).  Then the default aim position is offset by whatever it was last time it fired. So, the beam will always miss. My code is below. It was originally based on another mod where they had the beam sweep back and forth, but that's not exactly what I want in mine.
If anyone can see how to make sure the offsets are always reset, regardless of when the battle ends I would appreciate it. Of course if I'm totally doing this the hard way and there is an easier way that would be great too.

Note : ANGLES is an arraylist in the code but it has only one item. It was leftover from the original SCY code that had more than one intem.
package data.scripts.weapons;
import java.lang.Math;
//import com.fs.starfarer.api.combat.BeamAPI;
//import com.fs.starfarer.api.combat.BeamEffectPlugin;
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.util.IntervalUtil;
import org.lazywizard.lazylib.combat.CombatUtils;
//import org.lazywizard.lazylib.VectorUtils;
import java.awt.Color;
import java.util.*;
import org.lazywizard.console.Console;
import org.lwjgl.util.vector.Vector2f;

import com.fs.starfarer.api.Global;
import org.lwjgl.util.vector.ReadableVector2f;
import org.lazywizard.lazylib.FastTrig;
import java.util.Collection;
import com.fs.starfarer.api.combat.WeaponAPI;
import java.util.ArrayList;
import java.util.List;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;

public class phasorEffect implements EveryFrameWeaponEffectPlugin

private float timer=0, randomization=0, perShotRandom = 0;
    private Vector2f muzzle= new Vector2f();
    private boolean  runOnce=false , hasFired=false, setInitialRandom = false;;
    private ArrayList<java.lang.Float> ANGLES = new ArrayList<java.lang.Float>();
private ArrayList<java.lang.Float> originalAngles = new ArrayList<java.lang.Float>();
//public static boolean runOnce=false ;
    public phasorEffect() {
        this.randomization = 0.0f;


    public void advance(float amount, CombatEngineAPI engine, final WeaponAPI weapon)

if (engine.isPaused()) {
        //get the base offsets
// This still runs every frame at start of combat until I fire once
            ANGLES=new ArrayList<java.lang.Float>(weapon.getSpec().getTurretAngleOffsets());

// store original angles
for(int i=0; i<ANGLES.size(); i++){
if (originalAngles.size() == 0){
// Console.showMessage("setting orig angle " + i + " to " + ANGLES.get(i));

            randomization= (float)Math.random()*10;
            } else if(weapon.getSlot().isTurret()){
        //move the offsets while firing
if (!setInitialRandom) {
//Console.showMessage("setting new random at " + timer);
perShotRandom = (float)Math.random()*10 - 5f;
setInitialRandom = true;
//timer = 0;

            for(int i=0; i<ANGLES.size(); i++){
                //float offset=(float)FastTrig.cos(5*(timer+i+randomization))*2;
float offset=(float)FastTrig.cos(5*(perShotRandom+i+randomization))*10;

offset = offset * timer/2f;
java.lang.Float myAngle = (java.lang.Float)ANGLES.get(i);
                weapon.getSpec().getTurretAngleOffsets().set(i, myAngle+offset);
        if(weapon.getChargeLevel()==1 && !hasFired){
            //weapon glow
            Vector2f LOC = new Vector2f(weapon.getLocation());
            Vector2f.add(LOC, muzzle, LOC);
                    new Color(50,100,255,255)
        } else if(hasFired && weapon.getChargeLevel()==0){
timer = 0f;
setInitialRandom = false;
this.randomization = (float)Math.random()*10;
// Reset turret angles for next time
for(int i=0; i<ANGLES.size(); i++){
weapon.getSpec().getTurretAngleOffsets().set(i, originalAngles.get(i));


Bug Reports & Support (modded) / Suddenly all of my fights are retreats
« on: February 05, 2023, 07:54:00 PM »
So this is strange. Suddenly every fight I accept, my ships are being pursued like I elected to run away. Even when I elect to pursue a fleet that is reluctant to fight I'm the one that is set as teh running away fleet. Has anyone else encountered this? Very confusing.

General Discussion / Does the campaign use dynamic ship generation?
« on: December 30, 2022, 05:59:53 PM »
Are the ships we encounter in the campaign put together dynamically (hull + weapons + hull mods) or do they have to exist as a variant already?

Modding / Adding inaccuracy to a beam?
« on: December 29, 2022, 03:54:50 PM »
I'd like a beam that 'rakes' across an area of space where it's aimed at instead of hitting with perfect accuracy. I tried editing the min.max spread in the csv but that's only for projectiles.

My thought now is to get the angle of the beam relative to the firing ship and move it +/- some amount every second. However, it seems all methods in BeamAPI are getters and not setters so I'm not sure how I would, programmatically, move the beams target point.
Any suggestions?

I'm trying to make a weapon that abosrbs flux over time and then , when it fires, does bonus damage equal to the flux it has absorbed.
My code is below. I have a class implementing BeamEffectPlugin and a listener class. The listener is adding teh flux to the battery but when I fire the weapon the check for this.ML.fluxBattery > 0  always fails. It knows what the listener is because if I print some other value like FLUX_PER_SECOND_CHARGE_RATE  from this.ML, it knows what that is.
I hope someone can tell me what I'm doing wrong here.

package data.scripts.weapons;
import java.lang.Math;
import com.fs.starfarer.api.combat.*;
import com.fs.starfarer.api.combat.BeamAPI;
import com.fs.starfarer.api.combat.BeamEffectPlugin;
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.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 java.awt.Color;
import java.util.*;
import org.lwjgl.util.vector.Vector2f;
import static com.fs.starfarer.api.util.Misc.ZERO;

public class PlasmaMaulerEffect implements BeamEffectPlugin
public boolean listenerAttached = false;
public MaulerListenerScript ML = null;
public ShipAPI firer = null;

    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
if (!listenerAttached) {
listenerAttached = true;
this.firer = beam.getSource();
this.ML  = new MaulerListenerScript(this.firer);
if (!beam.getSource().hasListenerOfClass(ML.getClass())) {

if (this.ML == null) {
Console.showMessage("ML is null");
CombatEntityAPI target = beam.getDamageTarget();
if (this.ML.fluxBattery > 0 /* && beam.getBrightness() >= 1f && target instanceof ShipAPI */) {

Console.showMessage("*Flux battery*: " + this.ML.fluxBattery);

// TODO: add damage here
                        // Drain the batteries
this.ML.fluxBattery = 0;


public class MaulerListenerScript implements AdvanceableListener {
private ShipAPI ship;
private FluxTrackerAPI fluxTracker = null;
public float fluxBattery = 0f;
private float time;
public float FLUX_PER_SECOND_CHARGE_RATE = 400f;
private float MAX_BATTERY_CAPACITY = 8000f;

public MaulerListenerScript(ShipAPI ship) {
this.ship = ship;
this.fluxTracker = ship.getFluxTracker();

public void advance(float amount) {
// increment our timer to collect fluxBattery
time += amount;
if (time > 1f)

// move flux into the battery
float amountOfFluxToRemove = FLUX_PER_SECOND_CHARGE_RATE * time;
float currentFlux = fluxTracker.getCurrFlux();
if (amountOfFluxToRemove > currentFlux) {
amountOfFluxToRemove = currentFlux;
this.fluxBattery += amountOfFluxToRemove;
if (this.fluxBattery > MAX_BATTERY_CAPACITY)
this.fluxBattery = MAX_BATTERY_CAPACITY;

//Console.showMessage("Flux battery: " + this.fluxBattery);
//Console.showMessage("Current flux level: " + fluxTracker.getFluxLevel());
time = 0f;


General Discussion / Friendly fire, collisions turned off?
« on: December 22, 2022, 01:18:17 PM »
I don't know if they removed friendly fire and collisions or if I accidentally turned them off but I miss it. Can anyone tell me if this is a setting somewhere? Or if it's modded, the command that disables it so I can search for it in my installed mods.

Modding / Is it possible to modify which proj a weapon fires during combat
« on: December 11, 2022, 06:11:46 AM »
I want to make a weapon that has two modes, call them slug and shotgun. All the differences between them are in the proj class that the weapon fires. Is it possible to bind a hotkey that changes what proj a weapon fires and be able to call it during combat?
I see in the WeaponSpecAPI there is a GetProjectileSpec() but I don't see any setter method.

Modding / How to create a hullmod that provides benefit based on hull size
« on: December 08, 2022, 03:44:44 PM »
I want to create a hull mode that reduces the fuel used by small ships. I assume I do that in applyEffectsAfterShipCreation() like many examples I've seen. However, I need a reference to the shipAPI for the ship the mod is going on, right? How do I get that?
Once I have it I think I can use ship.getMutableStats().getFuelUseMod().modifyFlat(id, -1f); to do what I want.

Thanks in advance for any help.

I read the help file at and my weapon works fine if I use the console to drop it in a campaign. However, it does not show up as a choice when refitting a ship in a mission.  I was under the assumption that all weapons in the game are available when refitting for a mission. Any idea what I've forgotten to do?

[Edit] Never mind. It's showing up now. Not sure what was happening before.

Modding / Weapon damage loss with range. Does it happen? Moddable?
« on: January 15, 2021, 08:16:55 AM »
Do weapons lose damage with range? If not, is it moddable?

I sort of did this but since I'm new to modding stuff here its probably not the best way.
I made an energy torpedo modeled after the Starfleet Battles plasma torpedo. In the csv it lists 1 damage but in tn the script I override OnHit and calculate the range it has traveled since launch and apply the real damage there as a formula.

I assume this would work for any projectile weapon but how would I do something similar for a beam weapon? To keep it simple let's say I want the beam weapon to do one-half damage if the target is beyond one-half of the beam's max range. Any ideas?

Modding / Can a hullmod add weapons to a ship
« on: January 12, 2021, 04:29:02 PM »
Is it possible for a hullmod to add weapons to a ship? I know it can add fighters so I thought a weapon might be possible.

Modding / How to add a hullMod to a ship in a mission (not campaign)
« on: December 29, 2020, 11:59:11 AM »
I'm creating a mission like randomBattle and I want to get each ship and add a hullMod as the ship is added to the player's fleet. How should I do this? I think I'm close but its not quite working. Here's what I've tried so far.

BattleCreationContext batContext = api.getContext();
CampaignFleetAPI playerFleet = batContext.getPlayerFleet();
FleetMemberAPI ship = api.addToFleet(FleetSide.PLAYER, "astral_Elite", FleetMemberType.SHIP, false);
api.addBriefingItem("ship is " + ship.getVariant().getHullMods());

Modding / Vector2f not recognized
« on: December 23, 2020, 09:18:59 AM »
I have a mod I made about 4 years ago and I wanted to update it but I'm getting a "Cannot determine simple type of 'Vector2f'"

I believe I have the right import for the Vector2f class.

[Edit]. Now the error message is different.

Here is my class

Here is the log

The error message says :
Error compiling [data.scripts.weapons.SFB_PlasmaOnHitEffect]
java.lang.RuntimeException: Error compiling [data.scripts.weapons.SFB_PlasmaOnHitEffect]
   at com.fs.starfarer.loading.scripts.ScriptStore$ Source)
   at Source)
Caused by: java.lang.ClassNotFoundException: 1 error(s) while compiling unit "data/scripts/weapons/"
   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)

Pages: [1] 2 3