Im having trouble getting a TractorBeam to work, its for the startreker mod, its suppose to be a borg weapon of doom that feeds on player tears, but right now its feeding on my tears
package data.scripts.plugins;
import com.fs.starfarer.api.combat.BeamAPI;
import com.fs.starfarer.api.combat.BeamEffectPlugin;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.DamageType;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import java.awt.Color;
import org.lwjgl.util.vector.Vector2f;
import org.lazywizard.lazylib.MathUtils;
public class TractorBeamEffect implements BeamEffectPlugin {
private CombatEntityAPI currentArc = null;
private IntervalUtil fireInterval = new IntervalUtil(0.2f, 0.3f);
public void advance(float amount, CombatEngineAPI engine, BeamAPI beam) {
if (currentArc != null) {
if (!engine.isEntityInPlay(currentArc)) {
currentArc = null;
}//if
}//if
CombatEntityAPI target = beam.getDamageTarget();
if (target != null && target instanceof ShipAPI && (target.getShield() == null || !target.getShield().isWithinArc(beam.getTo()))) {
if (beam.getBrightness() >= 1f) {
fireInterval.advance(amount);
if (fireInterval.intervalElapsed()) {
Vector2f dir = Vector2f.sub(beam.getTo(), beam.getFrom(), new Vector2f());
if (dir.lengthSquared() > 0) dir.normalise();
dir.scale(5f);
Vector2f point = Vector2f.sub(beam.getTo(), dir, new Vector2f());
float emp = beam.getWeapon().getDerivedStats().getBurstDamage() * .667f;
float dam = emp * 0.25f;
engine.spawnEmpArc(beam.getSource(), point, beam.getDamageTarget(), beam.getDamageTarget(),
//engine.spawnEmpArc(beam.getSource(), beam.getFrom(), beam.getSource(), beam.getDamageTarget(),
DamageType.ENERGY,
dam, // damage
emp, // emp
100000f, // max range
"tachyon_lance_emp_impact",
30f, // thickness
new Color(68,250,50,255),
new Color(212,255,192,255)
);
Vector2f velocity, direction;
float distance;
velocity = beam.getDamageTarget().getVelocity();
distance = MathUtils.getDistance(beam.getDamageTarget(), beam.getSource());
// Normalized directional vector
direction = MathUtils.getDirectionalVector(beam.getDamageTarget(), beam.getSource());
float strength = distance * 300f;
velocity.set(velocity.x + (direction.x * strength * amount), velocity.y + (direction.y * strength * 100f));
}//if
}//if
}//if
}//advance
}//class
Based on LazyWizard blackhole code and a copy of the tachyon lance vanila weapon effect.
It semi works, it not pulling but it stops a ship from moving, heres a sneak peak:
I still need to make a "weaker" version of it, based on hull sizes for the other factions, this one should not care what size the ship is, he will pull it in like it was nothing while getting emp dmg on it