Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 553 554 [555] 556 557 ... 711

Author Topic: Misc modding questions that are too minor to warrant their own thread  (Read 1730849 times)

styrud

  • Ensign
  • *
  • Posts: 6
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8310 on: December 25, 2021, 10:21:30 AM »

Hmm - that almost sounds like the class defined in that file is not named NeutTractorbeamEffect? It'd help to see the full source of the file it's complaining about.

Here's the code from the java file.
Spoiler
//by Deathfly
package data.scripts.weapons;

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 static data.scripts.util.AdvForce.applyMomentum;
import java.awt.Color;
import org.lwjgl.util.vector.Vector2f;

public class NeutTractorbeamEffect implements BeamEffectPlugin {

    private float coreAlpha = 0;
    private Color coreColor;

    public NeutTractorbeamEffect() {

    }

    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam) {
        if (engine.isPaused()) {
            return;
        }
        CombatEntityAPI target = beam.getDamageTarget();
        if (target != null && beam.didDamageThisFrame()) {
            target.setMass(target.getMass() + 1000);
            applyMomentum(target, beam.getTo(), Vector2f.sub(beam.getTo(), beam.getFrom(), null), -100, false);
            target.setMass(target.getMass() - 1000);
            coreAlpha = coreAlpha < 1 ? coreAlpha + 0.1f : 1f;
           
        } else {
            coreAlpha = coreAlpha > 0 ? coreAlpha - 0.1f : 0f;
        }
        coreAlpha = coreAlpha < 0 ? 0:coreAlpha;
        coreAlpha = coreAlpha > 1 ? 1:coreAlpha;
        coreColor = new Color((int) (255 * coreAlpha), (int) (255 * coreAlpha), (int) (255 * coreAlpha));
        beam.setCoreColor(coreColor);
    }
}
[close]
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24151
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8311 on: December 25, 2021, 10:32:52 AM »

Is it in the data/scripts/weapons folder?

Also, I'd try changing:
private float coreAlpha = 0;
To:
private float coreAlpha = 0f;

Janino (the 3rd party java compiler used to compile loose scripts like this) can be really picky about this sort of thing.
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1727
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8312 on: December 25, 2021, 10:34:12 AM »

Is there a way to retrieve an instance of a constellation's label entity without being provided a SectorMapAPI? The only way to get constellation labels seems to be via SectorMapAPI.getConstellationLabelEntity(), but that doesn't seem to be possible in any context when you'd want to use the new VisualPanelAPI.showMapMarker.

Also, stop working and get back to Christmas, Alex!  :P

It seems to be the NeutTractorbeamEffect script or something related to it.
The error is saying it can't find that script at all. My guess would be you referenced it incorrectly in another file.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24151
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8313 on: December 25, 2021, 10:45:41 AM »

Is there a way to retrieve an instance of a constellation's label entity without being provided a SectorMapAPI? The only way to get constellation labels seems to be via SectorMapAPI.getConstellationLabelEntity(), but that doesn't seem to be possible in any context when you'd want to use the new VisualPanelAPI.showMapMarker.

After a quick check: those are created when the map is created, so they're not permanent entities - so, no.

Also, stop working and get back to Christmas, Alex!  :P

Aye aye :)
Logged

styrud

  • Ensign
  • *
  • Posts: 6
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8314 on: December 25, 2021, 10:50:59 AM »

Is it in the data/scripts/weapons folder?

Also, I'd try changing:
private float coreAlpha = 0;
To:
private float coreAlpha = 0f;
Yeah, the file is in src/data/scripts/weapons.
Changing the value to 0f didn't do anything and the error looks identical to the previous one.
Logged

Yunru

  • Admiral
  • *****
  • Posts: 1560
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8315 on: December 25, 2021, 11:11:22 AM »

Janino (the 3rd party java compiler used to compile loose scripts like this) can be really picky about this sort of thing.
Oh Janino, I once had it crash because it was trying (and failing) to convert a float... into a float.

Sundog

  • Admiral
  • *****
  • Posts: 1727
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8316 on: December 25, 2021, 11:17:59 AM »

Is there a way to retrieve an instance of a constellation's label entity without being provided a SectorMapAPI? The only way to get constellation labels seems to be via SectorMapAPI.getConstellationLabelEntity(), but that doesn't seem to be possible in any context when you'd want to use the new VisualPanelAPI.showMapMarker.

After a quick check: those are created when the map is created, so they're not permanent entities - so, no.
Ah, gotcha. Thanks!

Histidine

  • Admiral
  • *****
  • Posts: 4690
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8317 on: December 25, 2021, 05:47:32 PM »

Is it in the data/scripts/weapons folder?

Also, I'd try changing:
private float coreAlpha = 0;
To:
private float coreAlpha = 0f;
Yeah, the file is in src/data/scripts/weapons.
Changing the value to 0f didn't do anything and the error looks identical to the previous one.
Delete the contents of starsector.log, start the game and run it till it crashes, then post the log.

