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] 4 5 ... 10
31
How can I get the item that is in the first slot of a player's cargo? Is the cargo ordered? I'm trying to get the item in the first row, far left slot.

32
Mods / Re: [0.9.0a] Fleet Tester 1.0 (2019/02/25)
« on: August 17, 2023, 10:18:39 AM »
So I notice you have a method ForcedSpawn() that is commented out. Is this to force all ships, including freighters and tankers to spawn into the battle? Why was it commented out? Was there a problem with it?

Also, I want to add an option to make a "retreat" style battle. Did you happen to come across how to do that when you were making this mod?

33
Is there a way to make a certain type of missile more resistant to emp effects? Some weapons/effects like the emp system just seem to shut the missile down regardless of its hit points.

Assuming there is no built in way, would this work: Make an everyFrame listener and attach it to the missile and check if it had had its engine turned off before its duration expired and then turn it back on? Would it still have its target?

34
You can use CombatEngineAPI.createFakeWeapon(shipId, weaponId) to create a sabot (or whatever) weapon and use that.

Thanks. This worked perfectly.

35
There is a cool hull mod that creates mines using engine.spawnProjectile(). It passes in null for the weaponAPI parameter and creates a "mineLayer1" projectile. I wanted to change it to create a "sabot" projectile. However, that projectile has an OnHitEffect that has projectile.getWeapon().get.... which results in a null reference exception.
How can I pass an appropriate weaponAPI to spawnProjectile() so that any other script calling getWeapon on the projectile won't be null?

36
CR timers affect every ship, player and enemy alike. (Excluding stations and certain Omega-class ships - those are a special case, and have no CR timer.)

However, there is one additional gotcha here: CR time only runs down if there are enough hostile ships nearby. If you're piloting a cruiser, and that cruiser is the only ship of yours on the field, enemy capital ships will never lose CR.

Thank you. I did notice that sometimes it would say low enemy presence or something like that and CR would not deplete. I don't suppose the formula is listed anywhere as to what constitutes a significant enemy presence.

37
I'm staging a series of computer vs computer fights for testing and I've never noticed the enemy ships start having malfunctions. I even made a player ship with 10 minutes of combat readiness and it ran out while the enemy ships continued to be fine. Does combat readiness decrease only affect player ships?

38
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?

39
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.

40
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.

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

42
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.

Code
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);

listener.addProj(projectile);
}


    }

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) {
            projs.add(proj);
        }

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

        @Override
        public void advance(float amount) {

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

DamagingProjectileAPI proj = (DamagingProjectileAPI)iter.next();

if ( isHarmless((MissileAPI)proj) || proj.didDamage() ) {
//projs.remove(proj);
continue;
}


if (proj.getHitpoints() > 300 ) {
continue;
}


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

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

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


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

// 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)){
deadProjs.add(proj);
}

             
           
            }

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

deadProjs.clear();

        }

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++) {
engine.spawnEmpArcPierceShields(proj.getSource(),
proj.getLocation(),
proj,
target,
DamageType.ENERGY,
0f, // damage
750f, // emp damage
500f, // range
"shock_repeater_emp_impact", // sound
8f, // thickness
ARC_FRINGE_COLOR, // fringe
ARC_CORE_COLOR // core color
);
}

proj.setHitpoints(0f);
}
    }

}

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.

43
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.

44
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.

45
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.

Pages: 1 2 [3] 4 5 ... 10