Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Pages: 1 ... 428 429 [430] 431 432 ... 706

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

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6435 on: May 20, 2020, 11:01:24 PM »

So I could use this to add my own map of tokens as a separate generator class that could then be accounted for when using the Misc method to replace rules tokens? (which could then be used on the spreadsheet strings?) That would be the use case I would think I would need.

Correct!

I tried this out. Turns out that the problem is that when you reload a save it no longer saves the replacements and they show up as variables. Maybe I am doing something wrong, but I am adding the generator to rules on a new game. I tried to do it onApplicationLoad() to avoid the save problem, but it throws an error when I do so. Any advice?

*EDIT* Don't spend time on this unless you feel the need. I think I got this solved already.

*EDIT 2* Solved. Thanks!
« Last Edit: May 20, 2020, 11:56:03 PM by Morrokain »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6436 on: May 21, 2020, 08:33:28 AM »

Ah - per the comment in the chunk of code I pasted a few posts earlier: you need to do it in onGameLoad(), since they are not saved.
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6437 on: May 21, 2020, 01:42:54 PM »

Ah - per the comment in the chunk of code I pasted a few posts earlier: you need to do it in onGameLoad(), since they are not saved.

Ha I have no idea why my brain saw that and thought it was onNewGame()...  ::)

Made that change and it works like a charm now! Thanks for the catch.
-----------------------------

Ok next question: If I wanted to make a script to iterate over npcs at a market comm board, when is the best point to do this dynamically? When the player first docks at a market? Or maybe when the comm board is opened?

What I'm attempting is to use the logic I created to allow gender-based post names. (ie Lord/Lady of Commerce, Priest/Priestess of Commodities, etc)
Since npcs will change after invasions, etc, I can't just do this once so I instead have to make it dynamic. I also want to limit how many npcs I am iterating over at a time so keeping it to "as the player would see this" seems to be the best solution. I'm fairly sure the only time you can see post names is when actually docking at the market. You can't view them while simply being in the system, iirc.

*EDIT*
And unrelated:

Is:

Code
                index = (int) ((Math.random() * (1 + optionsList.size())) - 1);

a "true-er" random than?:

Code
                index = (int) (Math.random() * (optionsList.size()));
« Last Edit: May 21, 2020, 02:04:47 PM by Morrokain »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6438 on: May 21, 2020, 03:44:03 PM »

Ok next question: If I wanted to make a script to iterate over npcs at a market comm board, when is the best point to do this dynamically? When the player first docks at a market? Or maybe when the comm board is opened?

What I'm attempting is to use the logic I created to allow gender-based post names. (ie Lord/Lady of Commerce, Priest/Priestess of Commodities, etc)
Since npcs will change after invasions, etc, I can't just do this once so I instead have to make it dynamic. I also want to limit how many npcs I am iterating over at a time so keeping it to "as the player would see this" seems to be the best solution. I'm fairly sure the only time you can see post names is when actually docking at the market. You can't view them while simply being in the system, iirc.

The time to do it would be when the NPCs are created, no? Since if the NPCs change you have to redo it once. So if there's any post-invasion hook you'd want to do it there. Otherwise, you could do it when the player opens the colony, yeah, but that risks it being out of sync if *something* refers to the NPCs when you're not docked at the colony. For example, a piece of intel might talk about a specific NPC at a market and mention their rank or post.

*EDIT*
And unrelated:

Is:

Code
                index = (int) ((Math.random() * (1 + optionsList.size())) - 1);

a "true-er" random than?:

Code
                index = (int) (Math.random() * (optionsList.size()));

Well, the first one will frequently produce -1 as the result, so... :)

The second one should be fine, but you could also do:

Misc.random.nextInt(optionsList.size());

And not worry about it. Misc.random is a static instance of Random that the game uses for general purposes whenever that's needed. (Often, though, it'll instantiate a Random with a specific seed, when repeatable behavior over save/load cycles is needed...)
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6439 on: May 21, 2020, 04:57:15 PM »

The time to do it would be when the NPCs are created, no? Since if the NPCs change you have to redo it once. So if there's any post-invasion hook you'd want to do it there. Otherwise, you could do it when the player opens the colony, yeah, but that risks it being out of sync if *something* refers to the NPCs when you're not docked at the colony. For example, a piece of intel might talk about a specific NPC at a market and mention their rank or post.

Ideally, yes, I just wasn't sure how easy that would be compared to using a standard docking rule or something to run the script. The intel part is a small setback though I didn't think of that. I have no clue about whether a post invasion hook is possible I'll have to ask Histidine.

Otherwise, would the correct way of doing this (initially) be to iterate over all markets at the start of a new game, say, afterEconomyLoad() or something? Is there a way to know when an NPC is created? Like a way of setting up a listener or something? (I don't think I've done this before).

Quote
Well, the first one will frequently produce -1 as the result, so... :)

