Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.98a is out! (03/27/25)

Pages: 1 ... 768 769 [770] 771 772 ... 774

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

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25929
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11535 on: April 28, 2025, 09:04:47 PM »

* I have some hard times making price behave as I'd like to in case of my custom commodity, since I can't use RMB on it as well, would it be possible to make special item have commodity drag custom quantities functionality?

Just checked and they already do!

* I'm considering adding custom ability to open a dialog to "convert my commodity" as plan B, is there anything I can look for to get an idea how to (in a dialog, or in some other way) choose a number in a flexible way (an input someone could type a value in or a slider)? Instead of having many dialog options with hardcoded values like "convert 1 commodity", "convert 10 commodities", "convert 100 commodities", etc.)?

Yeah, there's a (pretty old) slider functionality in dialogs. See: OptionPanelAPI.addSelector().

Could also do something with a fully custom UI for a dialog but that's *substantially* more involved.
Logged

Timid

  • Admiral
  • *****
  • Posts: 654
  • Personal Text
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11536 on: April 29, 2025, 01:07:05 AM »

How is ShipAPI.getShield().getUnfoldTime() calculated?

We did some testing and thought it was based on the ship's area, ship's collision radius, but even when the shield arc and type are the same. They seem to differ a lot. Do you know the formula, Alex?

Mycophobia

  • Commander
  • ***
  • Posts: 111
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11537 on: April 29, 2025, 01:15:41 AM »

Hi alex, am wondering if there is a way to check/modify collision damage for damagetaken/dealt modifier listeners?

I noticed setting param to null will make the listener work in modifying collision damage, but I assume just using it without further conditions could have other unforseen effects?

Thanks!
Logged

volt

  • Lieutenant
  • **
  • Posts: 72
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11538 on: April 29, 2025, 03:55:29 AM »

oh feeling stupid right now, you are right, I thought it was because it of special item type, but it is just my mouse LMB misbehaving :facepalm:

1. If a mod is adding a custom commodity, what needs to be done in BaseModPlugin.afterGameSave to be able load the save with the mod disabled?
long question with my findings

1. I'm trying to make my mod easy to remove from game (set a flag which will be checked in `ModPlugin.beforeGameSave` and remove custom commodity if set, so it can be loaded without the mod), looking at other mods how they do it, but I can't find it so far.
How I go about it? Currently I'm looking at `Global.getSector().getEconomy().getCommoditySpec`, `getAllLocations()` and `getAllFactions()` with assumption that I have to iterate over them and find markets/fleets with the commodity to remove, am I on the right track?
[edit]
Actually, one of the saves I can't load, doesn't seem to have that commodity anywhere on market or fleet, it's like there is some meta data saved somewhere but not sure what, where, and how to remove it.
I'm gettting "Commodity with id  not found" from `com.fs.starfarer.campaign.econ.CommodityOnMarket.readResolve()` when trying to load game after disabling the mod.
Added removal but it still errors:
Code
Global.getSector().getAllLocations().forEach->.getAllEntities().forEach->.getMarket().getSubmarketsCopy().forEach->.getCargo().removeCommodity(id, quantity);
Not sure why I didn't do that earlier, but I went through save's xml file to figure out what's still left, I have added "make my illegal commodities legal before saving" with `faction.makeCommodityLegal` which removed some of occurrences of my commodity ID in the save. Still remaining (yet, while I'm trying to figure it out) in the xml:
 /CampaignEngine/uiData/abilitySlots/slots/AbilitySlot-array[1]/AbilitySlot[9]/abilityId
 /CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/submarketTradeData/e[32]/PlayerTradeDataForSubmarket/pS/s/CIStack/d
 /CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/submarketTradeData/e[33]/PlayerTradeDataForSubmarket/pS/s/CIStack/d
 /CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/submarketTradeData/e[35]/PlayerTradeDataForSubmarket/pS/s/CIStack/d
 /CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/submarketTradeData/e[36]/PlayerTradeDataForSubmarket/pS/s/CIStack/d
 /CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/profitabilityData/dataBought/e/st
 /CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/profitabilityData/dataBought/e/CommodityData/commodityId

I have added this:
 SharedData.getData().getPlayerActivityTracker().getSubmarketTradeData().get(submarket).getRecentPlayerBought().removeCommodity(id, bought.getCommodityQuantity(id));
