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 ... 374 375 [376] 377 378 ... 706

Author Topic: Misc modding questions that are too minor to warrant their own thread  (Read 1699734 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 #5625 on: November 09, 2019, 02:25:16 AM »

Does this need to link to a settings entry, mod plugin or a rule to run every frame? Or do I just need to include this in the correct jar for implementation? Thank you for any help.

Something like;

if (!Global.getSector().hasScript(CheckCommissionForPortraitLocks.class)) {
    Global.getSector().addScript(new CheckCommissionForPortraitLocks());
}

Somewhere in ModPlugin; say in onNewGameAfterEconomyLoad().

Not sure if my script isn't working or not running. It certainly isn't performing the intended behavior though. Can I leave all but the params portion of execute() null for a rule command?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5626 on: November 09, 2019, 07:26:28 AM »

The answer depends on the rule command - and you can look at the rule command's code to see if it uses a particular parameter or not, and whether it checks for it being null.

One quick way of making sure your script is running is to add something like:
if (true) {
    throw new RuntimeException("Yep, it's running");
}

Or some such... or you could send some output to the log and tail the log; that'd be a bit less extreme :)
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 #5627 on: November 09, 2019, 11:53:51 AM »

The answer depends on the rule command - and you can look at the rule command's code to see if it uses a particular parameter or not, and whether it checks for it being null.

One quick way of making sure your script is running is to add something like:
if (true) {
    throw new RuntimeException("Yep, it's running");
}

Or some such... or you could send some output to the log and tail the log; that'd be a bit less extreme :)

The script is running in general. I have confirmed that. It throws the exception before I even get out of the campaign load if I change the trigger to be "just not having a commission".

I have narrowed it down between last night and today to:

Code

boolean bool = Global.getSector().getPlayerPerson().getMemory().getBoolean("$FactionOnlyPortraitsEnabled")


Doesn't work. If I have a boolean in memory such as $player.FactionOnlyPortraitsEnabled set to true, how do I pull that into the script?

I know how to do it in a rule when I have access to Map<String, MemoryAPI> memoryMap from the rule itself.

*edit* I've also tried Global.getSector().getPlayerPerson().getMemory().getBoolean("$player.FactionOnlyPortraitsEnabled").

Similarly through the same control where it just checks for having a commission or not (so I know for sure it is running but won't throw an exception):
Code

Global.getSector().getPlayerPerson().getMemory().set("$FactionOnlyPortraitsEnabled", false, 0);

Also doesn't seem to populate any variables into memory.
« Last Edit: November 09, 2019, 12:05:49 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 #5628 on: November 09, 2019, 12:20:38 PM »

1) Use getMemoryWithoutUpdate() - getMemory() runs a bunch of code to populate the memory with 0-second expiring, temporary values that you don't need here. Generally like 99% of the time you want getMemoryWithoutUpdate(), not getMemory().

2) The last parameter to the .set method is the expiration; pass in -1 for no expiration. Right now it looks like you're passing in 0 which causes the value to expire immediately. The expiration value is in campaign days.
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 #5629 on: November 09, 2019, 12:37:59 PM »

1) Use getMemoryWithoutUpdate() - getMemory() runs a bunch of code to populate the memory with 0-second expiring, temporary values that you don't need here. Generally like 99% of the time you want getMemoryWithoutUpdate(), not getMemory().

2) The last parameter to the .set method is the expiration; pass in -1 for no expiration. Right now it looks like you're passing in 0 which causes the value to expire immediately. The expiration value is in campaign days.

Thanks I changed it to getMemoryWithoutUpdate().

Here is the full script now:

Code
package archeus.campaign.everyframescripts;

import com.fs.starfarer.api.EveryFrameScript;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.util.IntervalUtil;
import com.fs.starfarer.api.util.Misc;
import archeus.rulecmd.SetPlayerPortraits;

import java.util.ArrayList;
import java.util.List;

