Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 457 458 [459] 460 461

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

Arngrim

  • Ensign
  • *
  • Posts: 2
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6870 on: October 22, 2020, 04:16:31 PM »

Hey, I was wondering if it´s possible to make animated projectiles? Let´s say the projectile is a circle and I want to make it rotate as it travels.
Logged

PureTilt

  • Ensign
  • *
  • Posts: 8
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6871 on: October 26, 2020, 05:07:06 AM »

i want to make option to change portrait mid game, is it possible to use portrait picking window from new game menu?
Logged


Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17240
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6872 on: October 26, 2020, 03:07:41 PM »

weapon.getCooldownRemaining() works fine normally, but when  I use it to check cooldown time is 0 on something under some type of time mod (say temporal shell) it starts firing off inconsistently. Is there something extra I need to do for those cases?

(Sorry for the delay!)

Hmm, that's not really enough info. What's "inconsistently", vs what are your expectations? It would also help to see your code - or, rather, a minimal snippet that produces the behavior.


Hey, I was wondering if it´s possible to make animated projectiles? Let´s say the projectile is a circle and I want to make it rotate as it travels.

It's possible, but the details... I'm not 100% sure on off the top of my head, maybe someone more versed in modding this stuff in can chime in. The good news is it'll be significantly easier in the next release - there are plugins more or less explicitly for that sort of thing.


i want to make option to change portrait mid game, is it possible to use portrait picking window from new game menu?

I don't think this is exposed via the API, no. You'd have to code up a custom selector - doable (see: com.fs.starfarer.api.impl.campaign.ExampleCustomUIPanel), but some work.


What are the odds of having a `beforeGameLoad` hook added to `ModPlugin`?

The use case I'm thinking of is detecting save-breaking mod updates and showing an user-friendly message before the save file is deserialized and blows up.

