Fractal Softworks Forum

Starsector => Mods => Modding => Topic started by: hqz on March 23, 2016, 01:50:23 PM

Title: How to add a campaign ability?
Post by: hqz on March 23, 2016, 01:50:23 PM
I just want a button in the ability bar for an action that is instantaneous, i.e. no cooldown, the player clicks on it and it displays some message.

But I can't manage to make it work. I can't even get a copy of an existing ability to work.

mod_info.json
Code
{
    "id": "mod-examples",
    "name": "Mod Examples",
    "author": "hqz",
    "version": "1",
    "description": "Examples",
    "gameVersion": "0.7a",
    "jars": [],
}

data/campaign/abilities.json
Code
{
  "example_ability":{
    "plugin":"com.fs.starfarer.api.impl.campaign.abilities.SensorBurstAbility",
    "unlockedAtStart":true,
    "defaultForAIFleet":false,
    "sortOrder":500,

    "musicSuppression":0,
    "uiOn":"ui_sensor_burst_on",
    "worldOn":"world_sensor_burst_on",
  },
}

Note: these are the 2 only files in the mod. I'm trying to keep it simple so that I'm sure it's not some side effect from something else messing with my ability.

If I make a deliberate error in the ability definition (e.g. wrong class name), the game crashes, which means it somehow registers that an ability is defined. But it never shows up in the ability bar in game.

I've read the code from other mods and I don't see what I'm doing differently.
e.g. ExerelinCore/exerelin/campaign/abilities/FollowMeAbility.java (https://bitbucket.org/Histidine/exerelin/src/55d1ab3ae22b/jars/sources/ExerelinCore/exerelin/campaign/abilities/FollowMeAbility.java?at=master)

What am I missing here?
Title: Re: How to add a campaign ability?
Post by: Harpuea on March 29, 2016, 06:58:20 PM
You also need to add the png directory in settings.json.

Title: Re: How to add a campaign ability?
Post by: hqz on March 31, 2016, 09:44:19 PM
You also need to add the png directory in settings.json.

Even if I reuse an existing icon as I did in my example?

Code
  "uiOn":"ui_sensor_burst_on",
Title: Re: How to add a campaign ability?
Post by: Histidine on April 01, 2016, 07:24:47 PM
That's the sound file. Image is defined in the ability's Java class file.

Anyway, my (completely uninformed) guess is two abilities can't have the same class, though that sounds like a really odd limitation. Try making a stub class for your test ability.