Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 52 53 [54] 55 56 ... 548

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

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #795 on: September 17, 2013, 01:26:18 PM »

Are four jump points the minimum? I always get an extra fringe jump point which I don't want, but I can't see a way to remove it.
(My system always has two fringe jump points.)

Does this have anything to do with it?
system.autogenerateHyperspaceJumpPoints(true, true);

Yes the first one is if you want to generate hyperspace entrances on Gas Giants,
the second one asks if you want a fringe jump gate generated.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 19437
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #796 on: September 17, 2013, 01:27:53 PM »

Two fringe points is a symptom of your system being added to the game twice. Probably because you've got it in both onNewGame and onEnabled? Something like that.

For the second question: yes, it does, but that'd only generate one fringe point. Take a look at the javadoc here to see what the parameters mean:
http://fractalsoftworks.com/starfarer.api/index.html?com/fs/starfarer/api/campaign/StarSystemAPI.html


(You don't *have* to autogenerate any jump points, btw. Could do it all by hand, but it's trickier.)
Logged

Gotcha!

  • Admiral
  • *****
  • Posts: 1119
    • View Profile
    • Welcome to New Hiigara
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #797 on: September 17, 2013, 01:53:54 PM »

I did a search through my mod and yes, both OnNewGame and OnEnabled were both present.
Got it fixed now.

Damn, this community is the greatest. Solving problems like there's no tomorrow.
Logged
  

Gotcha!

  • Admiral
  • *****
  • Posts: 1119
    • View Profile
    • Welcome to New Hiigara
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #798 on: September 17, 2013, 02:42:15 PM »

I've got another question.
This is the script in my mod that causes Hiigaran supply ships to spawn near the border of its system.
Spoiler
Code
package data.scripts.world;

import java.util.List;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.Script;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.CargoAPI;
import com.fs.starfarer.api.campaign.FleetAssignment;
import com.fs.starfarer.api.campaign.LocationAPI;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.fleet.FleetMemberType;
import com.fs.starfarer.api.campaign.CargoAPI.CrewXPLevel;

@SuppressWarnings("unchecked")
public class HiigaraConvoySpawnPoint extends BaseSpawnPoint {

private final SectorEntityToken convoyDestination;

public HiigaraConvoySpawnPoint(SectorAPI sector, LocationAPI location,
float daysInterval, int maxFleets, SectorEntityToken anchor,
SectorEntityToken convoyDestination) {
super(sector, location, daysInterval, maxFleets, anchor);
this.convoyDestination = convoyDestination;
}

private static int convoyNumber = 0;

@Override
protected CampaignFleetAPI spawnFleet() {
String type = null;
float r = (float) Math.random();
if (r > 0.9f) {
type = "fuelConvoy";
} else if (r > 0.6f) {
type = "explorationFleet";
} else {
type = "supplyConvoy";
}

float angle = (float) ((float) Math.random() * Math.PI * 2f);
float x = (float) (Math.cos(angle) * 18000f);
float y = (float) (Math.sin(angle) * 18000f);

CampaignFleetAPI fleet = getSector().createFleet("hiigaran_descendants", type);
getLocation().spawnFleet(getAnchor(), x, y, fleet);

if (type.equals("supplyConvoy")) {
CargoAPI cargo = fleet.getCargo();
addRandomWeapons(cargo, 8);
}
else if (type.equals("explorationFleet")) {
CargoAPI cargo = fleet.getCargo();
cargo.addCrew(CrewXPLevel.ELITE, 10);
      cargo.addCrew(CrewXPLevel.VETERAN, 50);
      cargo.addCrew(CrewXPLevel.REGULAR, 100);
}
else if (type.equals("fuelConvoy")) {
CargoAPI cargo = fleet.getCargo();
cargo.addFuel(250);
}

addRandomShips(fleet.getCargo(), (int) (Math.random() * 4f));

Script script = null;
if (type.equals("supplyConvoy")) {
script = createArrivedScript();
Global.getSectorAPI().addMessage("A Hiigaran supply convoy is in-system and under way to rendezvous with the New Hiigaran Orbital Station");
}

fleet.addAssignment(FleetAssignment.DELIVER_RESOURCES, convoyDestination, 1000, script);
fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);

return fleet;
}

private Script createArrivedScript() {
return new Script() {
public void run() {
Global.getSectorAPI().addMessage("A Hiigaran transport fleet has delivered new equipment to their station");
}
};
}

