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 ... 589 590 [591] 592 593 ... 706

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

Lord Admiral Spire

  • Ensign
  • *
  • Posts: 6
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8850 on: June 21, 2022, 09:22:35 PM »

A shame. My java's just not good enough to make new API hooks at present. Have to hold off until I know more.
Logged

presidentmattdamon

  • Commander
  • ***
  • Posts: 249
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8851 on: June 22, 2022, 07:15:54 AM »

is there a way to get a fleet member object directly from a fleet member ID without searching through every location and fleet?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8852 on: June 22, 2022, 08:32:04 AM »

is there a way to get a fleet member object directly from a fleet member ID without searching through every location and fleet?

There isn't, and that might not necessarily do it - e.g. if it's a player ship, they might have put it in storage, or scuttled it.

You can take a look at com.fs.starfarer.api.impl.campaign.plog.SModRecord for a safe way (using WeakReference) to hang on to FleetMemberAPI references directly, that don't leak those fleet members if they go away.
Logged

presidentmattdamon

  • Commander
  • ***
  • Posts: 249
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8853 on: June 23, 2022, 09:18:20 AM »

is there a way to get a fleet member object directly from a fleet member ID without searching through every location and fleet?

There isn't, and that might not necessarily do it - e.g. if it's a player ship, they might have put it in storage, or scuttled it.

You can take a look at com.fs.starfarer.api.impl.campaign.plog.SModRecord for a safe way (using WeakReference) to hang on to FleetMemberAPI references directly, that don't leak those fleet members if they go away.

will take a look there then. my current way retrieves market storages as well, but there are times where i need the fleet members and needing to iterate through everything doesn't seem like the best way.
Logged

JAL28

  • Commander
  • ***
  • Posts: 217
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8854 on: June 23, 2022, 09:31:32 AM »

Is there a line or code that makes a script wait for a certain amount of time(say 2 cycles) before firing? And if so what units does Starsector use to measure time and how much would it that be for 2 cycles?
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8855 on: June 23, 2022, 10:19:10 AM »

Alex is it possible to make an AI Core admin that has permanent different than normal name, image and skills? One you can reassign around, that is. (ie: a player owned version of the tritach guy that has the SUSPECTED_AI tag.)
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8856 on: June 23, 2022, 10:47:53 AM »

Is there a line or code that makes a script wait for a certain amount of time(say 2 cycles) before firing? And if so what units does Starsector use to measure time and how much would it that be for 2 cycles?

To do that, you would just track the amount of time elapsed in the script and then fire whatever code you need and after that happens, have the script's isDone() return true.

The advance(float amount) method gets the amount of seconds elapsed (so, typically, 1/60 or so); you can convert that to in-universe days by using Global.getSector().getClock().convertToDays() or something very similar.

Alex is it possible to make an AI Core admin that has permanent different than normal name, image and skills? One you can reassign around, that is. (ie: a player owned version of the tritach guy that has the SUSPECTED_AI tag.)

Hmm, probably? I think you'd want to start with a regular person and fake it up a bit. I'm not sure exactly how it would work out as far as "not counting against the number of admins" etc, though; that would need a bunch of digging around.
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8857 on: June 23, 2022, 10:54:38 AM »

I tried imitating the tritach guy code but when you assign the admin to a planet, you start to see duplicates.

If you have two of such admins, assigning them both to a planet, make one of them show "unassigned" on the menu, meanwhile on planet list they are assigned properly.

It seems the handling of admins that are AI is very, VERY hardcoded.
Logged

AccuracyThruVolume

  • Commander
  • ***
  • Posts: 133
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8858 on: June 23, 2022, 08:56:48 PM »

What is the best way to play a sound from a ship when a shipsystem is activated?

I tried inside of the BaseShipSystemScript class but can't seem to find the right hooks.

For example, I tried:

public float getInfoText(ShipSystemAPI system, ShipAPI ship)
{
   Global.getSoundPlayer().playSound("waaagh", 1f, .8f, ship.getLocation(), new Vector2f());
   return 0f;
}


I tried something that would use the shipapi, therefore I could use ship.location.     Had no success so far.    Is there a simpler command inside of the BaseShipSystemScript class?


Current shipsystem code with commented out part:
Spoiler

package data.shipsystems.scripts;


import com.fs.starfarer.api.combat.*;
import com.fs.starfarer.api.Global;

//import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.impl.combat.BaseShipSystemScript;
import com.fs.starfarer.api.plugins.ShipSystemStatsScript;

import org.lwjgl.util.vector.Vector2f;

public class WaaaghStats extends BaseShipSystemScript {
   
   public static final float ROF_BONUS = 1f;
   public static final float FLUX_REDUCTION = 50f;
   
   /*
   public float getInfoText(ShipSystemAPI system, ShipAPI ship)
   {
      Global.getSoundPlayer().playSound("waaagh", 1f, .8f, ship.getLocation(), new Vector2f());
      return 0f;
   }
   */

