Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 321 322 [323] 324 325 ... 710

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

SafariJohn

  • Admiral
  • *****
  • Posts: 3021
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4830 on: August 21, 2019, 02:59:47 PM »

That works, thanks! Though, now I have to code descriptions *shakes fist*
Logged

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4831 on: August 21, 2019, 09:38:15 PM »

So, maybe a dumb question, but... I don't understand EventPlugins.

I've created a copy of part of the NearbyEventPlugin thingy. How do I go about adding it to the EventManager? I only see options to start or prime an event, but I just want to add it on a new game so it stays there and spawns distress calls.  ???

EDIT: Actually, what are the advantages of using an EventPlugin over an EveryFrameScript? It looks like the NearbyEventPlugin distress call bit in particular tracks its own timeout, etc, in an IntervalUtil and the advance() method, just like it would as an EveryFrameScript, so...

EDIT EDIT: While I'm here and asking questions: How would I go about getting the actual ShipAPI/FleetMemberAPI created as a CustomCampaignEntityAPI derelict? I need to add a custom hullmod to it, no matter what hull it is - so i can't just use a custom variant/hull that always has it - is my goal here. I have a sinking feeling it's not actually created until the player interacts with it, but I'm sure there's a way around that.
« Last Edit: August 21, 2019, 10:49:05 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

Hoon

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4832 on: August 22, 2019, 10:42:35 AM »

How does one use applyEffectsToFighterSpawnedByShip with xxxx.getMutableStats? I spent the entire day yesterday trying to make a simple hullmod that adds 25% more armor to fighters but no matter what I try it seems like I just can't seem to understand how anything works with applyEffectsToFighterSpawnedByShip
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1727
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4833 on: August 22, 2019, 01:18:46 PM »

@Varya: I'm afraid I don't have much experience with all that. I might get the chance to look into it later though.

@MrHoon:
That should be as simple as this:
Code
    @Override
    public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
        fighter.getMutableStats().getArmorBonus().modifyPercent(id, 25);
    }

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24116
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4834 on: August 22, 2019, 01:36:42 PM »

So, maybe a dumb question, but... I don't understand EventPlugins.

I've created a copy of part of the NearbyEventPlugin thingy. How do I go about adding it to the EventManager? I only see options to start or prime an event, but I just want to add it on a new game so it stays there and spawns distress calls.  ???

EDIT: Actually, what are the advantages of using an EventPlugin over an EveryFrameScript? It looks like the NearbyEventPlugin distress call bit in particular tracks its own timeout, etc, in an IntervalUtil and the advance() method, just like it would as an EveryFrameScript, so...

Yeah, just use an EFS - the NearbyEventsEvent is an event only for historical reasons. It used to be required/handy to send out reports, but since the intel system is completely different, "Events" have lost their purpose, code-wise.

EDIT EDIT: While I'm here and asking questions: How would I go about getting the actual ShipAPI/FleetMemberAPI created as a CustomCampaignEntityAPI derelict? I need to add a custom hullmod to it, no matter what hull it is - so i can't just use a custom variant/hull that always has it - is my goal here. I have a sinking feeling it's not actually created until the player interacts with it, but I'm sure there's a way around that.

DerelictShipEntityPlugin plugin = (DerelictShipEntityPlugin) entity.getCustomPlugin();
plugin.getData().ship <- this is a com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.ShipRecoverySpecial. PerShipData

It could be based on a variantId (i.e. ship.variantId != null), or it may be based on a variant (i.e. ship.variant != null). If there's a variant, you can change it however you like.

If it's based on a variantId, you'll need to set the variant first (to... whatever variant you want, really), but that should also work.


@Varya: I'm afraid I don't have much experience with all that. I might get the chance to look into it later though.

(Thank you for helping out here, btw! Much appreciated.)


@MrHoon:
That should be as simple as this:
Code
    @Override
    public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
        fighter.getMutableStats().getArmorBonus().modifyPercent(id, 25);
    }

Possibly worth noting: the hullmod needs to be on the carrier, *not* on the fighter.
Logged

Hoon

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4835 on: August 22, 2019, 02:04:21 PM »

Thank you guys so much! I didnt realize it had to be fighter.getMutableStats() and I kept doing ship.getMutableStats()

edit

So i tried this and I'm not sure its working?

This is the part of the code I'm working with
Code
public class hhe_FighterPlating extends BaseHullMod {
///
public static final float FIGHTER_ARMOR = 25f;
///
    @Override
public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
fighter.getMutableStats().getArmorBonus().modifyPercent(id, FIGHTER_ARMOR);
}
}


For testing purpose, I changed the FIGHTER_ARMOR = 25f to 5000f , but my fighters are still dying at the same speed as if they didn't have this hull.

Ive been testing this in both run simulation inside a fresh save and the benchmark tester, same results. Is there something else I need to add into the code? (aside from the string)
« Last Edit: August 22, 2019, 03:05:22 PM by MrHoon »
Logged

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4836 on: August 22, 2019, 02:55:44 PM »

It could be based on a variantId (i.e. ship.variantId != null), or it may be based on a variant (i.e. ship.variant != null). If there's a variant, you can change it however you like.

If it's based on a variantId, you'll need to set the variant first (to... whatever variant you want, really), but that should also work.

Thanks so much! I think I can puzzle it out from here.
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

Sundog

  • Admiral
  • *****
  • Posts: 1727
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4837 on: August 22, 2019, 03:50:48 PM »

Ive been testing this in both run simulation inside a fresh save and the benchmark tester, same results. Is there something else I need to add into the code? (aside from the string)
Is that all of the code? If so, it looks like you're missing your package and import lines. It's not strictly necessary, but you'll want to override getDescriptionParam as well. If that's not the problem... Is the hullmod showing up on the carrier? What's your hull_mods.csv look like? Are you sure it points to hhe_FighterPlating correctly?