private void addRandomWeapons(CargoAPI cargo, int count) {
List weaponIds = getSector().getAllWeaponIds();
for (int i = 0; i < count; i++) {
      String weapon = (String) weapons[(int) (weapons.length * Math.random())];
int quantity = (int)(Math.random() * 4f + 2f);
cargo.addWeapons(weapon, quantity);

}
}

private void addRandomShips(CargoAPI cargo, int count) {
List weaponIds = getSector().getAllWeaponIds();
for (int i = 0; i < count; i++) {
if ((float) Math.random() > 0.5f) {
String wing = (String) wings[(int) (wings.length * Math.random())];
cargo.addMothballedShip(FleetMemberType.FIGHTER_WING, wing, null);
} else {
String ship = (String) ships[(int) (ships.length * Math.random())];
cargo.addMothballedShip(FleetMemberType.SHIP, ship, null);
}
}
}

private static String [] ships = {
"hii_fiirkan_Hull",
"hii_jet_Hull",
"hii_kaan_Hull",
"hii_rathan_Hull",
"hii_vraan_Hull",
"hii_vaahrok_Hull",
};

private static String [] wings = {
"hii_tarii_wing",
"hii_toba_wing",
"hii_heeshk_wing",
"hii_raachok_wing",
};

private static String [] weapons = {
"hii_pulsar_beam",
"hii_sustained_ion_beam",
"hii_sustained_ion_beam_xl",
"hii_accelerated_pulsar_beam_sm",
"hii_accelerated_pulsar_beam",
"hii_singularity_cannon",
"hii_flak_cannon",
"hii_kinetic_driver",
"hii_chaingun_medium",
"hii_chaingun_large",
"hii_chaingun_medium_he",
"hii_chaingun_large_he",
"hii_kinetic_burst_cannon",
"hii_kinetic_burst_cannon_large",
"hii_kinetic_burst_cannon_he",
"hii_kinetic_burst_cannon_large_he",
"hii_single_cannon",
"hii_cor_missile_pod",
"hii_cor_missile_pod_xl",
"hii_tviir_launcher",
"hii_torpedo_launcher",
"hii_abas_missile_pod",
"hii_abas_missile_pod_xl",
};
}
[close]

I'd like to have the supply fleets spawn from one of the wormholes instead. But how would that be done?

I take it that I'd need to remove this and that it would need to be replaced with something else?
Code
		float angle = (float) ((float) Math.random() * Math.PI * 2f);
float x = (float) (Math.cos(angle) * 18000f);
float y = (float) (Math.sin(angle) * 18000f);

CampaignFleetAPI fleet = getSector().createFleet("hiigaran_descendants", type);
getLocation().spawnFleet(getAnchor(), x, y, fleet);
Logged
  

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #799 on: September 17, 2013, 10:18:24 PM »

Is there a functional way I can get a mod to check for other installed mods, and trigger code if they are, without crashing if they aren't?

example: I have both my Kadur Theocracy and MShadowy's Shadowyards Heavy Industries mods installed. Can I somehow write code in the Kadur Theocracy scripts to trigger if SHI is loaded and make a station in the Kadur star system send supply convoys to/from stations in the star system that Shadowyards Heavy Industries adds, without crashing the game if the SHI mod isn't installed?

This should still work:

Code
try
{
Global.getSettings().getScriptClassLoader().loadClass("data.scripts.world.SHIGen");
System.out.println("Shadowyards HI installed");
// TODO STUFF
}
catch (ClassNotFoundException ex)
{
System.out.println("Shadowyards HI not installed");
}

Coming back to this now :P

I thought it was working, but as it turns out I need to import chunks of the other mod to do stuff (in this case spawn fleets from it). The problem being, if the mod isn't turned "on" in the mods menu when you start Starsector (or presumably also if it's not installed at all) it crashes trying to import a thing that it can't.

So I guess what I'm really asking is this: Is there either a way to catch failed imports or a way to only import something if it exists? Google has failed me, you guys are my only hope. My approach to scripting/coding is pretty much just bashing my forehead on the keyboard and forgetting commas and semicolons, so my attempts at figuring it out on my own have not met with any success.

edit: I can see that the way Exerelin was doing it did work, since I played that for a long time without the optional faction mods installed and it obv. didn't crash. I'll keep digging and see if I can figure out where I'm going wrong.
« Last Edit: September 17, 2013, 10:54:28 PM by Vayra »
Logged
Kadur Remnant: http://fractalsoftworks.com/forum/index.php?topic=6649
Vayra's Sector: http://fractalsoftworks.com/forum/index.php?topic=16058
Vayra's Ship Pack: http://fractalsoftworks.com/forum/index.php?topic=16059

