Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 670 671 [672] 673 674 ... 711

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

Liral

  • Admiral
  • *****
  • Posts: 718
  • Realistic Combat Mod Author
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10065 on: August 13, 2023, 10:53:30 AM »

Is there any way to change the ShotBehaviorSpecAPI of a MissileSpecAPI once it has loaded from its JSON?  I ask because I have noticed that I cannot adjust the firing distance of a DEM missile.  I can see an obfuscated method to do it; also, the method name seems misspelled: setBehavor (and getBehavor) are both missing an 'i' between 'v' and 'o'.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10066 on: August 13, 2023, 10:57:13 AM »

You can change the JSONObject returned by ShotBehaviorSpecAPI.getParams(); that should have an effect but may or may not work across the board, depending.

(Yeah, that looks like it's misspelled. Ah well.)
Logged

Lukas04

  • Captain
  • ****
  • Posts: 372
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10067 on: August 13, 2023, 11:44:12 AM »

Is there any way to stop a weapon from firing while it is in burst?
Im making a shipsystem that will apply to all modules of the ship, but one one modules has the system itself, so i cant rely on the shipsystems "noFiring" for the other modules.

To clarify, im able to stop further firing from weapons, but i cant figure out how to example, stop a Squall from firing the moment i activate the effect, and due to how long those fire id rather find a way to disable their current burst.
Logged
My Mods

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10068 on: August 13, 2023, 12:47:17 PM »

Hmm. When a ship system has noFiring, under the hood it results in:
ship.blockCommandForOneFrame(CommandType.USE_SELECTED_GROUP);
ship.setHoldFireOneFrame(true);

But I don't think that would stop a firing weapon, either. The only thing that comes to mind is WeaponAPI.disable() - I expect that would do it.
Logged

Liral

  • Admiral
  • *****
  • Posts: 718
  • Realistic Combat Mod Author
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10069 on: August 13, 2023, 01:03:28 PM »

You can change the JSONObject returned by ShotBehaviorSpecAPI.getParams(); that should have an effect but may or may not work across the board, depending.

(Yeah, that looks like it's misspelled. Ah well.)

Wow, snappy!  Thanks for the answer.  I wonder how to make it work because the following code works when changing the specs but ends up, somehow, with null values for triggerDistance and preferredMinFireDistance:
Code
final float distance = payloadWeaponSpec.getMaxRange() * 3;
final JSONArray distanceRange = new JSONArray(new float[]{distance, distance});
behaviorSpec.getParams().put("triggerDistance", distanceRange);
behaviorSpec.getParams().put("preferredMinFireDistance", distanceRange);

Lukas04

  • Captain
  • ****
  • Posts: 372
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10070 on: August 13, 2023, 03:35:16 PM »

Hmm. When a ship system has noFiring, under the hood it results in:
ship.blockCommandForOneFrame(CommandType.USE_SELECTED_GROUP);
ship.setHoldFireOneFrame(true);

But I don't think that would stop a firing weapon, either. The only thing that comes to mind is WeaponAPI.disable() - I expect that would do it.

any way to hide the particles and such that come from using the disable method though?
Logged
My Mods

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10071 on: August 13, 2023, 04:01:10 PM »

I don't think so. Yeah, this isn't... ideal. Let me make a note about a possible API addition here.

(You could also ship.setPhased(true) for one frame and set the collision class back to its original value - that might do the trick. Might have some other unintended consequences during that one frame, though, such as confusing missiles that are targeting it etc.)
Logged

rogerbacon

  • Commander
  • ***
  • Posts: 151
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10072 on: August 13, 2023, 05:54:53 PM »

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

Thanks. This worked perfectly.
Logged

Lukas04

  • Captain
  • ****
  • Posts: 372
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10073 on: August 14, 2023, 02:02:06 AM »

I don't think so. Yeah, this isn't... ideal. Let me make a note about a possible API addition here.

(You could also ship.setPhased(true) for one frame and set the collision class back to its original value - that might do the trick. Might have some other unintended consequences during that one frame, though, such as confusing missiles that are targeting it etc.)

The issue here is that its already a phase system so i dont think that would work either haha, basicly making a rightclick phase that can apply to all modules of a ship, and things like squalls continuing to fire on the modules is the crux of the issue.

Il probably just avoid missile mounts on it for now since those tend to have the issue the most.
Logged
My Mods

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10074 on: August 14, 2023, 09:59:46 AM »

Ahh, interesting! Reading the code a little more, if you give the module a version of phase cloak - as a ship system - with an AI of NONE, that should make firing weapons get interrupted when the module is phased. And if the AI is NONE it would not get used otherwise. At least, I think this would work.

The downside being that the module would not be able to have another ship system.
Logged

Mephansteras

  • Commander
  • ***
  • Posts: 102
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10075 on: August 14, 2023, 07:40:02 PM »

How should I handle situations where NPC fleets don't have a commander? Or their commander exists but doesn't have stats?

People are getting crashes with my mod because I'm modifying NAVIGATION_PENALTY_MULT. This is fine most of the time, but if there is nothing to reference for that the game crashes with a null pointer exception.

I'm trying to set things up so my code gracefully handles this situation, and still ends with the NPC fleet getting the bonus correctly.
Code in question
Code
    private static void applyHarmonics(CampaignFleetAPI fleet)
    {
        PersonAPI commander = fleet.getCommander();
        MutableCharacterStatsAPI commanderStats;
        if (commander == null)
        {
            commander = Global.getFactory().createPerson();
            fleet.setCommander(commander);
        }

        if (fleet.isPlayerFleet())
        {
            commanderStats = Global.getSector().getPlayerStats();
        }
        else
        {
            commanderStats = commander.getFleetCommanderStats();
        }

        if (commanderStats == null)
        {
            commander.setStats(new CharacterStats());
        }


        float currentNavPenalty = commanderStats.getDynamic().getStat(Stats.NAVIGATION_PENALTY_MULT).getModifiedValue();

        FleetDataAPI fleetData = fleet.getFleetData();
        MutableFleetStatsAPI fleetStats = fleetData.getFleet().getStats();
        boolean hasHarmonics = fleetStats.hasMod(HARMONIC_ID);
        boolean hasHarmonicMod = false;

        for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
            if (member.getVariant().hasHullMod("stardust_WarpHarmonicResonator"))
            {
                hasHarmonicMod = true;
                break;
            }
        }

        if (hasHarmonics == false && hasHarmonicMod == true)
        {
            commanderStats.getDynamic().getStat(Stats.NAVIGATION_PENALTY_MULT).modifyFlat(HARMONIC_ID,
                    -0.01f * stardust_WarpHarmonicResonator.NAVIGATION_PENALTY_REDUCTION);
            MutableStat fleetChecked = new MutableStat(0.0F);
            fleetStats.addTemporaryModMult(365f, HARMONIC_ID, HARMONIC_DESC, 1f, fleetChecked);
        }
        else if (hasHarmonics == true && hasHarmonicMod == false)
        {
            //commanderStats.getDynamic().getStat(Stats.NAVIGATION_PENALTY_MULT).modifyFlat(HARMONIC_ID,
            //        0.01f * stardust_WarpHarmonicResonator.NAVIGATION_PENALTY_REDUCTION);
            commanderStats.getDynamic().getStat(Stats.NAVIGATION_PENALTY_MULT).unmodify(HARMONIC_ID);
            fleetStats.removeTemporaryMod(HARMONIC_ID);
        }

    }
[close]

The chunk of code at the top is what I have in to handle things, but it still doesn't solve my problem. When it gets down to grabbing the current Nav Penalty, it crashes out on the null pointer because even if I do create a commander and initialize Stats for them.

What do I need to do to get this to work properly?

I could catch the errors so it doesn't crash, but I'd much rather have it put the game into a correct state so NPC fleets also get the intended bonus from this ship being in their fleet.

[update]
I have noticed that
Code
commanderStats = fleet.getCommanderStats();
ends up giving me nulls much less often. Does not help for what to do if nulls show up, though.
« Last Edit: August 14, 2023, 10:34:02 PM by Mephansteras »
Logged

rogerbacon

  • Commander
  • ***
  • Posts: 151
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10076 on: August 14, 2023, 08:49:17 PM »

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?
« Last Edit: August 15, 2023, 05:43:47 AM by rogerbacon »
Logged

Lukas04

  • Captain
  • ****
  • Posts: 372
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10077 on: August 15, 2023, 05:26:54 AM »

Ahh, interesting! Reading the code a little more, if you give the module a version of phase cloak - as a ship system - with an AI of NONE, that should make firing weapons get interrupted when the module is phased. And if the AI is NONE it would not get used otherwise. At least, I think this would work.

The downside being that the module would not be able to have another ship system.

Yeah we are planning to give them different systems so that wont work, we will just avoid letting it have missiles for now and il use the new API feature that you marked down on your notes once thats available someday, thanks for looking in to it!
Logged
My Mods

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10078 on: August 15, 2023, 09:13:44 AM »

How should I handle situations where NPC fleets don't have a commander? Or their commander exists but doesn't have stats?

People are getting crashes with my mod because I'm modifying NAVIGATION_PENALTY_MULT. This is fine most of the time, but if there is nothing to reference for that the game crashes with a null pointer exception.
...

It would help to see the actual error! Looking at internal code, it seems very nearly impossible that you would get a null return value from either fleet.getCommander() or fleet.getCommanderStats(), so something other than what you're describing is probably happening. (It *is* possible that one of the methods might cause an NPE under some specific circumstances, but that's different.)

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?

