Does anyone know of a way to give a weapon the ability to temporarily disable enemy shields (Like a malfunction)? I'm looking to make a weapon that has a small chance to apply some catastrophic effect like one of the three major malfunctions (Engine, shield, weapon) to a target ship. I know how to increase the chance of those things happening to a ship, simply mutable stats, however I'm not sure how I would go about that with an on hit script. I'm not asking anyone to make me anything, but if anyone has any ideas I'd be very appreciative of a nudge in one direction or another.
The
Star Wars mod had a combat plugin that could disable shields temporarily. That might be a good base for what you're trying to do.
If I remember correctly, it did have a problem resetting shield upkeep cost when it re-enabled shields. It actually worked by removing the shield from your ship for the duration then adding a new, identical one once the timer was up, but the API at the time couldn't retrieve shield upkeep so that wasn't stored.
Can someone please explain to me the IntervalUtil class and how it relates to the combat engine and frames? Some examples would be greatly appreciated.
It's pretty simple once you get a handle on it. It's actually not based on the combat engine or frames or even time. This is because it doesn't advance on its own, you call its advance() method manually with the amount to advance by. While this is usually the time since the last frame, it doesn't
have to be. You could just as easily use an IntervalUtil to keep track of how many times you fired a weapon for creating a special effect that only happens every <x> shots.
So, a basic example. Let's go with a common use, having an event happen occasionally during battle. Say you defined a new IntervalUtil with
IntervalUtil example = new IntervalUtil(30f, 50f);
And in an EveryFrameCombatPlugin's advance(), you call
example's advance() method with the time since last frame.
In this case, a random target number would be chosen between 30 and 50. When the total amount passed into this IntervalUtil's advance() method reaches that target, a few things happen:
- intervalElapsed() will return true until you call advance() again (so make sure you check intervalElapsed() every time you call advance())
- The target number will be reset to a new random number in the range you provided
- The interval starts counting from 0 again
Here's a full example that shows a message every 30-50 seconds:
package data.scripts.plugins;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
import com.fs.starfarer.api.util.IntervalUtil;
import java.awt.Color;
import java.util.List;
public class IntervalUtilExample implements EveryFrameCombatPlugin
{
// Used to have an event occur every 30-50 seconds
// The 'target' interval will be randomly chosen between these two
// numbers every time the IntervalUtil starts a new interval
private final IntervalUtil exampleInterval = new IntervalUtil(30f, 50f);
private CombatEngineAPI engine;
@Override
public void advance(float amount, List events)
{
// Advances the IntervalUtil by much time has passed since last frame
exampleInterval.advance(amount);
// Checks if the IntervalUtil has hit its target - will only be true for a single frame
// Check this EVERY time you call advance(), otherwise you can miss elapsed events
if (exampleInterval.intervalElapsed())
{
// Show a message every 30-50 seconds
engine.addFloatingText(engine.getViewport().getCenter(),
"Interval elapsed!", 50f, Color.CYAN,
null, 0f, 0f);
// After the interval has elapsed, IntervalUtil will automatically reset
// and choose a new random target in the range you provided
// You can change the IntevalUtil's target range using the following:
//exampleInterval.setInterval(20f, 60f);
}
}
@Override
public void init(CombatEngineAPI engine)
{
this.engine = engine;
}
}
There are a few other methods you can mess with once you've got the basics down, but that's all you really need to know. The full source for IntervalUtil is included in starfarer.api.zip in starsector-core. It's in com/fs/starfarer/api/util/IntervalUtil.java.