im gonna push jangala into the sun i swear to god im gonna do it

TimeDiver

  • Commander
  • ***
  • Posts: 188
    • View Profile
Any method of implementing aptitudes/skills in missions?
« Reply #800 on: September 17, 2013, 10:55:33 PM »

A general search of the forums hasn't provided much info on the following, so I ask in detail: Is implementing aptitudes/skills in missions possible via scripting?

I've seen one mod (Verrius' Fleet Control Mod) that can directly affect the aptitude/skill level(s) of other fleets (in a campaign), but only by calling MutableCharacterStatsAPI via CampaignFleetAPI.

Since playing missions from within the campaign isn't possible from what I've gathered, is there a way to implement the above, much in the same way that running a combat simulation within the campaign factors in the player's aptitudes/skills, unlike when loading said simulation from the Missions menu?

Granted, I'm not expecting to be able to force the 'Character' UI tab to display, but more along the lines of defining friendly/enemy fleet aptitude/skill levels for a single mission in the .java file.
« Last Edit: September 18, 2013, 12:34:48 AM by TimeDiver »
Logged

Zaphide

  • Admiral
  • *****
  • Posts: 799
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #801 on: September 18, 2013, 01:01:34 AM »

@Varya
Hmmm i think that loading things from mods a user has disabled is probably not the best approach. They may be disabled for a reason.

The code I posted just checks for the existence of a class. The class you check for should be unique for the mod your checking for, and if that class exists then you can assume that mod in its entirety has been loaded.

Regardless, it sounds like you want to use scripts from the other mod, without those scripts being in you mod. In Exerelin, I just use the other mods assets (art, hulls, variants etc) which are not scripts. Scripts in StarSector are Java classes, and those classes need to exist at compile time (StarSector initial load) otherwise it will say 'class not found'. As this happens at compile time, you can't try/catch to handle any errors.

I think you will either have to write generic scripts that you can use for any faction (similar to the way Exerelin does it) or have copies of the other mods scripts in your mod so that it passes the compile check, and then you can use those scripts only if te other mod is loaded as well (using the above code snippet).

Hopefully that makes (some sort of) sense :)
Logged

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #802 on: September 18, 2013, 01:04:40 AM »

@Varya
Hmmm i think that loading things from mods a user has disabled is probably not the best approach. They may be disabled for a reason.

I was trying to get it to only load the scripts if they were enabled, or continue without them if they were disabled.  :P
 
The code I posted just checks for the existence of a class. The class you check for should be unique for the mod your checking for, and if that class exists then you can assume that mod in its entirety has been loaded.

Regardless, it sounds like you want to use scripts from the other mod, without those scripts being in you mod. In Exerelin, I just use the other mods assets (art, hulls, variants etc) which are not scripts. Scripts in StarSector are Java classes, and those classes need to exist at compile time (StarSector initial load) otherwise it will say 'class not found'. As this happens at compile time, you can't try/catch to handle any errors.

I think you will either have to write generic scripts that you can use for any faction (similar to the way Exerelin does it) or have copies of the other mods scripts in your mod so that it passes the compile check, and then you can use those scripts only if te other mod is loaded as well (using the above code snippet).


Hopefully that makes (some sort of) sense :)


This was really helpful, thank you.  ;D

edit: Ok, new question. I have a ship system that is essentially just a burn drive with some variables changed. One of those variables is the flameout on impact chance being 1, i.e. guaranteed to happen if you crash. Problem is, if that happens the ship keeps going -- at it's increased speed, too -- until the engines come back online from the flameout!

How fix? :o
« Last Edit: September 18, 2013, 01:51:07 AM by Vayra »
Logged
Kadur Remnant: http://fractalsoftworks.com/forum/index.php?topic=6649
Vayra's Sector: http://fractalsoftworks.com/forum/index.php?topic=16058
Vayra's Ship Pack: http://fractalsoftworks.com/forum/index.php?topic=16059

im gonna push jangala into the sun i swear to god im gonna do it

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #803 on: September 18, 2013, 07:57:06 AM »

Heres a piece of code some might be interested in, its basically a self armor repair, all you need is the target (ShipAPI) set and do this condition in a IntervalTimer to prevent a infinite loop:

Code: java
            float[][] armorgrid = target.getArmorGrid().getGrid();      
            for(int line = 0;line < armorgrid.length;line++)
            {
                //for each line, we got several columns
                for(int column = 0;column < armorgrid[line].length;column++)
                {
                    float armorAmount = Math.round(target.getArmorGrid().getArmorValue(line,column));
                    //Math.round prevents unnecessary huge float numbers that might come out from this.
                    float armorToFix = target.getArmorGrid().getMaxArmorInCell() - armorAmount;
                    target.getArmorGrid().setArmorValue(line, column, armorToFix);
                }
            }
« Last Edit: October 02, 2013, 07:20:48 AM by silentstormpt »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 19437
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #804 on: September 18, 2013, 10:11:35 AM »

@TimeDiver: You can set the skills/aptitudes of individual captains, like so:
      FleetMemberAPI fleetMember;
      fleetMember = api.addToFleet(FleetSide.PLAYER, "venture_Balanced", FleetMemberType.SHIP, "ISS Hamatsu", false);
      fleetMember.getCaptain().getStats().setAptitudeLevel(id, level)
      fleetMember.getCaptain().getStats().setSkillLevel(id, level);


Unless I'm forgetting something, it's not possible to apply fleetwide skill effects this way, though - just the "piloted ship" ones.
Logged

TimeDiver

  • Commander
  • ***
  • Posts: 188
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #805 on: September 18, 2013, 02:45:06 PM »

Thanks for that info, Alex! Can't imagine how busy you must be, ironing out the numerous kinks for v0.6.1a...
Logged

Gotcha!

  • Admiral
  • *****
  • Posts: 1119
    • View Profile
    • Welcome to New Hiigara
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #806 on: September 18, 2013, 02:51:45 PM »

This probably has been asked before, but what do the two numbers do in a spawn line like this?

HiigaraPirateSpawnPoint pirateSpawn = new HiigaraPirateSpawnPoint(sector, system, 1, 40, system.getEntityByName("Kohntala"));
Logged
  

Dayshine

  • Ensign
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #807 on: September 18, 2013, 03:16:10 PM »

This probably has been asked before, but what do the two numbers do in a spawn line like this?

HiigaraPirateSpawnPoint pirateSpawn = new HiigaraPirateSpawnPoint(sector, system, 1, 40, system.getEntityByName("Kohntala"));


From BaseSpawnPoint.java:

Code
public BaseSpawnPoint(SectorAPI sector, LocationAPI location, 
float daysInterval, int maxFleets, SectorEntityToken anchor)

The two numbers are the minimum number of days between two spawns and the maximum number of fleets to be deployed.

Code
if (clock.getElapsedDaysSince(lastSpawnTime) >= daysInterval) {
  //Try to spawn a fleet
}

It just tracks the last time it tried to spawn a fleet, then compares days elapsed to the value.

Code
if (fleets.size() < maxFleets) {
  //Actually spawn a fleet
}

If it is time to spawn a new fleet it prunes all dead fleets then tries to spawn a fleet. If there are too many it doesn't, but still counts this as the last time a fleet was spawned. So it won't try more than every daysInterval, stops insta-replacements I guess.

Of course you can override this behavior by changing the public void advance(float amount) method and make it spawn based on whatever you want.
Logged

Gotcha!

  • Admiral
  • *****
  • Posts: 1119
    • View Profile
    • Welcome to New Hiigara
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #808 on: September 18, 2013, 03:22:12 PM »

Ah, thank you. Much obliged.

Of course you can override this behavior by changing the public void advance(float amount) method and make it spawn based on whatever you want.

Well, someone could. But I have no idea what you're talking about. ^_^'
Logged
  

Darloth

  • Admiral
  • *****
  • Posts: 564
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #809 on: September 18, 2013, 03:29:03 PM »

the 'public void advance(float amount)' method is a method that exists on all SpawnPoints and EveryFramePlugins.

Basically, if you have one of those, and you put code in advance(), it will be called every frame(if you're in the right location).  The parameter 'amount' will be set to a floating point value (number with a decimal bit, like... 4.8 for example) equal to how many seconds have passed since advance() was last called.

So, if you really wanted a spawnpoint to spawn a fleet every real-time 18.7 seconds, that would be how you do it: Have a variable, add up the amount values each time advance() is called, and when it's greater than 18.7, zero it(sic) and spawn the fleet.
« Last Edit: September 19, 2013, 12:28:57 AM by Darloth »
Logged
Pages: 1 ... 52 53 [54] 55 56 ... 548