   public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel)
   {
      if (state == ShipSystemStatsScript.State.OUT) {
         stats.getMaxSpeed().unmodify(id); // to slow down ship to its regular top speed while powering drive down
      } else {
         stats.getMaxSpeed().modifyFlat(id, 200f * effectLevel);
         stats.getAcceleration().modifyFlat(id, 200f * effectLevel);
         //stats.getAcceleration().modifyPercent(id, 200f * effectLevel);
      }
      
      
      float mult = 1f + ROF_BONUS * effectLevel;
      stats.getBallisticRoFMult().modifyMult(id, mult);
      stats.getBallisticWeaponFluxCostMod().modifyMult(id, 1f - (FLUX_REDUCTION * 0.01f));
      
   }   
   
   public void unapply(MutableShipStatsAPI stats, String id)
   {
      stats.getMaxSpeed().unmodify(id);
      stats.getMaxTurnRate().unmodify(id);
      stats.getTurnAcceleration().unmodify(id);
      stats.getAcceleration().unmodify(id);
      stats.getDeceleration().unmodify(id);
      
      stats.getBallisticRoFMult().unmodify(id);
      stats.getBallisticWeaponFluxCostMod().unmodify(id);

   }
   
   public StatusData getStatusData(int index, State state, float effectLevel) {
      
      float mult = 1f + ROF_BONUS * effectLevel;
      float bonusPercent = (int) ((mult - 1f) * 100f);
      if (index == 0)
      {
         return new StatusData("ballistic rate of fire +" + (int) bonusPercent + "%", false);
         //return new StatusData("increased engine power", false);
      }
      if (index == 1)
      {
         return new StatusData("ballistic flux use -" + (int) FLUX_REDUCTION + "%", false);
      }
      return null;
   }
}
[close]

Also, what is the correct way to return more then one StatusData at the same time?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8859 on: June 24, 2022, 09:46:33 AM »

The easiest would be to specify it via
"useSound":"<whatever>",

In the .system file.

For status, you can check out AmmoFeedStats or anything else in vanilla that has multiple status items.
Logged

AccuracyThruVolume

  • Commander
  • ***
  • Posts: 133
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8860 on: June 24, 2022, 05:29:43 PM »

*facepalm*  Missed the usesound line in the system file, that worked nicely, thanks!    ;D


All vanilla systems I checked only return a single status data item per index number.

How does one return 2 StatusData items for the same index number?


Example ammofeed:

if (index == 0) {
   return new StatusData("ballistic rate of fire +" + (int) bonusPercent + "%", false);
   }
   if (index == 1) {
   return new StatusData("ballistic flux use -" + (int) FLUX_REDUCTION + "%", false);
   }
   return null;
« Last Edit: June 24, 2022, 05:32:23 PM by AccuracyThruVolume »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8861 on: June 24, 2022, 08:05:33 PM »

Why would you want to/how would that even work? I feel like there may be some misconception about what the index numbers do - they're just a means to enable the script to return a bunch of different statuses. (I don't remember why I did it this way instead of it just returning a List or some such.)
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8862 on: June 25, 2022, 09:18:04 AM »

How I add an abandoned station with stuff in storage but that you must fight to get the stuff?

Also, I tried adding defenders to a planet ruins with setDefenderOverride and it works, but prints some "null" errors on the text, how I fix that?
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8863 on: June 25, 2022, 06:56:21 PM »

Maybe get the actual null errors from starsector.log and work from there.

For defenders of an abandoned station, I'd probably do a custom path for the interaction dialog in rules.csv, started by a rule with an OpenInteractionDialog trigger that checks if the interaction is with the particular station we want. I think once a $defenderFleet is defined, you could use a SalvageDefenderInteraction call to set up the battle.
Logged

AccuracyThruVolume

  • Commander
  • ***
  • Posts: 133
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8864 on: June 26, 2022, 06:46:22 AM »

Why would you want to/how would that even work? I feel like there may be some misconception about what the index numbers do - they're just a means to enable the script to return a bunch of different statuses. (I don't remember why I did it this way instead of it just returning a List or some such.)

I'm not so much worried about the index number, more interested if there is a way to return two StatusData items.


Basically I squished the ammofeed and burndrive together, because rushing in with guns blazing is lore correct for the faction I'm working on.   However, the mix of the two shipsystems led me to this in the StatusData  function:

Spoiler

public StatusData getStatusData(int index, State state, float effectLevel) {
      
      float mult = 1f + ROF_BONUS * effectLevel;
      float bonusPercent = (int) ((mult - 1f) * 100f);
      if (index == 0)
      {
         return new StatusData("ballistic rate of fire +" + (int) bonusPercent + "%", false);
         //return new StatusData("increased engine power", false);    <---- had to comment this out
      }
      if (index == 1)
      {
         return new StatusData("ballistic flux use -" + (int) FLUX_REDUCTION + "%", false);
      }
      return null;
   }


[close]

So doing two return commands at once is a no-no, but is there a way to combine the two statusdata commands into one return command?    No worries if this is a no-go.

Hope this makes things less muddy   :)
Logged
Pages: 1 ... 589 590 [591] 592 593 ... 706