The game already shows a "mod compatibility warning" when you try to load the game (I'm not 100% sure if this is in 0.9.1a, actually), and will also show the saved with/current versions for all the mods involved in the save game's tooltip, so I think this should be covered?
Logged

shoi

  • Commander
  • ***
  • Posts: 157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6873 on: October 26, 2020, 03:43:45 PM »



(Sorry for the delay!)

Hmm, that's not really enough info. What's "inconsistently", vs what are your expectations? It would also help to see your code - or, rather, a minimal snippet that produces the behavior.



Hi, and no worries! Here's a video of what im talking about https://imgur.com/a/9OSiZ7e
You can see the first time I shoot, I think all the bullets spawn correctly. But the next time I use the system, only one bullet is spawned in while firing.

So I have a weapon that fires a burst of 8 shots. The ship this issue is on has a system that replaces these shots with a stronger version of them.
To prevent bullets appearing when they shouldn't, I added (if(weapon.getCooldownRemaining() <= 0)) as a condition, which works flawlessly..or almost always, anyway. BUT when time dilation effect is active, sometimes bullets will spawn, and sometimes they wont.

Puretilt actually helped me with this, because he had a similar issue, and well, I will post my code, and then the conclusion he came to. This is in an every frame weapon effect script.
Code: java
				

    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {


for (DamagingProjectileAPI proj : engine.getProjectiles())
{
//if this is one of our projectiles and hasn't been accounted for
if (weapon == proj.getWeapon() && !registeredProjectiles.contains(proj) && !explodingProjectiles.contains(proj))
{
//add it (prevent infinite bullet works)
registeredProjectiles.add(proj);

//If the weapon can actually fire
if(weapon.getCooldownRemaining() <= 0)
{
FluxTrackerAPI fluxLevel = weapon.getShip().getFluxTracker();
//Spawn the new projectile
DamagingProjectileAPI newProj = (DamagingProjectileAPI) engine.spawnProjectile(ship, weapon, "armaa_einhanderGun2", proj.getLocation(), proj.getFacing(), ship.getVelocity());

if(fluxLevel.getCurrFlux()+weapon.getFluxCostToFire() > fluxLevel.getMaxFlux())
{
fluxLevel.forceOverload(0f);
}

else
fluxLevel.setCurrFlux(fluxLevel.getCurrFlux()+weapon.getFluxCostToFire());

//ad the new proj for fx stuff later
explodingProjectiles.add(newProj);
Global.getSoundPlayer().playSound("plasma_cannon_fire", 1f, 0.7f, newProj.getLocation(), newProj.getVelocity());
}
//remove old bullet
Global.getCombatEngine().removeEntity(proj);
}
}
}


I don't 100% remember the specifics of the issue now, but it seemed like there is a delay with spawning bullets under time dilation? What tilt did was add a 2 frame delay to his script, which fixed his issue, but I just disabled being able to use this specific ships right click to get around it for the time being
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17240
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6874 on: October 26, 2020, 03:57:43 PM »

Ah, ok - yeah, the conclusion makes sense. Fast-time ships will advance() several times in a row without the rest of the engine advancing, so stuff like adding/removing projectiles might not get processed if it's done in a system script for a ship that's in fast-time. I forget the details - they're hairy - but, yeah, this doesn't sound unreasonable.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17240
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6875 on: October 27, 2020, 08:04:02 AM »

(I split the more suggestion-themed discussion regarding mod versioning into a separate thread.)
Logged

shoi

  • Commander
  • ***
  • Posts: 157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6876 on: October 27, 2020, 09:15:25 PM »

Thanks!

I noticed fighters will sometimes leave behind a hulk like disabled ships, or straight out be vaporized.
Is there any way to make them always become hulks/husks?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17240
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6877 on: October 28, 2020, 10:23:28 AM »

Ah, there isn't, sorry! It's hardcoded to 50% for fighters.
Logged

Jaghaimo

  • Commander
  • ***
  • Posts: 110
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6878 on: October 28, 2020, 11:52:38 AM »

Is there a way to get the intersection of two CargoAPI objects easily? Right now I use brute force and go over each cargo stack in both CargoAPIs, check if it's the same item, take one stack, and adjust size to min of the two sizes.

I could also use mathematical approach (pseudocode, for simplicity assume it returns new CargoAPI, in actuality would need to use to multiple copies):
Code
aLessB = cargoA.removeAll(cargoB);// left side of union
bLessA = cargoB.removeAll(cargoA);// right side of union
aPlusB = cargoA.addAll(cargoB);// union
intersection = aPlusB.removeAll(aLessB).removeAll(bLessA);// center of union, intersection, but need to accommodate for duplicates (stacks have sizes which mutate due to addAll/removeAll, lets treat them as duplicates), every stack needs to be halfed (got napkin math to cover that)
Actual quantity in intersection is: in bLessA: max(0, qB - qA), in aLessB: max(0, qA - qB), in aPlusB: qA + qB, in intersection: qA + qB - max(0, qB - qA) - max(0, qA - qB), solve for A > B, A < B, A = B) to see quantity is doubled in each case.

Edit: Actual Java code doesn't seem too terrible:
Code
    public CargoAPI getCommonCargo(CargoAPI cargoA, CargoAPI cargoB) {
        CargoAPI aLessB = cargoA.createCopy();
        aLessB.removeAll(cargoB);
        CargoAPI bLessA = cargoB.createCopy();
        bLessA.removeAll(cargoA);
        CargoAPI intersection = cargoA.createCopy();
        intersection.addAll(cargoB);
        intersection.removeAll(aLessB);
        intersection.removeAll(bLessA);
        halveQuantities(intersection);
        return intersection;
    }

    private void halveQuantities(CargoAPI cargo) {
        for (CargoStackAPI cargoStack : cargo.getStacksCopy()) {
            float size = cargoStack.getSize();
            cargoStack.setSize(size / 2);
        }
    }
Even with having to create those copies this code is vastly simpler to what I actually ended up with (the two nested loops), it is even simpler than one helper function I use (below)! I worry about performance (and calls to addAll, removeAll) though.

Is there an easier way to check if two cargo stacks are the same item (disregarding quantities)? I stole this from Misc.isSameCargo():
Code
    private boolean isSameCargoStack(CargoStackAPI s1, CargoStackAPI s2) {
        if ((s1 == null || s2 == null) && s1 != s2) {
            return false;
        }
        if (s1.getType() != s2.getType()) {
            return false;
        }
        if ((s1.getData() == null || s2.getData() == null) && s1.getData() != s2.getData()) {
            return false;
        }
        if (!s1.getData().equals(s2.getData())) {
            return false;
        }
        return true;
    }