SharedData.getData().getPlayerActivityTracker().getSubmarketTradeData().get(submarket).getRecentPlayerSold()  .removeCommodity(id, sold  .getCommodityQuantity(id));

Now I'm left with the below:
 /CampaignEngine/uiData/abilitySlots/slots/AbilitySlot-array[1]/AbilitySlot[9]/abilityId
 /CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/profitabilityData/dataBought/e/st
 /CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/profitabilityData/dataBought/e/CommodityData/commodityId
error
ERROR com.fs.starfarer.campaign.save.CampaignGameManager  - Failed calling method
---- Debugging information ----
message             : Failed calling method
cause-exception     : java.lang.RuntimeException
cause-message       : Commodity with id cpr_commodity not found
method              : com.fs.starfarer.campaign.econ.MarketDemand.readResolve()
class               : com.fs.starfarer.campaign.econ.MarketDemand
required-type       : com.fs.starfarer.campaign.econ.MarketDemand
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number         : 3978
class[1]            : com.fs.starfarer.campaign.econ.MarketDemandData
class[2]            : com.fs.starfarer.campaign.econ.Market
class[3]            : com.fs.starfarer.campaign.CampaignPlanet
class[4]            : java.util.ArrayList
converter-type[1]   : com.thoughtworks.xstream.converters.collections.CollectionConverter
class[5]            : com.fs.util.container.repo.ObjectRepository
class[6]            : com.fs.starfarer.campaign.StarSystem
class[7]            : com.fs.starfarer.campaign.CircularOrbit
class[8]            : com.fs.starfarer.rpg.Person
class[9]            : com.fs.starfarer.api.impl.campaign.events.OfficerManagerEvent$AvailableOfficer
class[10]           : com.fs.starfarer.api.impl.campaign.events.OfficerManagerEvent
class[11]           : java.util.LinkedHashMap
converter-type[2]   : com.thoughtworks.xstream.converters.collections.MapConverter
class[12]           : com.fs.starfarer.campaign.rules.Memory
class[13]           : com.fs.starfarer.campaign.CommDirectoryEntry
class[14]           : com.fs.starfarer.campaign.CommDirectory
class[15]           : com.fs.starfarer.campaign.econ.reach.ReachEconomy
class[16]           : com.fs.starfarer.campaign.econ.reach.ReachEconomyStepper
class[17]           : com.fs.starfarer.campaign.econ.Economy
class[18]           : com.fs.starfarer.campaign.StarSystem$UpdateFromHyperspaceLocation
class[19]           : com.fs.starfarer.campaign.BaseLocation$LocationToken
class[20]           : com.fs.starfarer.campaign.Hyperspace
class[21]           : com.fs.starfarer.campaign.CampaignEngine
converter-type[3]   : com.fs.starfarer.campaign.save.public
[close]
To access it I tried SharedData.getData().getPlayerActivityTracker().getProfitabilityData(), but not sure how to get to the `dataBought`, it's a private variable so I cannot extend `PlayerTradeProfitabilityData` and alias it in `configureXStream`, it would need to not be private, or that class needs to have something like `getDataBought() -> dataBought` or `deleteBoughtDataFor(String commodityId) -> dataBought.remove(commodityId)` method on it. Is there any other way removing mod commodity from it?

Another progress:
 PlayerTradeProfitabilityData profitabilityData = SharedData.getData().getPlayerActivityTracker().getProfitabilityData();
 profitabilityData.getBoughtDataFor(id).setQuantity(0);
 profitabilityData.advance(365); //  A year, arbitrarily chosen number > 1 (because it wasn't working with 1 :) )

and with above in the save file I see only two entries left for now:
 /CampaignEngine/uiData/abilitySlots/slots/AbilitySlot-array[1]/AbilitySlot[9]/abilityId
 /CampaignEngine/memory/d/e[49]/st
which seems to be safe in save :) as I was able to load the game with mod disabled. Probably I will hit more edge cases once I spend more time testing but for now it works?...
[close]
Once I know a little better what I'm doing, I may create a thread to summarise deleting custom commodities in `beforeGameSave`, assuming there is no simpler way and no one wrote it yet (I couldn't find it).



