Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 462 463 [464] 465 466 ... 710

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

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6945 on: December 30, 2020, 04:52:15 PM »

Ah thanks!
Logged

Originem

  • Purple Principle
  • Captain
  • ****
  • Posts: 430
  • Dancing like a boss.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6946 on: December 30, 2020, 07:03:51 PM »

fine...Is there any better way to detect if a fleet member exists? There is a problem that if I record a FleetMemberAPI, the member would be strong reference that won't be removed from the save.
Now I use member == null || member.getFleetData() == null to check. And another way I think is to use WeakReference, though it will take several lines in the save.
Logged
My mods


Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6947 on: December 30, 2020, 08:35:31 PM »

Using member.getFleetData() == null sounds reasonable, yeah. You might also check - if that's not null - whether getFleetData().getFleet() is also null, and if not, whether the fleet .isAlive().

You could use a weak reference, too. If it's only used occasionally the extra lines in the save don't matter very much, but if it's a commonplace thing with tens/hundreds or more uses, then it might be a concern.
Logged

Originem

  • Purple Principle
  • Captain
  • ****
  • Posts: 430
  • Dancing like a boss.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6948 on: December 30, 2020, 08:40:03 PM »

Using member.getFleetData() == null sounds reasonable, yeah. You might also check - if that's not null - whether getFleetData().getFleet() is also null, and if not, whether the fleet .isAlive().

You could use a weak reference, too. If it's only used occasionally the extra lines in the save don't matter very much, but if it's a commonplace thing with tens/hundreds or more uses, then it might be a concern.
What I wanna add is only in player's fleet and player's ship. hmm, maybe I could first not use weak reference and have a try.
« Last Edit: December 30, 2020, 08:44:57 PM by Originem »
Logged
My mods


Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6949 on: January 01, 2021, 03:51:16 PM »

2 Questions:

1) Having some trouble with:

Code
float count = submarket.getQuantity(CargoAPI.CargoItemType.NULL, hullmod);

I've tried all the CargoAPI.CargoItemType options other than FIGHTER_CHIP and WEAPONS. I assumed SPECIAL would be the correct one for hullmods but it doesn't seem like it. "hullmod" is the hullmod id string in the hullmods csv. "submarket" is a CargoAPI gotten from an existing submarket in the campaign's eceonomy.

I've verified that the id is correct and the market in question has a single copy of safetyoverrides, but when I use this code count is still coming up as 0.0

Is there a way to detect and remove hullmods from markets using the API? Weapons and fighters were comparatively very easy to adjust.

2) Does setting the hull frequency to 0 also prevent a ship from spawning in the market as well as fleets?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6950 on: January 01, 2021, 04:07:26 PM »

The getQuantity method won't work quite how you want. The second parameter is the id of the special item *type*, so something like:
getQuantity(CargoItemType.SPECIAL, Items.MODSPEC)

Would get you the total number of mod specs in the cargo, but not for a specific modspec.

You'd want to do something like this:

for (CargoStackAPI stack : cargo.getStacksCopy()) {
   SpecialItemData data = stack.getSpecialDataIfSpecial();
   if (data != null && data.getData().equals(hullmod)) {
      count++;
   }
}
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6951 on: January 01, 2021, 04:07:52 PM »

2) Does setting the hull frequency to 0 also prevent a ship from spawning in the market as well as fleets?

(Oh, and this: ... I don't actually remember. I *think* so?)
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6952 on: January 01, 2021, 05:30:21 PM »

Ah ok. Can I remove them using: submarket.removeItems(CargoAPI.CargoItemType.SPECIAL, hullmod, count);?

2) Does setting the hull frequency to 0 also prevent a ship from spawning in the market as well as fleets?

(Oh, and this: ... I don't actually remember. I *think* so?)

It at least seems to. But I assume the BPs are still raid-able since the faction still technically knows them. I need to test raiding a bit more.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6953 on: January 01, 2021, 06:05:01 PM »

It'd be something like:

cargo.removeItems(CargoAPI.CargoItemType.SPECIAL, new SpecialItemData(Items.MODSPEC, hullmod), count)
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6954 on: January 02, 2021, 01:00:07 AM »

^Thanks! I tested it out and the code works now.
Logged

IonDragonX

  • Admiral
  • *****
  • Posts: 816
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6955 on: January 02, 2021, 11:43:25 AM »

It'd be something like:

cargo.removeItems(CargoAPI.CargoItemType.SPECIAL, new SpecialItemData(Items.MODSPEC, hullmod), count)
How can I modify this code to remove a specific wing LPC from the player's cargo?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6956 on: January 02, 2021, 11:47:48 AM »

Something like:
cargo.removeItems(CargoAPI.CargoItemType.FIGHTER_CHIP, wingId, count)
Logged

IonDragonX

  • Admiral
  • *****
  • Posts: 816
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6957 on: January 02, 2021, 12:23:34 PM »

Something like:
cargo.removeItems(CargoAPI.CargoItemType.FIGHTER_CHIP, wingId, count)
Thank You Very Much!!! I'm 90% there.
Where can I place this call so it will run whenever a Hullmod is removed? Or maybe somewhere else like where a wing is dropped out of a bay during Refit?
Logged

shoi

  • Admiral
  • *****
  • Posts: 658
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6958 on: January 02, 2021, 05:33:22 PM »

Is there any plan to add something to API that allows us to pass an arbitrary amount of time?

I feel like this was asked before, and you said it'd be a pain to do, but I can't seem to find where so I don't know if im imagining things
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6959 on: January 02, 2021, 05:59:33 PM »

Thank You Very Much!!! I'm 90% there.
Where can I place this call so it will run whenever a Hullmod is removed? Or maybe somewhere else like where a wing is dropped out of a bay during Refit?

Ah, but that's the hard part! Offhand I'm not sure that there are good places to do that.

Is there any plan to add something to API that allows us to pass an arbitrary amount of time?

I feel like this was asked before, and you said it'd be a pain to do, but I can't seem to find where so I don't know if im imagining things

No plans for that, no. It's not easily doable.
Logged
Pages: 1 ... 462 463 [464] 465 466 ... 710