This one helper function is already comparable to the whole code using addAll/removeAll. Curious, how would you find the common part of two cargos?
« Last Edit: October 28, 2020, 02:04:57 PM by Jaghaimo »
Logged
Stellar Logistics - courier services
Hyperspace Network - information services

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17240
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6879 on: October 28, 2020, 12:50:13 PM »

What you're doing seems fine! Depending, might want to throw in a .sort() for each of the starting cargos; that'd - iirc - compress any multiple stacks of something into a single stack. (Careful if doing this to player cargo, since that'd also nuke any special custom stacking/ordering they might have done.)

I think the more important question, performance-wise, is whether worrying about the performance on this makes sense or not. For example, if this code runs in response to a UI interaction (i.e. inside some dialog or similar), then it likely doesn't matter. If it can run in the background while the player is flying around, then it might matter if the cargo size could be pretty large or you need to do this a lot for some reason, but if not, then again it probably doesn't matter how optimized that is.

Edit: regarding the "are the stacks the same" question, your code looks good to me. Are you concerned about performance or code length? The former seems like it'd be very good for this method, and the latter it doesn't seem like there's an easy/obvious way to cut down on it.
« Last Edit: October 28, 2020, 08:47:02 PM by Alex »
Logged

shoi

  • Commander
  • ***
  • Posts: 157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6880 on: October 28, 2020, 01:14:28 PM »

Ah, there isn't, sorry! It's hardcoded to 50% for fighters.

thanks  :'(
Logged

Sinosauropteryx

  • Commander
  • ***
  • Posts: 225
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6881 on: November 05, 2020, 11:09:29 AM »

What's the difference between getVisualBounds() and getExactBounds()?

Ah, there isn't, sorry! It's hardcoded to 50% for fighters.

thanks  :'(
I don't know if you've already tried this (I haven't) but if you turn a fighter into a frigate, or change its collision class, right as it dies, the hulk might stick around?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17240
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6882 on: November 05, 2020, 11:15:45 AM »

getExactBounds() is used for collisions. getVisualBounds() is used for rendering ship pieces after they've been split apart, the ship sprite is stenciled to an area defined by the bounds, weapons outside it are discarded, etc. I forget what the difference is in how the two are generated, but in terms of what they're for, that's it.
Logged

boogie

  • Ensign
  • *
  • Posts: 1
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6883 on: November 09, 2020, 02:11:57 PM »

Could anyone please give me a direction to dig infor this error?
I'm trying to run a basic ship mod following the wiki intro to modding guide. there should be nothing creating this.
Never mind I'm an actual idiot, I forgot to enable lazy lib with the console command mod for testing.
Code
12695 [Thread-4] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.RuntimeException: Failed to find script of class [com.fs.starfarer.api.impl.campaign.CoreLifecyclePluginImpl]
java.lang.RuntimeException: Failed to find script of class [com.fs.starfarer.api.impl.campaign.CoreLifecyclePluginImpl]
at com.fs.starfarer.loading.scripts.ScriptStore.new(Unknown Source)
at com.fs.starfarer.settings.StarfarerSettings.OO0000(Unknown Source)
at com.fs.starfarer.launcher.ModManager.getEnabledModPlugins(Unknown Source)
at com.fs.starfarer.loading.ResourceLoaderState.init(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
« Last Edit: November 09, 2020, 02:43:02 PM by boogie »
Logged

Krelian

  • Lieutenant
  • **
  • Posts: 59
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6884 on: November 09, 2020, 06:16:48 PM »

Hello. Just curious, are non-orignal mods (as in from popular culture) frowned upon on this comunity? I ask because there is a TON of awesome mods, but most impressive of all is that almost all of them are original ideas, besides the unavoidable starwars one, one from gundam iron brooded, and one from homeworld (that comes from the top of my mind). The "original" mod ratio is extremelly high; and with a game that is a perfect fit for a ton of popular culture sci-fy, I just cant but wonder why is that.

More to the point, I had been toying with the idea of implementing certain sci-fy I would like a lot to play with, but now I fear it could be rejected by the comunity because of my previous point.

Regards
Logged
Pages: 1 ... 457 458 [459] 460 461