2. I did add custom loot scripts as well, and I thought removing before save and adding on loading and after saving should be enough, but I'm getting error "com.thoughtworks.xstream.mapper.CannotResolveClassException" I suppose it is because I'm adding script with `permaRegister=true` which creates a listener, but I can't seem to remove it. I'm pretty sure I'm doing something silly I just don't know what yet.
Code
/* ModPlugin.onGameLoad && ModPlugin.afterGameSave */
Global.getSector().addScript(new LootScript(true));

/* ModPlugin.beforeGameSave */
Global.getSector().removeScriptsOfClass(LootScript.class);

/* tried adding the following (because of `permaRegister=true`) but it didn't help: */

Global.getSector().getListenerManager().removeListenerOfClass(LootScript.class);

Global.getSector().getListenerManager().getListeners(LootScript.class); /* this doesn't return anything but the following `getAllListeners` finds it: */
Global.getSector().getAllListeners().forEach(listener -> {
    if(listener.getClass() != LootScript.class) return;

    log.info("Removing LootScript listener: " + listener.getClass().getName());
    Global.getSector().getListenerManager().removeListener(listener);
});

Global.getSector().getAllListeners().forEach(listener -> {
    if(listener.getClass() != RescueCrewLootScript.class) return;
    log.info("YU still here?!");
});


public class LootScript extends BaseCampaignEventListener implements EveryFrameScript {
    @Override
    public void reportEncounterLootGenerated(FleetEncounterContextPlugin plugin, CargoAPI loot) {
        /* Add mod commodity. */
    }
    @Override
    public void advance(float arg0) {}
    @Override
    public boolean isDone() {return false;}
    @Override
    public boolean runWhilePaused() {return false;}
« Last Edit: May 01, 2025, 11:21:26 AM by volt »
Logged

alaricdragon

  • Captain
  • ****
  • Posts: 256
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11539 on: April 29, 2025, 12:30:22 PM »

hello again everyone. I have a confusion I would like to request help on rectifying.
so, for reasons, I want to add S-mods to a fleet after fleet creation. and it seems to add the S-mods fine. but when I save the game, and reload it, the S-mods are always missing.
Code
for (FleetMemberAPI member : members) {
   member.getVariant().addPermaMod("fluxcoil",true);
}
thanks again for the help everyone has given me in the past. it is remembered.
Logged

UltimateAutist

  • Ensign
  • *
  • Posts: 4
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11540 on: April 29, 2025, 09:44:46 PM »

Hey does anyone know if there's a way to make wormholes usable by other fleets? I've been looking but I can't find any info about if its possible, let alone a mod that adds the feature. I know the official blog said something about it, just wanna know if someones DONE it.
Logged

Gopsky

  • Ensign
  • *
  • Posts: 32
    • View Profile
    • My German YouTube Channel
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11541 on: April 30, 2025, 06:59:15 AM »

I'm looking for the thread where you as a modder can report that you have updated your mod to the latest version, but I can't find it anywhere

Can someone please help me?
Thanks in advance

SirHartley

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1027
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11542 on: April 30, 2025, 08:01:03 AM »

I'm looking for the thread where you as a modder can report that you have updated your mod to the latest version, but I can't find it anywhere

Can someone please help me?
Thanks in advance
Hey, that was retired - I'm going through the mods every now and then and checking manually like we usually do. You can also DM me the thread link to fast-track it :)
Logged

Sorrydough

  • Ensign
  • *
  • Posts: 33
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11543 on: April 30, 2025, 09:06:22 AM »

Yes I tried that, but it doesn't work because it uses the engine style data from engine index 0 for all the engines. Like, I can't mix engines on the campaign map.
All the rest just copy whatever the first one does. This is also an issue that's commonly encountered by people who want to mix engine colors.

Ah - in this case, you could reorder the engines in the .ship file, no?

Well... that would cause all the engines to be invisible on the campaign map, rather than just the auxiliary ones...
I think we would need a change on your end for the campaign engines to use the style appropriate for the individual engine, rather than only using the primary style for all engines. That way we (modders) can mix engine styles and have them appear correctly on the campaign map.

EDIT: Just to be clear, my issue is that I've designed a bunch of ships that have engines on the front. This is part of how I balanced them, with the expectation that a defender can slow them down by disabling some of their engines from the frontal profile. So I need a way to hide these front engines from the campaign map, and I can't do it by mixing engine styles due to it only rendering one engine style on the campaign map.
« Last Edit: April 30, 2025, 03:38:18 PM by Sorrydough »
Logged

Reshy