The second one should be fine, but you could also do:

Misc.random.nextInt(optionsList.size());

And not worry about it. Misc.random is a static instance of Random that the game uses for general purposes whenever that's needed. (Often, though, it'll instantiate a Random with a specific seed, when repeatable behavior over save/load cycles is needed...)

*facepalm* yeah I see that now lol. And the random the game uses would be ideal, so I will change it to that. The repeatable behavior part is nice because then players can't save scum (in the case of some instances of this) to get the result they want.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6440 on: May 21, 2020, 05:49:28 PM »

Ideally, yes, I just wasn't sure how easy that would be compared to using a standard docking rule or something to run the script. The intel part is a small setback though I didn't think of that. I have no clue about whether a post invasion hook is possible I'll have to ask Histidine.

Otherwise, would the correct way of doing this (initially) be to iterate over all markets at the start of a new game, say, afterEconomyLoad() or something? Is there a way to know when an NPC is created? Like a way of setting up a listener or something? (I don't think I've done this before).

There's no way to know. You can look in CoreLifecyclePluginImpl to see when vanilla does it but that's no guarantee regarding when mods might do it. It could literally happen at any time.

*facepalm* yeah I see that now lol. And the random the game uses would be ideal, so I will change it to that. The repeatable behavior part is nice because then players can't save scum (in the case of some instances of this) to get the result they want.

(Ah, please re-read what I said more carefully. Misc.random does not produce consistent save/load behavior.)
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6441 on: May 21, 2020, 05:59:36 PM »

There's no way to know. You can look in CoreLifecyclePluginImpl to see when vanilla does it but that's no guarantee regarding when mods might do it. It could literally happen at any time.
Yeah that was my thought as well. For my specific implementation, this wouldn't likely be a problem... but considering the intel caveat it would probably be hard to do this globally for all modders. Oh well, maybe I can expand upon that later.

Quote
(Ah, please re-read what I said more carefully. Misc.random does not produce consistent save/load behavior.)

Oh so the game sometimes uses a random with a seed to do that, but Misc.random does not? Is that what you were saying? Sorry if it's not clicking.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6442 on: May 21, 2020, 06:06:29 PM »

Oh so the game sometimes uses a random with a seed to do that, but Misc.random does not? Is that what you were saying? Sorry if it's not clicking.

Right, yeah, that's what I meant.
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6443 on: May 22, 2020, 12:28:07 PM »

*Solved* Can anyone help getting this file to load correctly? The log shows the issue.

Code:
Code
            JSONArray StringData = Global.getSettings().getMergedSpreadsheetDataForMod("id", FILE, "fleetdialogue_morro");
            for(int i = 0; i < StringData.length(); i++) {
                JSONObject row = StringData.getJSONObject(i);
                if(row.getString("id")!=null){
                    // Set up dialogue response map. Response category keys are hardcoded and called in the various get methods implemented below.
                    // Also checks for missing or empty dialogue responses as a safeguard.
                    if (row.getString("commodityRequestDescription") != null && !row.getString("commodityRequestDescription").isEmpty()) {
                        DIALOGUE_RESPONSES.put("commodityRequestDescription", row.getString("commodityRequestDescription"));
                    }
                    if (row.getString("commoditySupplyRequestDescription") != null && !row.getString("commoditySupplyRequestDescription").isEmpty()) {
                        DIALOGUE_RESPONSES.put("commoditySupplyRequestDescription", row.getString("commoditySupplyRequestDescription"));
                    }
                    // Add nested map to the faction map under the faction id.
                    FACTION_DIALOGUE.put(row.getString("id"), DIALOGUE_RESPONSES);
                }
            }

            // This is to test that the information is being loaded correctly.
            String defaultCommodityRequestDescription = FACTION_DIALOGUE.get("default").get("commodityRequestDescription").toString();
            String defaultCommoditySupplyRequestDescription = FACTION_DIALOGUE.get("default").get("commoditySupplyRequestDescription").toString();
            String hegCommodityRequestDescription = FACTION_DIALOGUE.get("hegemony").get("commodityRequestDescription").toString();
            String hegCommoditySupplyRequestDescription = FACTION_DIALOGUE.get("hegemony").get("commoditySupplyRequestDescription").toString();

            LOG.error("Contents of dialogue map for default: " + defaultCommodityRequestDescription + " " + defaultCommoditySupplyRequestDescription);
            LOG.error("Contents of dialogue map for hegemony: " + hegCommodityRequestDescription + " " + hegCommoditySupplyRequestDescription);

File Contents:
id,commodityRequestDescription,commoditySupplyRequestDescription,
default,"After exchanging a few pleasantries, you inform the $personRank that you could use some assistance. The weight of your influence, if any, with $hisOrHer faction is behind the request, as is the military strength of each of your respective forces...","You should see this under default.",
hegemony,"$lordOrLady...$priestOrPriestess...$sorcererOrSorceress","Test",

