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)

Author Topic: General modding help request  (Read 2898 times)

TheDTYP

  • Commander
  • ***
  • Posts: 136
    • View Profile
General modding help request
« on: May 19, 2014, 06:46:10 PM »

Hello, modders. I want to say right off the bat: I have zero experience modding and I have little to no clue what I'm doing. The only things I have done were attempt to make a faction and mission, but it seems like the available guides are out of date.
Basically what I wanted to do was make a small faction (No special ships or systems or anything fancy, just another group of people who use vanilla ships) and a solar system for them to call home. Being that the "Guide to adding your own faction to the game" is almost two years old and was around long before other solar systems were implemented, I'm now pretty stuck. Much of this file stuff is absolute gibberish to me. What I tried to do was copy and paste other files over and try to edit them myself, but that ended in disaster.
I know you have better things to do,  but I'd really appreciate it if someone could have the time and the heart to create an up to date guide on how to build a vanilla faction and add a solar system.
Telling me how to make a mission wouldn't go amiss either. And if it just so happens everything I need already exists and is on this very forum and I just wasn't vigilant enough, could I please have a link? Thank you very much.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: General modding help request
« Reply #1 on: May 19, 2014, 07:22:14 PM »

If you're new to Java, do a bit of homework first; while this is pretty trivial to code, you're still working with a programming language, not just some text files.  It's one of the awesome things about StarSector, but the learning-curve is a little steep.

Anyhow... all you need to do is write a ModPlugin that constructs your System on a new game; see how this is done in the core ModPlugins of most of the single-faction mods.  Here's a straightforward example that generates Askonia:
Spoiler
Code: java
package data.scripts;

import com.fs.starfarer.api.BaseModPlugin;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CampaignPlugin;
import com.fs.starfarer.api.campaign.SectorAPI;

import data.scripts.world.systems.Askonia;

public class MyModModPlugin extends BaseModPlugin
{
    private static void initMyMod()
    {
        try
        {
            Global.getSettings().getScriptClassLoader().loadClass("data.scripts.world.ExerelinGen");
        }
        catch (ClassNotFoundException ex)
        {
            new Askonia().generate(Global.getSector());
        }
    }

    @Override
    public void onNewGame()
    {
        initMyMod();
    }
}
[close]

Your modinfo.json file needs to refer to that ModPlugin.

Then you just need to build the System itself.  This part is not trivial- it can be very simple or very complex, depending on what you want to do; you need to learn some Java first, and study the available examples.  

See Askonia.java in scripts/worlds/systems for some details.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

TheDTYP

  • Commander
  • ***
  • Posts: 136
    • View Profile
Re: General modding help request
« Reply #2 on: May 21, 2014, 04:09:51 PM »

Hey, thanks for the request! Helps me out a bit. Alright, now one more question, I'm guessing doing this in a text document doesn't cut it? Do I need some kind of program or have I just been doing it slightly wrong?
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: General modding help request
« Reply #3 on: May 21, 2014, 07:56:07 PM »

While you can use a text editor like Notepad++, that limits your code to what the Janino JIT compiler can handle; without getting into a bunch of details, that means editing a few things will get pretty scary.  Not only that, but the only way you'll get bug reports is via StarSector's logs, which makes things a little slow if this is your first time learning to code, because you'll have to wait for the game to crash, scroll down through the log to see the error, find the line where it happened, etc., etc.

I strongly suggest that, instead of doing it that way, which is slow and inefficient, set up an IDE.  IDEs are great, because they'll catch code bugs as you write them, give helpful explanations about structural things you can do, etc., etc., and they're the easiest way to compile a JAR (it's like a DLL- a pre-compiled bit of code SS can use), which is necessary if your mod's code gets really big, as otherwise startup times can increase a bit.  This is one of those things where it's a little hard at first, but will save you lots of time in the future.

I'm currently using NetBeans, which is easy to use and configure.  There are lots of IDEs for Java, but NetBeans is a very solid, well-supported one and it's easy to set up.  LazyWizard wrote up a great newbie tutorial on how to set up your mod to compile and all that here.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Thaago

  • Global Moderator
  • Admiral
  • *****
  • Posts: 7174
  • Harpoon Affectionado
    • View Profile
Re: General modding help request
« Reply #4 on: May 22, 2014, 11:51:21 AM »

I will completely second working with an IDE like Netbeans. Not only will it save you time, but you will learn Java faster because you have immediate feedback if you do something wrong (and we all do). LazyWizard's tutorial may seem long, but it will save you lots of time once you start modding.
Logged