public class CheckCommissionForPortraitLocks implements EveryFrameScript {
private IntervalUtil tracker = new IntervalUtil(0.05f, 0.1f);

public CheckCommissionForPortraitLocks() {
//Global.getSector().getPlayerPerson().getMemoryWithoutUpdate().getBoolean("$FactionOnlyPortraitsEnabled") &&
if (Misc.getCommissionFactionId() == null) {
resetPlayerPortraits();
}
}

public void advance(float amount) {
float days = Global.getSector().getClock().convertToDays(amount);
tracker.advance(days);


if (tracker.intervalElapsed()) {
if (Global.getSector().getPlayerPerson().getMemoryWithoutUpdate().getBoolean("$FactionOnlyPortraitsEnabled") && Misc.getCommissionFactionId() == null) {
resetPlayerPortraits();
}
}
}

public void resetPlayerPortraits() {
SetPlayerPortraits portraits = new SetPlayerPortraits();

List<Misc.Token> params = new ArrayList<Misc.Token>();
Misc.Token token = new Misc.Token("all", null);
params.add(0, token);
portraits.execute(null, null, params, null);

Global.getSector().getPlayerPerson().getMemoryWithoutUpdate().set("$FactionOnlyPortraitsEnabled", false, -1);

//throw new RuntimeException("Yep, it's running");
}

public boolean isDone() {
return true;
}

public boolean runWhilePaused() {
return false;
}
}

Unfortunately, even when I annul my commission it doesn't populate anything into memory. When I add the memory check and the runtime exception that have been commented out, the runtime exception never fires because it never finds the boolean in memory. Even though I've confirmed its there:

Spoiler

[close]
Logged

creature

  • Captain
  • ****
  • Posts: 400
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5630 on: November 09, 2019, 03:39:03 PM »

Is there a way I can make a ship retreat via code? Like if they reach a certain CR or Hull point value, I could override their existing order?
Logged

Salv

  • Lieutenant
  • **
  • Posts: 56
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5631 on: November 10, 2019, 05:29:12 AM »

Is flux generation from engaging wings modifiable or is it harcoded? I'm wondering if I could make a fast carrier that gets the zero flux speed bonus even with the engage order on. I couldn't find any reference to this upkeep in the api.
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5632 on: November 10, 2019, 08:28:24 AM »

@Morrokain: Are you certain your script is being run? I'm not certain exactly how it functions, but I'm pretty sure returning true for isDone() tells the engine that it's not necessary to run your script anymore.

Is there a way I can make a ship retreat via code? Like if they reach a certain CR or Hull point value, I could override their existing order?
There sure is:
Code: java
            boolean retreatDirectly = true;
            ship.setRetreating(true, retreatDirectly);

Is flux generation from engaging wings modifiable or is it harcoded? I'm wondering if I could make a fast carrier that gets the zero flux speed bonus even with the engage order on. I couldn't find any reference to this upkeep in the api.
I don't see anything for that either, but it might be possible to get the desired behavior by adjusting stats.getZeroFluxMinimumFluxLevel()

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5633 on: November 10, 2019, 10:00:13 AM »

@Morrokain: Are you certain your script is being run? I'm not certain exactly how it functions, but I'm pretty sure returning true for isDone() tells the engine that it's not necessary to run your script anymore.

Oh, I missed that, but, yeah, the script as-ise would get removed either immediately or after running for one frame.

Is flux generation from engaging wings modifiable or is it harcoded? I'm wondering if I could make a fast carrier that gets the zero flux speed bonus even with the engage order on. I couldn't find any reference to this upkeep in the api.
I don't see anything for that either, but it might be possible to get the desired behavior by adjusting stats.getZeroFluxMinimumFluxLevel()

It's actually set to a (Helmsmanship.ZERO_FLUX_LEVEL * 0.01) fraction of the ship's max flux, plus triple the dissipation rate. So setting the getZeroFluxMinimumFluxLevel to something reliably above that would do the job, yeah.
Logged

connortron7

  • Captain
  • ****
  • Posts: 439
  • "God has cursed me for my hubris" - brian gilbert
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5634 on: November 10, 2019, 10:07:22 AM »

Where can i find what determines a star systems location?

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5635 on: November 10, 2019, 10:25:14 AM »

data/campaign/starmap.json

Alternatively, you can do:
system.getLocation().set(x, y);
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 #5636 on: November 10, 2019, 11:01:27 AM »

@Morrokain: Are you certain your script is being run? I'm not certain exactly how it functions, but I'm pretty sure returning true for isDone() tells the engine that it's not necessary to run your script anymore.

