Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Trying to learn modding  (Read 1438 times)

Xanderzoo

  • Captain
  • ****
  • Posts: 342
    • View Profile
Trying to learn modding
« on: February 21, 2015, 07:47:54 PM »

I've been playing Starsector for a while an enjoying it a lot. I've also been trying to learn to mod it, but without much success. I've managed to make a few missions, but what I really want to do is create plugins. As far as I know from looking at other mods, a mod needs a "master plugin" that initiates the other ones. I tried to create an empty mod with a blank master plugin to see if I could just get it to run. Unfortunately, I got this error.

java.lang.RuntimeException: Error compiling [data.scripts.TestPlugin]
   at com.fs.starfarer.loading.scripts.ScriptStore$3.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: data.scripts.TestPlugin
   at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:179)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   ... 2 more

My master plugin is named TestPlugin.java and it is in the jars//data//scripts folder of my mod. I'm passing "data.scripts.TestPlugin" to "modPlugin" in mod_info.json. This is what my empty plugin looks like:

Code
package data.scripts;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.BaseModPlugin;

class TestPlugin extends BaseModPlugin {

}

I hope you can help me, as I really want to learn how to mod this game.
Logged

Protonus

  • Captain
  • ****
  • Posts: 444
  • AAAAAAAAAAAA
    • View Profile
Re: Trying to learn modding
« Reply #1 on: February 21, 2015, 10:33:54 PM »

The plugin is necessary whenever you are going to start the campaign integration or you have a unique coding that you may want to have your ships behave differently, like the Interstellar Imperium mod, which is where most of the magic happens. But if you are going to make some ships and a mission, the plugin is not necessary to build up.



To start with, your mod should have a mod_info.json, which is located just about inside your main mod folder, at "Mods\Your Mod Folder".

Then your plugin should be located at "Mods\Your Mod Folder\data\scripts".

For the script itself, here is mine:
Spoiler
Code
package data.scripts;  
  
import com.fs.starfarer.api.BaseModPlugin;  
import com.fs.starfarer.api.Global;  
import com.fs.starfarer.api.PluginPick;  
import com.fs.starfarer.api.campaign.CampaignPlugin;  
import com.fs.starfarer.api.combat.MissileAIPlugin;  
import com.fs.starfarer.api.combat.MissileAPI;  
import com.fs.starfarer.api.combat.ShipAPI;  
import data.scripts.world.PTgen;
  
public class PTechPlugin extends BaseModPlugin {  
  
    private static void initPT() {  
        try {  
            Global.getSettings().getScriptClassLoader().loadClass("data.scripts.world.ExerelinGen");  
        } catch (ClassNotFoundException ex) {  
        new PTgen().generate(Global.getSector());  
}
    }  
  
    @Override
    public void onNewGame()
    {
        initPT();
//        new PTgen().generate(Global.getSector());  
    }
}  
[close]

Well, almost ideal, except that it has Missile Plugins for future updates.

And yes, you have the necessary imports, but if you are going to have star system, the Global package and the name of your Generator, like the "PTgen", should also be there. Provided that you have the faction for it.

You can also locally reference the mods that already appeared in the Mods thread, just be wary that some of them have already integrated ShaderLib and LazyLib in their codes.
« Last Edit: February 21, 2015, 10:36:09 PM by Protonus »
Logged

The cookies are a weird one, okay.

Xanderzoo

  • Captain
  • ****
  • Posts: 342
    • View Profile
Re: Trying to learn modding
« Reply #2 on: February 21, 2015, 10:59:36 PM »

Thank you!!  No more errors!! ;D
Logged