IIRC if the game fails to load the class (then crashes later because it can't find the said class), it'll write an error earlier in the log.


Hmm, but before that check if the mod has the data.scripts.util.AdvForce class, since the tractor beam class is importing a method from it.
Logged

styrud

  • Ensign
  • *
  • Posts: 6
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8318 on: December 25, 2021, 07:59:49 PM »

I've cleared the log and got myself a fresh crash. The new log is linked here since it was too big to post or attach. https://mega.nz/file/Xk4QhZYA#y_gC8Yo7cmHrql7zm3XgrM5jVojUivDU3IF3jsIP3IY
I have a java file called AdvForce in the src/data/scrpts/util folder. I post the contents below.
Spoiler
package data.scripts.util;

import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import org.lazywizard.lazylib.VectorUtils;
import org.lwjgl.util.vector.Vector2f;

public class AdvForce {

    /**
     * Apply momentum to an object.
     *
     * Momentum is multiplied by 100 to avoid requiring ridiculous momentum
     * amounts.
     *
     * @param entity The {@link CombatEntityAPI} to apply the momentum to.
     * @param direction The directional vector of the momentum (this will
     * automatically be normalized).
     * @param pointOfImpact Where the momentum should apply to.
     * @param momentum How much momentum to apply. Unit is how much it takes to
     * modify a 100 weight object's velocity by 1 su/sec.
     */
    public static void applyMomentum(CombatEntityAPI entity, Vector2f pointOfImpact, Vector2f direction, float momentum, boolean elasticCollision) {
        if(entity==null){
            return;
        }
        // Filter out forces without a direction
        if (direction.lengthSquared() == 0) {
            return;
        }
        // Avoid divide-by-zero errors...
        float mass = Math.max(1f, entity.getMass());
        // We should not move stations, right?
        if (entity instanceof ShipAPI) {
            ShipAPI ship = (ShipAPI) entity;
            if (ship.isStation() || (ship.isStationModule() && ship.getParentStation().isStation())) {
                return;
            }
            if (ship.isStationModule() && ship.isShipWithModules()) {
                entity = ship.getParentStation();
                mass = Math.max(1f, ship.getMassWithModules());
            }
        }
        // Momentum is far too weak otherwise
        momentum *= 100f;
        // Doing some vector calculate
        Vector2f BPtoMC = Vector2f.sub(entity.getLocation(), pointOfImpact, null);
        Vector2f forceV = new Vector2f();
        direction.normalise(forceV);
        forceV.scale(momentum);
        // get force vector
        BPtoMC.normalise(BPtoMC);
        // calculate acceleration
        BPtoMC.scale(Vector2f.dot(forceV, BPtoMC) / mass);
        if (elasticCollision) {
            // Apply velocity change
            Vector2f.add(BPtoMC, entity.getVelocity(), entity.getVelocity());
        } else {
            // Apply velocity change
            direction = new Vector2f(forceV);
            direction.scale(1 / mass);
            Vector2f.add(direction, entity.getVelocity(), entity.getVelocity());
        }
        // calculate moment change
        float angularAcc = VectorUtils.getCrossProduct(forceV, BPtoMC) / (0.5f * mass * entity.getCollisionRadius() * entity.getCollisionRadius());
        angularAcc = (float) Math.toDegrees(angularAcc);
        // Apply angular velocity change
        if (elasticCollision) {
            entity.setAngularVelocity(entity.getAngularVelocity() + angularAcc);
        } else {
            entity.setAngularVelocity(entity.getAngularVelocity() - angularAcc);
        }
    }
}
[close]
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4690
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8319 on: December 25, 2021, 08:38:18 PM »

Hmmm, log indicates the script is loading fine, only for it to not be found later...

At this point it's probably easier to upload the whole mod and I can see what's going wrong when I can. (I have a couple of suspicions, but need to look at the folder to be sure)
Logged

styrud

  • Ensign
  • *
  • Posts: 6
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8320 on: December 25, 2021, 08:54:17 PM »

Here's the mod. Hope you can figure something out.
https://mega.nz/file/7lwATZiL#VJR54FgBIU6a7KsNuMTZZmoxORPhZnZbgjblAM18Jj4
Logged

Timid

  • Admiral
  • *****
  • Posts: 640
  • Personal Text
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8322 on: December 26, 2021, 03:06:23 AM »

Is there a way to just prevent hullmod from being applied on modules without having the module require a built-in hullmod to block this out?

Like ship.getParentStation() would work, but this seems to be null regardless of module status in the refit screen...

Histidine

  • Admiral
  • *****
  • Posts: 4690
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8323 on: December 26, 2021, 05:10:49 PM »

Here's the mod. Hope you can figure something out.
https://mega.nz/file/7lwATZiL#VJR54FgBIU6a7KsNuMTZZmoxORPhZnZbgjblAM18Jj4
So I looked at it and the issue was what I suspected:

Janino (the game's runtime compiler for Java scripts) only works on scripts in data/scripts and a couple of other directories. Files in src/ need to be compiled using an IDE (which is also recommended for other reasons if you're going to be doing any extensive scripting); you can see how to do that here.

Anyway I fixed the mod by moving the files in src/data/scripts to data/scripts. After doing this I moved one of the copied-over files from data/shipsystem to data/shipsystems. It loads correctly, at least to the point of getting into the campaign and adding a Styrud ship to the player fleet.
Logged

styrud

  • Ensign
  • *
  • Posts: 6
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8324 on: December 26, 2021, 11:37:28 PM »

Thanks! That's seems to have fixed it.
Logged
Pages: 1 ... 553 554 [555] 556 557 ... 711