Oh, I missed that, but, yeah, the script as-ise would get removed either immediately or after running for one frame.

Oh! Ok got it. Can I just remove that whole portion? Or should I return false?
Logged

connortron7

  • Captain
  • ****
  • Posts: 439
  • "God has cursed me for my hubris" - brian gilbert
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5637 on: November 10, 2019, 11:01:56 AM »

data/campaign/starmap.json

Alternatively, you can do:
system.getLocation().set(x, y);

cool thanks! so would i be able to just slap it in my mod and type in my custom system or would there be another step?

Salv

  • Lieutenant
  • **
  • Posts: 56
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5638 on: November 10, 2019, 11:42:14 AM »

It's actually set to a (Helmsmanship.ZERO_FLUX_LEVEL * 0.01) fraction of the ship's max flux, plus triple the dissipation rate. So setting the getZeroFluxMinimumFluxLevel to something reliably above that would do the job, yeah.

I considered doing something like this, but I suppose it would also affect shields and weapons when fighters are regrouped. Is there a particular flag or something I could use that checks whether the carrier has the engage order on? Maybe I could try making an EveryFrame script that applies and unapplies a getZeroFluxMinimumFluxLevel modifier.

Edit: One more thing. The upkeep you mentioned is per wing or constant regardless of the number of wings on the ship?
« Last Edit: November 10, 2019, 11:51:03 AM by Salv »
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 #5639 on: November 10, 2019, 12:01:06 PM »

I set the isDone() return to false, but still no luck actually populating anything to memory. The RuntimeException does fire if I take away the memory check (like before) but if I comment that out and just leave the portion that is supposed to attach a variable to the player's memory it never shows up.

I even directly referenced TutorialMissionEvent and set the PersonAPI to protected like it is there.

Are there any examples I can reference where a memory variable is attached to the player rather than an entity PersonAPI?

I know it at least gets to this code:

Code

player = Global.getSector().getPlayerPerson();
        player.getMemoryWithoutUpdate().set("$PortraitsEnabled", false);


But that particular code doesn't seem to work while under EveryFrameScript.

I don't understand what I could be doing wrong. :( It seems rather straightforward on the surface.

Full script:
Code

package archeus.campaign.everyframescripts;

import com.fs.starfarer.api.EveryFrameScript;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.characters.PersonAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import com.fs.starfarer.api.util.Misc;
import archeus.rulecmd.SetPlayerPortraits;

import java.util.ArrayList;
import java.util.List;

public class CheckCommissionForPortraitLocks implements EveryFrameScript {
private IntervalUtil tracker = new IntervalUtil(0.05f, 0.1f);

    protected PersonAPI player;

public CheckCommissionForPortraitLocks() {
//player.getMemoryWithoutUpdate().is("$FactionOnlyPortraitsEnabled", true) &&
        player = Global.getSector().getPlayerPerson();
if (Misc.getCommissionFactionId() == null) {
resetPlayerPortraits();
}
}

public void advance(float amount) {
float days = Global.getSector().getClock().convertToDays(amount);
tracker.advance(days);
player = Global.getSector().getPlayerPerson();

//Global.getSector().getPlayerPerson().getMemoryWithoutUpdate().getBoolean("$player.FactionOnlyPortraitsEnabled")
if (tracker.intervalElapsed()) {
if (player.getMemoryWithoutUpdate().is("$FactionOnlyPortraitsEnabled", false) && Misc.getCommissionFactionId() == null) {
resetPlayerPortraits();
}
}
}

public void resetPlayerPortraits() {
        SetPlayerPortraits portraits = new SetPlayerPortraits();

List<Misc.Token> params = new ArrayList<Misc.Token>();
Misc.Token token = new Misc.Token("all", null);
params.add(0, token);
portraits.execute(null, null, params, null);

        player = Global.getSector().getPlayerPerson();
        player.getMemoryWithoutUpdate().set("$PortraitsEnabled", false);

        //throw new RuntimeException("Yep, it's running");
}

public boolean isDone() {
return false;
}

public boolean runWhilePaused() {
return false;
}
}


« Last Edit: November 10, 2019, 12:04:01 PM by Morrokain »
Logged
Pages: 1 ... 374 375 [376] 377 378 ... 706