Log on application start:
11915 [Thread-4] ERROR factions.FDialogue_factionTextLoader  - Contents of dialogue map for default: $lordOrLady...$priestOrPriestess...$sorcererOrSorceress Test
11915 [Thread-4] ERROR factions.FDialogue_factionTextLoader  - Contents of dialogue map for hegemony: $lordOrLady...$priestOrPriestess...$sorcererOrSorceress Test

*EDIT*

Nvm, I figured it out. I needed to create the map for the responses each iteration of the loop rather than using a global static map. It reads the file correctly now.

(New code)

Code
            for(int i = 0; i < StringData.length(); i++) {
                JSONObject row = StringData.getJSONObject(i);
                Map<String, String> responses = new HashMap<>();
                responses.clear();
                if(row.getString("id")!=null){
                    // Set up dialogue response map. Response category keys are hardcoded and called in the various get methods implemented below.
                    // Also checks for missing or empty dialogue responses as a safeguard.
                    if (row.getString("commodityRequestDescription") != null && !row.getString("commodityRequestDescription").isEmpty()) {
                        responses.put("commodityRequestDescription", row.getString("commodityRequestDescription"));
                    }
                    if (row.getString("commoditySupplyRequestDescription") != null && !row.getString("commoditySupplyRequestDescription").isEmpty()) {
                        responses.put("commoditySupplyRequestDescription", row.getString("commoditySupplyRequestDescription"));
                    }
                    // Add nested map to the faction map under the faction id.
                    FACTION_DIALOGUE.put(row.getString("id"), responses);
                }
            }
« Last Edit: May 22, 2020, 02:25:54 PM by Morrokain »
Logged

ctuncks

  • Commander
  • ***
  • Posts: 115
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6444 on: May 23, 2020, 07:16:27 PM »

Want to try a bit of weapon modding, but have some questions before I really get stuck in.

Does setting a weapon's rarity above 1.0 have any affect to it's commonality?

Is there any issue with have a duplicate weapon with the same display name, but different ID?

Is there a way to set weapon frequency similar to hull frequency in the faction file?
   If so, do weapons otherwise default to a frequency of 1.0? (100%)
      
Logged

Üstad

  • Commander
  • ***
  • Posts: 131
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6445 on: May 26, 2020, 03:41:00 AM »

I try to make certain industry produce more commodities but after I make changes in .java file, no effects seems to happen at all. Any way to implement the changes?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6446 on: May 26, 2020, 08:47:38 AM »

Does setting a weapon's rarity above 1.0 have any affect to it's commonality?

Sorry for the delay - it should make it more common in drops, but rarity only affects drops from salvage etc, not how often it's used by ships.

Is there any issue with have a duplicate weapon with the same display name, but different ID?

That should be fine.

Is there a way to set weapon frequency similar to hull frequency in the faction file?
   If so, do weapons otherwise default to a frequency of 1.0? (100%)

There isn't, no - aside from setting "tier" higher or lower; higher-tier weapons are less common.


I try to make certain industry produce more commodities but after I make changes in .java file, no effects seems to happen at all. Any way to implement the changes?

Are you changing the source in starfarer.api.zip? That's just provided for reference and isn't directly used by the game. You'll need to put your changes in a separate file in your mod, and probably compile them etc.
Logged

Nia Tahl

  • Admiral
  • *****
  • Posts: 790
  • AI in disguise
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6447 on: May 26, 2020, 10:39:12 AM »

So I've been doing some fiddling with some spawned projectiles and it seems that while the api comments say that modifiers for range and such values are pulled from the source weapon, they are actually pulled from the ship passed as damage source which is proving to be inconvenient as I'd like to spawn a projectile with a variable damage source (as it spawns from another ship) without that affecting the projectile properties.

Am I correct in my observations and is there another way of spawning a projectile like that from another ship without it immediately colliding with said ship?
Logged
My mods: Tahlan Shipworks - ScalarTech Solutions - Trailer Moments
It's all in the presentation

Üstad

  • Commander
  • ***
  • Posts: 131
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6448 on: May 26, 2020, 11:20:36 AM »

Quote
Are you changing the source in starfarer.api.zip? That's just provided for reference and isn't directly used by the game. You'll need to put your changes in a separate file in your mod, and probably compile them etc.
I'm modding a mod called better colonies for my taste. It's in "src.zip\src\com\fs\starfarer\api\impl\campaign\econ\impl"
« Last Edit: May 26, 2020, 04:31:01 PM by Üstad »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6449 on: May 26, 2020, 11:49:23 AM »

Looks like that mod also provides the source for reference. But when the game runs, it's using the compiled code from the jar. In that case, changing that code wouldn't do anything, you'd need to recompile it and replace the jar.
Logged
Pages: 1 ... 428 429 [430] 431 432 ... 706