  • Admiral
  • *****
  • Posts: 1269
  • White
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11544 on: April 30, 2025, 09:09:37 PM »

How do you get crew capacity to persist after marking a ship as automated?  I know there's a way (similar to how you can make a ship avoid the automated penalty with a tag) but I'm unsure how to do so with the crew capacity.
Logged

StarSiesta

  • Ensign
  • *
  • Posts: 14
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11545 on: May 01, 2025, 09:05:05 AM »

How do I get custom planet/moon names to not populate in the vanilla star systems? I butchered the vanilla file and eliminated 90% of the names featured there with my own, but I left the ones specified for certain Core systems like Zagan and Samarra. When I generate a new sector I'll occasionally see my custom names in these systems. Not sure how to avoid this.
Logged

Vexlia Artemiss

  • Ensign
  • *
  • Posts: 6
  • Zeta Level AI core
    • View Profile
    • Bluesky Page
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11546 on: May 02, 2025, 12:59:09 AM »

I working with rules.cvs and was wondering. Is active rules updating mid game was removed? I know guide ("You merely adopted...") is not so new so maybe it was changed. Or problem is what I use mod rules.cvs?

I did test with devmode on and off, but no visible results (even errors don't change if i change option ids). It's updates after game relaunch, so i know problem is not in code.
Logged
Working on faction mod in background. You can see snipets on my Bluesky.

Check my flag pack: Terra Invicta Inspired Flag Pack.

Killer of Fate

  • Admiral
  • *****
  • Posts: 3393
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11547 on: May 02, 2025, 01:26:00 AM »

How do I get custom planet/moon names to not populate in the vanilla star systems? I butchered the vanilla file and eliminated 90% of the names featured there with my own, but I left the ones specified for certain Core systems like Zagan and Samarra. When I generate a new sector I'll occasionally see my custom names in these systems. Not sure how to avoid this.
if you did not use the replace function, then all you did was just add your names

to make it more probably to assign certain names, you need to add frequency 100000 or something to them. But obviously if you run out of names, default ones will be assigned. Unless you add TRUE under the reusable column
Logged
years ago, I was Mairaathaneese
Now, I'm a naturalised Kazeroneese

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25929
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11548 on: May 02, 2025, 08:25:12 AM »

How is ShipAPI.getShield().getUnfoldTime() calculated?

We did some testing and thought it was based on the ship's area, ship's collision radius, but even when the shield arc and type are the same. They seem to differ a lot. Do you know the formula, Alex?

Code
public float getUnfoldTime(float testArc) {
MutableShipStatsAPI stats = ship.getMutableStats();
// unfold rate of, say, 100 pixels/second
float unfoldTime = (2f * radius * (float) Math.PI) * testArc/360f / (100f * stats.getShieldUnfoldRateMult().getModifiedValue());

if (type == ShieldType.FRONT) {
unfoldTime /= 2f;
}
return unfoldTime;
}

Hi alex, am wondering if there is a way to check/modify collision damage for damagetaken/dealt modifier listeners?

I noticed setting param to null will make the listener work in modifying collision damage, but I assume just using it without further conditions could have other unforseen effects?

Thanks!

I'm... actually not sure. Does that even get reported? If it does, then I don't see why not.

I'm not sure what you mean by setting param to null - it's just a local variable in the method, no? Setting it to null will have absolutely no impact outside the method.


1. If a mod is adding a custom commodity, what needs to be done in BaseModPlugin.afterGameSave to be able load the save with the mod disabled?

Hmm, so thos is near-impossible on a fundamental level. Imagine another mod has a CargoAPI in a member variable in a random script somewhere and that CargoAPI has your commodity. How are you ever going to find that? Heck, I couldn't swear that vanilla won't do that under certain circumstances; it *might*. With vanilla you could theoretically track down every single case where it might do this and handle them individually. When other mods enter the picture, that becomes impossible.

Also, I think each market has a reference to all the possible commodities, and the economy might as well; I'm not sure if the economy keeps some cached data or w/e that might reference these. It just seems... very problematic to do.

hello again everyone. I have a confusion I would like to request help on rectifying.
so, for reasons, I want to add S-mods to a fleet after fleet creation. and it seems to add the S-mods fine. but when I save the game, and reload it, the S-mods are always missing.
Code
for (FleetMemberAPI member : members) {
   member.getVariant().addPermaMod("fluxcoil",true);
}
thanks again for the help everyone has given me in the past. it is remembered.


Take a look at DefaultFleetInflater. Basically: you need to make sure the variant is not a stock variant, and if it is, to clone it, set the member's variant to the cloned copy, set the variant source to VariantSource.REFIT, etc. What's happening right now, I think, is the game sees it as a "stock" variant and so just saves it in the savefile as "tempest_Attack" or whatever, without any actual data, which is done to reduce file size.

Well... that would cause all the engines to be invisible on the campaign map, rather than just the auxiliary ones...
I think we would need a change on your end for the campaign engines to use the style appropriate for the individual engine, rather than only using the primary style for all engines. That way we (modders) can mix engine styles and have them appear correctly on the campaign map.

EDIT: Just to be clear, my issue is that I've designed a bunch of ships that have engines on the front. This is part of how I balanced them, with the expectation that a defender can slow them down by disabling some of their engines from the frontal profile. So I need a way to hide these front engines from the campaign map, and I can't do it by mixing engine styles due to it only rendering one engine style on the campaign map.

Ah, crap - sorry, I wasn't thinking it through. I'll keep it in mind as a thing to maybe add.

The only other thing that comes to mind is modifying the ship hull spec data when combat starts and then again when it ends, but that gets pretty complicated because I'm pretty sure this is not actually exposed in the API.


How do you get crew capacity to persist after marking a ship as automated?  I know there's a way (similar to how you can make a ship avoid the automated penalty with a tag) but I'm unsure how to do so with the crew capacity.

The Automated hullmod multiplies it by zero, so I don't think you can if you keep the hullmod. You can however mark a ship as automated by adding an "automated" tag to it in ship_data.csv, which would leave you free to implement your own version of Automated which might not do that.


How do I get custom planet/moon names to not populate in the vanilla star systems? I butchered the vanilla file and eliminated 90% of the names featured there with my own, but I left the ones specified for certain Core systems like Zagan and Samarra. When I generate a new sector I'll occasionally see my custom names in these systems. Not sure how to avoid this.

You could remove the StarSystemGenerator.addOrbitingEntities() calls from those files, which are the ones that add a few random planets to these systems.
Logged

Chozo

  • Ensign
  • *
  • Posts: 36
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #11549 on: May 02, 2025, 10:28:56 PM »

Have a question on how skills are handled on the backend, since it impacts a bug I am trying to track down.

Some background: Fleet Size by DP changes the fleet limit from being based on ship count to being based on DP.  Since the game's default logic for fleet size isn't exposed in the API, FSDP uses a hidden skill (tagged npc_only and then assigned to the player when the game is loaded) to check the player's current fleet size and apply/remove penalties as needed.  The level 1 portion of the skill handles supply use penalties, while level 2 handles the burn penalties.

Substance Abuse has logic that triggers at the start of each in-game day, which handles the various housekeeping and modifiers for that mod: this logic eventually calls FleetMember.updateStats(), which then calls applyFleetwideToStats().  For some reason, however, this seems to trigger level 1 (but not level 2?) of the FSDP skill even when the player is on the campaign map, which causes stuttering issues when the two are used together.  A sample trace is included in the spoiler tag below:

Spoiler
[close]

For giggles and grins I created a test player character with all skills to see if any of those were triggered along with the FSDP skill, but they do not appear to be triggered.  I've looked at the various skill files for vanilla skills and I'm not sure why the FSDP skill is triggering, and why only the first level of the skill.  I've also removed the npc_only tag on the FSDP skill to check if that might be the source of some odd interaction, but the issue still occurs without it.

So, the following questions:

1. For skills that adjust logistics/base stats (e.g. Crew Training, Makeshift Equipment), how does the game determine when to call the associated logic to calculate and apply the modifiers?
2. Is there any way to force the game (or at least make it recognize) to only run the logic for a given skill when the player is not on the campaign map?  I am thinking of adding a check to see if the game is paused/in a menu, but that feels extremely kludgy and I don't see that sort of logic in the vanilla skill implementations.
« Last Edit: May 02, 2025, 10:36:09 PM by Chozo »
Logged
Pages: 1 ... 768 769 [770] 771 772 ... 774