missile.setEmpResistance(<number of times the missile will ignore being hit by the EMP system and similar>)

Well, not exactly ignore - it'll still take damage - but it will avoid the instant flameout effect.


Yeah we are planning to give them different systems so that wont work, we will just avoid letting it have missiles for now and il use the new API feature that you marked down on your notes once thats available someday, thanks for looking in to it!

*thumbs up* - added WeaponAPI.stopFiring().
Logged

Mephansteras

  • Commander
  • ***
  • Posts: 102
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10079 on: August 15, 2023, 10:09:33 AM »

How should I handle situations where NPC fleets don't have a commander? Or their commander exists but doesn't have stats?

People are getting crashes with my mod because I'm modifying NAVIGATION_PENALTY_MULT. This is fine most of the time, but if there is nothing to reference for that the game crashes with a null pointer exception.
...

It would help to see the actual error! Looking at internal code, it seems very nearly impossible that you would get a null return value from either fleet.getCommander() or fleet.getCommanderStats(), so something other than what you're describing is probably happening. (It *is* possible that one of the methods might cause an NPE under some specific circumstances, but that's different.)

That's good to know. I didn't see any cases where the fleet didn't have a commander, personally, but was told it could happen.

I did get issues with this code:
Code
    PersonAPI commander = fleet.getCommander();
    MutableCharacterStatsAPI commanderStats = commander.getFleetCommanderStats();

Where getting the stats from the fleet's commander, rather than the fleet, would give me nulls when trying to actually access stats. Which I'm guessing just means that I was doing it wrong.

If fleet.getCommanderStats will always get me a correct set that won't end up with null pointers, I should be good. I'll keep an eye out and get you specific errors if I end up with any using that method.
Logged
Pages: 1 ... 670 671 [672] 673 674 ... 711