(Thank you for helping out here, btw! Much appreciated.)
No problem! I figure trying to help with the easier problems in this thread is a way to help compensate for the time you've spent answering all my questions  :)

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24116
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4838 on: August 22, 2019, 04:26:59 PM »

No problem! I figure trying to help with the easier problems in this thread is a way to help compensate for the time you've spent answering all my questions  :)

;D <3
Logged

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4839 on: August 22, 2019, 04:32:51 PM »

Quick followup question!

Code: java
            DerelictShipEntityPlugin plugin = (DerelictShipEntityPlugin) entity.getCustomPlugin();
            PerShipData shipData = plugin.getData().ship;
            this.variant = shipData.variant;
            if (this.variant == null) {
                this.variant = Global.getSettings().getVariant(shipData.variantId);
            }
            this.variant = this.variant.clone(); // THIS LINE RIGHT HERE
           
            this.variant.addPermaMod("vayra_ghost_ship");

Is this .clone() line necessary to avoid messing up all hound_Assaults across the sector, or does Global.getSettings().getVariant(shipData.variantId) return a unique instance that I can mess with as much as I want?
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

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24116
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4840 on: August 22, 2019, 04:35:49 PM »

Is this .clone() line necessary to avoid messing up all hound_Assaults across the sector,

Correct!
Logged

Hoon

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4841 on: August 22, 2019, 06:25:40 PM »

Ive been testing this in both run simulation inside a fresh save and the benchmark tester, same results. Is there something else I need to add into the code? (aside from the string)
Is that all of the code? If so, it looks like you're missing your package and import lines. It's not strictly necessary, but you'll want to override getDescriptionParam as well. If that's not the problem... Is the hullmod showing up on the carrier? What's your hull_mods.csv look like? Are you sure it points to hhe_FighterPlating correctly?

(Thank you for helping out here, btw! Much appreciated.)
No problem! I figure trying to help with the easier problems in this thread is a way to help compensate for the time you've spent answering all my questions  :)

forgot about the import codes whoops

Code
package data.hullmods.scripts;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;

I didn't bother doing the description part yet because I wanted to see the mod actually working.

Normally if i messup in the import, I get an error message when i start the mod. Is it possible Im importing the wrong things?
Logged

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4842 on: August 22, 2019, 10:10:35 PM »

Whoops, got one more.

Code: java
            DerelictShipEntityPlugin plugin = (DerelictShipEntityPlugin) entity.getCustomPlugin();
            PerShipData shipData = plugin.getData().ship;
            this.variant = shipData.variant;
            if (this.variant == null) {
                this.variant = Global.getSettings().getVariant(shipData.variantId);
            }
            shipData.variantId = null;
            this.variant = this.variant.clone();
So this creates a ShipVariantAPI. All good so far. Note the shipData.variantId = null; because it looks like ShipRecoverySpecial prefers variantId over variant, heh.

This, in ShipRecoverySpecial
Code: java
		FleetMemberAPI member = null;
if (shipData.variantId != null) {
member = Global.getFactory().createFleetMember(FleetMemberType.SHIP, shipData.variantId);
} else {
member = Global.getFactory().createFleetMember(FleetMemberType.SHIP, shipData.variant);
}
creates a FleetMemberAPI, and sets its variant to that ShipVariantAPI as long as it doesn't have a .variantId. Am I right in assuming the ShipVariantAPI we created with .clone() above is the same instance as this new FleetMemberAPI will have, and will be unique to that FleetMemberAPI since it's a clone created in the process of generating it, and I can therefore store data in the hullmod with the ShipVariantAPI as a key? Or does .createFleetMember() clone the variant again?
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

Sundog

  • Admiral
  • *****
  • Posts: 1727
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4843 on: August 22, 2019, 11:06:01 PM »

Is it possible Im importing the wrong things?
It looks to me like you've got all your bases covered as far as imports are concerned. My guess at this point is that there's something wrong with your hull_mods.csv file. If you want to zip up your mod and send it to me I'd be happy to take a look.

@Varya: This stretches the limits of my knowledge a bit (hopefully Alex will correct me if I'm wrong), but...
Looking through decompiled code of createFleetMember, I see that it assigns the instance of the variant you pass it, so it looks to me like it should be the same key. Of course, it's always possible that it's changed later. If you want to make sure, you should be able to check for instance equality like this:
Code
if(if(member.getVariant() == shipData.variant)) {
    // Notify you somehow
}
clone() creates a new instance, which is the method of comparison used by HashMaps for objects that don't override equals() and hashCode(), so each clone should work as a unique key, even if they all have the same values.

bowman

  • Commander
  • ***
  • Posts: 101
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4844 on: August 23, 2019, 12:31:15 AM »

So, I did a search but.. not much came up. Hopefully I didn't just miss a post entirely.

Is there a way to check if a ship is phased? This is a built-in hullmod so it isn't an issue between "does the ship have phase or shield", instead it's simply "is it currently using its phase cloak". Without this if-statement the rest of the code seems to work fine but, with it, it doesn't activate even when phased. Are phase systems not considered shields for the ShieldAPI and thus returning null? Is there a different API I should be using? Maybe I'm just using the API wrong?(I really don't know java so it's probably the case)
I saw a phasecloakstats but that seemed like it was the phase jump ship system or something else.

Code
public void advanceInCombat (ShipAPI ship, float amount) {
ShieldAPI cloak = ship.getShield();

if (cloak != null && cloak.isOn()) {

//lines im ommitting because they're otherwise functional and it would just take up forumspace
}
Logged
Pages: 1 ... 321 322 [323] 324 325 ... 710