Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Nekora

Pages: [1] 2
1
Nice catch thereEnder nerd code, didnt even see that one. Okay heres another, trying to make a shot bounce off sheilds. i can spawn the shots by this:
Code
		if (shieldHit && target instanceof ShipAPI)
{
float angle = ((float) Math.random() * 360f) - 180f;
engine.spawnProjectile(projectile.getSource(), projectile.getWeapon(),
projectile.getWeapon().getId(), point, angle, null);
}
Now i know that i can get the location of the projectile by useing "point" and i can get the location or the target by useing target.getLocation(), but can anyone show me how to calculate the angle from point to target.getLocation()? Im asumeing theres trig involved >_<

2
Sometesting of the code shows that
Code
            particleVelocity.x = ((float) Math.random() * 10f); //give the particle a random velocity.
            particleVelocity.y = ((float) Math.random() * 10f); //Math.random() results in a number between 0.0 and 1.0

are causeing the problems. As for the corect code? not sure ill look into it.
Oh also the damage spawning line of code, you had "engine" as the source of the damage. I changed that to projectile.getSource(), dont know if that has any relevance though as it didnt fix the problem till i got rid of the .x .y lines of code.

EDIT*
After some testing i got the code to work... as for why? i dont know. Maybe its because i set up the particalVelocity vairable useing getVelocity()... not idea. Well:

heres what i used that worked without error:
Code
package data.scripts.weapons;

import java.awt.Color;

import org.lwjgl.util.vector.Vector2f;

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.DamagingProjectileAPI;
import com.fs.starfarer.api.combat.OnHitEffectPlugin;
import com.fs.starfarer.api.combat.ShipAPI;

public class ExtraHitEffect implements OnHitEffectPlugin {

public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target, Vector2f point, boolean shieldHit, CombatEngineAPI engine) {
if (!shieldHit && target instanceof ShipAPI)
{
//set vairables for the partical. Could do inside the call but will do it here
float particleSize = 15f;
float particleBrightness = 1f;
float particleDuration = 2f;
Color particleColor = new Color(85, 25, 215, 255);
Vector2f particleVelocity = projectile.getVelocity(); // Lines below were causing issues, so i replaced them for testing
                        particleVelocity.x = ((float) Math.random() * 10f); //give the particle a random velocity.
                        particleVelocity.y = ((float) Math.random() * 10f); //Math.random() results in a number between 0.0 and 1.0

//set damage vairables
float damageAmount = projectile.getDamageAmount() * .25f; //extra damage is 1/4 of full
float empAmount = projectile.getEmpAmount(); //extra emp is... well full amount of normal hit

engine.applyDamage(target, point, damageAmount, DamageType.ENERGY, empAmount, false, false, projectile.getSource());
                        engine.addHitParticle(point, particleVelocity, particleSize, particleBrightness, particleDuration, particleColor);
//soundToPlay.playSound(soundName, pitch, volume, point, particleVelocity);
}
}
}

Also, anyone able to take a look at my question earlier yet? http://fractalsoftworks.com/forum/index.php?topic=5061.msg85513#msg85513

3
Modding / Re: Example Code Request: spawnEmpArc()
« on: January 22, 2013, 07:51:23 AM »
Thanks again wizard, that worked perfectly.

heres my proof of concept code:
Code
package data.scripts.weapons;

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 java.util.*;
import org.lwjgl.util.vector.Vector2f;

public class CascadeChainLightningEffect implements BeamEffectPlugin
{
    private static final boolean IGNORE_SAME_SHIP_IN_BURST = true; // If true, don't hit the same ship twice in the same burst
    private static final boolean PICK_RANDOM_ENEMY_IN_RANGE = false; // If true, pick a random enemy in range to be the next link in the chain
    private static final float TIME_BETWEEN_BURSTS = .3f; // How long must the beam be fired for before it will start a second chain?
    private static final float INITIAL_CHAIN_RANGE = 200f; // How far can the initial chain travel to hit an enemy?
    private static final float RANGE_RETENTION_PER_CHAIN = .90f; // How much of its previous max length will each chain retain?
    private static final float DAMAGE_RETENTION_PER_CHAIN = .85f; // How much damage will each chain do, compared to the previous?
    private static final int MAXIMUM_CHAINS_PER_BURST = 10; // How many chains should we limit the weapon to generating?
    private static final Color CORE_COLOR = new Color(255, 255, 255, 255); // What color is the core of the arc?
    private static final Color FRINGE_COLOR = new Color(215, 25, 25, 255); // What color is the fringe of the arc?
    private IntervalUtil fireInterval = new IntervalUtil(TIME_BETWEEN_BURSTS, TIME_BETWEEN_BURSTS);

private static final float baseglow = 10f; //base arc glow
private float heldTime = 0f; //How long have we been fireing the beam.
private CombatEntityAPI lastHit = null; //The last target we hit.

    private static float getDistance(Vector2f point1, Vector2f point2)
    {
        return (float) Math.hypot(point1.x - point2.x, point1.y - point2.y);
    }

    private static List getEnemiesInRange(CombatEntityAPI ship, float range,
            int side, CombatEngineAPI engine)
    {
        List enemies = new ArrayList(), allShips = engine.getShips();
        ShipAPI tmp;

        // Iterate through all ships on the battlefield
        for (int x = 0; x < allShips.size(); x++)
        {
            tmp = (ShipAPI) allShips.get(x);

            // Filter through and find active enemies that are within range
            if (!tmp.isHulk() && !tmp.isShuttlePod() && ship.getOwner() != side
                    && getDistance(ship.getLocation(), tmp.getLocation()) <= range)
            {
                enemies.add(tmp);
            }
        }

        return enemies;
    }

    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
    {
        CombatEntityAPI target = beam.getDamageTarget();

        // Check that we hit something and that it wasn't a shield hit
        //if (target != null && target instanceof ShipAPI
        //        && (target.getShield() == null || !target.getShield().isWithinArc(beam.getTo())))
//fudge that, Arc off shields
if (target != null && target instanceof ShipAPI)
        {
            fireInterval.advance(amount);
            if (fireInterval.intervalElapsed())
            {
//check if target hit is the same target
if (target == lastHit)
{
heldTime += amount;
}
else
{
lastHit = target;
heldTime = amount;
}

                // Count how many links are in the chain so far
                int numStrikes = 0;
                // Source of the current lightning chain
                Vector2f source = beam.getFrom();
                // Victim of the current lightning chain
                CombatEntityAPI currentVictim = target;
                // Emmitter of the current lightning chain
                CombatEntityAPI currentEmmiter = beam.getSource();


                float range = INITIAL_CHAIN_RANGE * heldTime;
                // Ensure we keep the same DPS as listed in the weapon's stats tooltip
                float damage = (beam.getWeapon().getDerivedStats().getDps()
                        * beam.getSource().getMutableStats().getBeamWeaponDamageMult().getModifiedValue()
                        * TIME_BETWEEN_BURSTS) * heldTime;
                float emp = (beam.getWeapon().getDerivedStats().getEmpPerSecond()
                        * TIME_BETWEEN_BURSTS) * heldTime;

float glow = baseglow * heldTime;

                // This is used to prevent hitting the same target twice
                // if IGNORE_SAME_SHIP_IN_BURST is set to true
                Set struck = new HashSet();

                do
                {
                    // Spawn this chain's lightning arc
                    engine.spawnEmpArc(beam.getSource(), source,
                                currentEmmiter, currentVictim,
                                DamageType.ENERGY, damage, emp, 100000f,
                                "tachyon_lance_emp_impact", glow,
                                FRINGE_COLOR, CORE_COLOR);

// Emmitter of the Next lightning chain is the target of this one
                    currentEmmiter = currentVictim;

                    // Check that we haven't hit our chain limit
                    if (++numStrikes >= MAXIMUM_CHAINS_PER_BURST)
                    {
                        return;
                    }

                    // Reduce the stats of the next chain
                    range *= RANGE_RETENTION_PER_CHAIN;
                    damage *= DAMAGE_RETENTION_PER_CHAIN;
                    emp *= DAMAGE_RETENTION_PER_CHAIN;

                    // Find our next victim
                    source = currentVictim.getLocation();
                    List enemies = getEnemiesInRange(currentVictim, range,
                            beam.getSource().getOwner(), engine);
                    enemies.remove(currentVictim);

                    // Remove enemies that have already been struck once
                    // (only if IGNORE_SAME_SHIP_IN_BURST is true)
                    if (IGNORE_SAME_SHIP_IN_BURST)
                    {
                        struck.add(currentVictim);
                        enemies.removeAll(struck);
                    }

                    // Remove enemies who would block or avoid a strike
                    ShipAPI tmp;
//Again... lets hit shields but not phazed
    for (Iterator iter = enemies.iterator(); iter.hasNext();)
                    {
                        tmp = (ShipAPI) iter.next();
                        if (tmp.getPhaseCloak() != null
                                && tmp.getPhaseCloak().isActive())
                        {
                            iter.remove();
                        }
                    }


                    // Pick a random valid enemy in range
                    if (!enemies.isEmpty())
                    {
                        if (PICK_RANDOM_ENEMY_IN_RANGE)
                        {
                            currentVictim = (ShipAPI) enemies.get((int) (Math.random() * enemies.size()));
                        }
                        else
                        {
                            ShipAPI closest = null;
                            float distance, closestDistance = Float.MAX_VALUE;

                            // Find the closest enemy in range
                            for (int x = 0; x < enemies.size(); x++)
                            {
                                tmp = (ShipAPI) enemies.get(x);

                                distance = getDistance(tmp.getLocation(),
                                        currentVictim.getLocation());
                                // This ship is closer than the previous best
                                if (distance < closestDistance)
                                {
                                    closest = tmp;
                                    closestDistance = distance;
                                }
                            }

                            currentVictim = closest;
                        }
                        // No enemies in range, end the chain
                    }
                    else
                    {
                        currentVictim = null;
                    }
                }
                while (currentVictim != null);
            }
        }
    }
}

Although i have knoticed the chain will arc to the fireing ship for some reason... odd

4
Regarding the spawnEmpArc() the notes say that you can target this to a specific location by passing in a custom class as the combatentity target: "@param empTargetEntity Target of the EMP arc. If it's a ship, it will randomly pick an engine nozzle/weapon to arc to. Can also pass in a custom class implementing CombatEntityAPI to visually target the EMP at a specific location (and not do any damage)."

Does anyone know a way to do this?

I was thinking allong the lines of useing addSmoothParticle(beam.getTo(), target.getVelocity(), 1f, 0f, .5f, CORE_COLOR); to create a teporary entity to target but couldnt get this to work >_<


5
Modding / Re: Example Code Request: spawnEmpArc()
« on: January 21, 2013, 03:15:07 PM »
Oh, another question. Is there a way to count how long a beam has been held onto a target? I want to make the chain lightning arc more times the longer a beam is held on a single target.

Guess i would need a way of makeing a global tag to check if the target is the same as the last and then if it is incrament the counter, if not reset it... no idea how to do that though? can we attatch infromation to the beam emmiter entity?

6
Modding / Re: Community Mod 2
« on: January 19, 2013, 02:57:59 PM »
Okay, I think I got the infection system to a point where it's visually pleasing, though I still don't have a massive amount of separate graphics.



I added four 128x128 overlays, as well as three 64x64 overlays.

Oh man, i cant wait to see this in action. As for the infection beam, take a look at LazyWizards Chain lightning code :D get that beam to bounce :D

7
both BALLISTIC_AS_BEAM and BALLISTIC work normaly, however PLASMA does not seem to use ohHitEffect

8
Modding / Re: Example Code Request: spawnEmpArc()
« on: January 19, 2013, 02:28:16 PM »
ugh, just spent a few hours trying to get a ball lighting aoe weapon to work, turns out "spawnType":"PLASMA" does not alow onhiteffects... damnit...

well incase you are intrested in what i came up with:
Code
package data.scripts.weapons;

import java.awt.Color;

import org.lwjgl.util.vector.Vector2f;

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.DamagingProjectileAPI;
import com.fs.starfarer.api.combat.OnHitEffectPlugin;
import com.fs.starfarer.api.combat.ShipAPI;


import com.fs.starfarer.api.util.IntervalUtil;
import java.util.*;

public class LightningAOEHitEffect implements OnHitEffectPlugin {

//Based on LazyWizard's chain lightning code.


    private static final boolean IGNORE_SAME_SHIP_IN_BURST = true; // If true, don't hit the same ship twice in the same burst
    private static final boolean PICK_RANDOM_ENEMY_IN_RANGE = true; // If true, pick a random enemy in range to be the next hit in the burst
    private static final float RANGE_MOD = 1.5f; // Range of aoe * damage
    private static final int MAXIMUM_CHAINS_PER_BURST = 5; // How many chains should we limit the weapon to generating?
    private static final Color CORE_COLOR = new Color(255, 255, 255, 255); // What color is the core of the arc?
    private static final Color FRINGE_COLOR = new Color(85, 25, 215, 255); // What color is the fringe of the arc?

private static float getDistance(Vector2f point1, Vector2f point2)
    {
        return (float) Math.hypot(point1.x - point2.x, point1.y - point2.y);
    }

private static List getEnemiesInRange(CombatEntityAPI ship, float range, int side, CombatEngineAPI engine)
    {
        List enemies = new ArrayList(), allShips = engine.getShips();
        ShipAPI tmp;
        // Iterate through all ships on the battlefield
        for (int x = 0; x < allShips.size(); x++)
        {
            tmp = (ShipAPI) allShips.get(x);

            // Filter through and find active enemies that are within range
            if (!tmp.isHulk() && !tmp.isShuttlePod() && ship.getOwner() != side
                    && getDistance(ship.getLocation(), tmp.getLocation()) <= range)
            {
                enemies.add(tmp);
            }
        }

        return enemies;
    }



public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target, Vector2f point, boolean shieldHit, CombatEngineAPI engine)
{
//did we hit a ship?
if (target instanceof ShipAPI)
{

//damage is 1/4 of original hit
float emp = projectile.getEmpAmount() * .25f;
float damage = projectile.getDamageAmount() * .25f;
float range = projectile.getDamageAmount() * RANGE_MOD;
//float range = 1000f;

// Count how many links are in the chain so far
            int numStrikes = 0;

            // Victim of the current lightning chain
            CombatEntityAPI currentVictim = target;
               
            // This is used to prevent hitting the same target twice
            // if IGNORE_SAME_SHIP_IN_BURST is set to true
            Set struck = new HashSet();

do
            {
// Spawn this chain's lightning arc
                engine.spawnEmpArc(projectile.getSource(), point, projectile, currentVictim,
                                DamageType.ENERGY, damage, emp, 100000f,
                                "tachyon_lance_emp_impact", 15f,
                                FRINGE_COLOR, CORE_COLOR);

// Check that we haven't hit our chain limit
                if (++numStrikes >= MAXIMUM_CHAINS_PER_BURST)
                   {
                        return;
                   }

                // Find our next victim
                List enemies = getEnemiesInRange(currentVictim, range, projectile.getSource().getOwner(), engine);
                enemies.remove(currentVictim);

                // Remove enemies that have already been struck once
                // (only if IGNORE_SAME_SHIP_IN_BURST is true)
                if (IGNORE_SAME_SHIP_IN_BURST)
                {
struck.add(currentVictim);
                    enemies.removeAll(struck);
                }

                // Remove enemies who would block or avoid a strike
                ShipAPI tmp;
                for (Iterator iter = enemies.iterator(); iter.hasNext();)
                {
tmp = (ShipAPI) iter.next();
                    if (tmp.getPhaseCloak() != null && tmp.getPhaseCloak().isActive())
                    {
iter.remove();
                    }
                }

                // Pick a random valid enemy in range
                if (!enemies.isEmpty())
                {
if (PICK_RANDOM_ENEMY_IN_RANGE)
                    {
currentVictim = (ShipAPI) enemies.get((int) (Math.random() * enemies.size()));
                    }
                    else
                    {
ShipAPI closest = null;
                        float distance, closestDistance = Float.MAX_VALUE;

// Find the closest enemy in range
for (int x = 0; x < enemies.size(); x++)
{
tmp = (ShipAPI) enemies.get(x);

distance = getDistance(tmp.getLocation(), currentVictim.getLocation());

// This ship is closer than the previous best
if (distance < closestDistance)
{
closest = tmp;
closestDistance = distance;
}
}
                    currentVictim = closest;
                    }
                    // No enemies in range, end the chain
                }
                else
                {
                    currentVictim = null;
                }
            }
            while (currentVictim != null);
}
}
}

9
Modding / Re: The Code Foundry
« on: January 19, 2013, 11:52:47 AM »
Do you call the script at: data.scripts.plugins.RotatingDish? Because thats where its package points at.

According to your error log, you call it at data/scripts/weapons/.

damnit, i missed the package data.scripts.weapons; Thanks Romeo_One

10
Modding / Re: The Code Foundry
« on: January 18, 2013, 11:05:14 PM »
Hey, the Rotating dish does not work.

I get the following error.

Caused by: org.codehaus.commons.compiler.CompileException: Source file "data/scripts/weapons/RotatingDish.java" does not declare class "data.scripts.weapons.RotatingDish"

11
Modding / Re: Example Code Request: spawnEmpArc()
« on: January 18, 2013, 12:44:17 PM »
Hmm, quick tweak to LazyWizards code, Ancoring the arc to the emmiter looks much better so add the following lines to do so...
After the line of code "CombatEntityAPI currentVictim = target;" add this:
Code
CombatEntityAPI currentEmmiter = beam.getSource();	// Emmitter of the Next lightning chain is the target of this one

and change the "engine.spawnEmpArc" to:
Code
// Spawn this chain's lightning arc
engine.spawnEmpArc(beam.getSource(), source,
          currentEmmiter, currentVictim,
          DamageType.ENERGY, damage, emp, 100000f,
          "tachyon_lance_emp_impact", 15f,
          FRINGE_COLOR, CORE_COLOR);

currentEmmiter = currentVictim; // Emmitter of the Next lightning chain is the target of this one

Just makes it look a bit nicer thats all.

Should look like this:
Spoiler
Code
package data.scripts.weapons;

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 java.util.*;
import org.lwjgl.util.vector.Vector2f;

public class ChainLightningEffect implements BeamEffectPlugin
{
    // If true, don't hit the same ship twice in the same burst
    private static final boolean IGNORE_SAME_SHIP_IN_BURST = true;
    // If true, pick a random enemy in range to be the next link in the chain
    private static final boolean PICK_RANDOM_ENEMY_IN_RANGE = false;
    // How long must the beam be fired for before it will start a second chain?
    private static final float TIME_BETWEEN_BURSTS = .2f;
    // How far can the initial chain travel to hit an enemy?
    private static final float INITIAL_CHAIN_RANGE = 1000f;
    // How much of its previous max length will each chain retain?
    private static final float RANGE_RETENTION_PER_CHAIN = .90f;
    // How much damage will each chain do, compared to the previous?
    private static final float DAMAGE_RETENTION_PER_CHAIN = .85f;
    // How many chains should we limit the weapon to generating?
    private static final int MAXIMUM_CHAINS_PER_BURST = 5;
    // What color is the core of the arc?
    private static final Color CORE_COLOR = new Color(255, 255, 255, 255);
    // What color is the fringe of the arc?
    private static final Color FRINGE_COLOR = new Color(85, 25, 215, 255);
    private IntervalUtil fireInterval = new IntervalUtil(TIME_BETWEEN_BURSTS, TIME_BETWEEN_BURSTS);

    private static float getDistance(Vector2f point1, Vector2f point2)
    {
        return (float) Math.hypot(point1.x - point2.x, point1.y - point2.y);
    }

    private static List getEnemiesInRange(CombatEntityAPI ship, float range,
            int side, CombatEngineAPI engine)
    {
        List enemies = new ArrayList(), allShips = engine.getShips();
        ShipAPI tmp;

        // Iterate through all ships on the battlefield
        for (int x = 0; x < allShips.size(); x++)
        {
            tmp = (ShipAPI) allShips.get(x);

            // Filter through and find active enemies that are within range
            if (!tmp.isHulk() && !tmp.isShuttlePod() && ship.getOwner() != side
                    && getDistance(ship.getLocation(), tmp.getLocation()) <= range)
            {
                enemies.add(tmp);
            }
        }

        return enemies;
    }

    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
    {
        CombatEntityAPI target = beam.getDamageTarget();

        // Check that we hit something and that it wasn't a shield hit
        //if (target != null && target instanceof ShipAPI
        //        && (target.getShield() == null || !target.getShield().isWithinArc(beam.getTo())))
//fudge that, Arc off shields
if (target != null && target instanceof ShipAPI)
        {
            if (beam.getBrightness() >= 1f)
            {
                fireInterval.advance(amount);
                if (fireInterval.intervalElapsed())
                {
                    // Count how many links are in the chain so far
                    int numStrikes = 0;

                    // Source of the current lightning chain
                    Vector2f source = beam.getFrom();
                    // Victim of the current lightning chain
                    CombatEntityAPI currentVictim = target;
                    // Emmitter of the current lightning chain
                    CombatEntityAPI currentEmmiter = beam.getSource();


                    float range = INITIAL_CHAIN_RANGE;
                    // Ensure we keep the same DPS as listed in the weapon's stats tooltip
                    float damage = beam.getWeapon().getDerivedStats().getDps()
                            * beam.getSource().getMutableStats().getBeamWeaponDamageMult().getModifiedValue()
                            * TIME_BETWEEN_BURSTS;
                    float emp = beam.getWeapon().getDerivedStats().getEmpPerSecond()
                            * TIME_BETWEEN_BURSTS;

                    // This is used to prevent hitting the same target twice
                    // if IGNORE_SAME_SHIP_IN_BURST is set to true
                    Set struck = new HashSet();

                    do
                    {
                        // Spawn this chain's lightning arc
                        engine.spawnEmpArc(beam.getSource(), source,
                                currentEmmiter, currentVictim,
                                DamageType.ENERGY, damage, emp, 100000f,
                                "tachyon_lance_emp_impact", 15f,
                                FRINGE_COLOR, CORE_COLOR);

// Emmitter of the Next lightning chain is the target of this one
                        currentEmmiter = currentVictim;

                        // Check that we haven't hit our chain limit
                        if (++numStrikes >= MAXIMUM_CHAINS_PER_BURST)
                        {
                            return;
                        }

                        // Reduce the stats of the next chain
                        range *= RANGE_RETENTION_PER_CHAIN;
                        damage *= DAMAGE_RETENTION_PER_CHAIN;
                        emp *= DAMAGE_RETENTION_PER_CHAIN;

                        // Find our next victim
                        source = currentVictim.getLocation();
                        List enemies = getEnemiesInRange(currentVictim, range,
                                beam.getSource().getOwner(), engine);
                        enemies.remove(currentVictim);

                        // Remove enemies that have already been struck once
                        // (only if IGNORE_SAME_SHIP_IN_BURST is true)
                        if (IGNORE_SAME_SHIP_IN_BURST)
                        {
                            struck.add(currentVictim);
                            enemies.removeAll(struck);
                        }

                        // Remove enemies who would block or avoid a strike
                        ShipAPI tmp;
                        //for (Iterator iter = enemies.iterator(); iter.hasNext();)
                        //{
                        //    tmp = (ShipAPI) iter.next();
                        //    if ((tmp.getShield() != null && tmp.getShield().isOn()
                        //            && tmp.getShield().isWithinArc(source))
                        //            || (tmp.getPhaseCloak() != null
                        //            && tmp.getPhaseCloak().isActive()))
                        //    {
                        //        iter.remove();
                        //    }
                        //}
//Again... lets hit shields but not phazed
for (Iterator iter = enemies.iterator(); iter.hasNext();)
                        {
                            tmp = (ShipAPI) iter.next();
                            if (tmp.getPhaseCloak() != null
                                    && tmp.getPhaseCloak().isActive())
                            {
                                iter.remove();
                            }
                        }


                        // Pick a random valid enemy in range
                        if (!enemies.isEmpty())
                        {
                            if (PICK_RANDOM_ENEMY_IN_RANGE)
                            {
                                currentVictim = (ShipAPI) enemies.get((int) (Math.random() * enemies.size()));
                            }
                            else
                            {
                                ShipAPI closest = null;
                                float distance, closestDistance = Float.MAX_VALUE;

                                // Find the closest enemy in range
                                for (int x = 0; x < enemies.size(); x++)
                                {
                                    tmp = (ShipAPI) enemies.get(x);

                                    distance = getDistance(tmp.getLocation(),
                                            currentVictim.getLocation());

                                    // This ship is closer than the previous best
                                    if (distance < closestDistance)
                                    {
                                        closest = tmp;
                                        closestDistance = distance;
                                    }
                                }

                                currentVictim = closest;
                            }
                            // No enemies in range, end the chain
                        }
                        else
                        {
                            currentVictim = null;
                        }
                    }
                    while (currentVictim != null);
                }
            }
        }
    }
}
[close]

12
Modding / Re: Example Code Request: spawnEmpArc()
« on: January 18, 2013, 12:00:47 PM »
this will work for that. With a few tweaks, let me look at it for ya...

and done, well that was easy enough, just modified the awesome code from LazyWizard... Also changed the anchor point as it looked silly ancoring to the target... well i thought it did. Anyway:
Code
package data.scripts.weapons;

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 java.util.*;
import org.lwjgl.util.vector.Vector2f;

public class LightningStrikeEffect implements BeamEffectPlugin
{
    private static final float TIME_BETWEEN_BURSTS = .1f;    // How long between each discharge
    private static final Color CORE_COLOR = new Color(255, 255, 255, 255);// What color is the core of the arc?
    private static final Color FRINGE_COLOR = new Color(85, 25, 215, 255);// What color is the fringe of the arc?
    private IntervalUtil fireInterval = new IntervalUtil(TIME_BETWEEN_BURSTS, TIME_BETWEEN_BURSTS);

    @Override //i have no idea what this does
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
    {
        CombatEntityAPI target = beam.getDamageTarget();
        // Check that we hit something, modified to arc to shields
        if (target != null && target instanceof ShipAPI)
        {
//Only activate if beam is at full power (beam charge up time)
            if (beam.getBrightness() >= 1f)
            {
                fireInterval.advance(amount);
                if (fireInterval.intervalElapsed())
                {
                    // Source of the current lightning chain
                    Vector2f source = beam.getFrom();
                    // Victim of the current lightning chain
                    CombatEntityAPI currentVictim = target;
                    // Ensure we keep the same DPS as listed in the weapon's stats tooltip
                    float damage = beam.getWeapon().getDerivedStats().getDps()
                            * beam.getSource().getMutableStats().getBeamWeaponDamageMult().getModifiedValue()
                            * TIME_BETWEEN_BURSTS;
                    float emp = beam.getWeapon().getDerivedStats().getEmpPerSecond()
                            * TIME_BETWEEN_BURSTS;

// Spawn lightning strike
                    engine.spawnEmpArc(beam.getSource(), source,
                                beam.getSource(), currentVictim,
                                DamageType.ENERGY, damage, emp, 100000f,
                                "tachyon_lance_emp_impact", 15f,
                                FRINGE_COLOR, CORE_COLOR);
                }
            }
        }
    }
}

BTW anyone know what does the "@overide" Does?

13
Modding / Re: Example Code Request: spawnEmpArc()
« on: January 17, 2013, 05:08:25 PM »
Just save the code I posted as ChainLightningEffect.java in the data/scripts/weapons/ folder. Then open the weapon file of the beam you want to use this effect and add this line:
Code
"beamEffect":"data.scripts.weapons.ChainLightningEffect",

would you beleve i had / instead of . in the effect refrence field >_< thank, i have no idea why i made that mistake.

14
Modding / Re: Example Code Request: spawnEmpArc()
« on: January 17, 2013, 04:44:44 PM »
Here's the code for a beam that creates a chain lightning effect. I tried to keep it easy to customize. :)

Thanks for the quick work there, however when i try to implement this i keep getting an obscure error, obviously im doing something wrong. Ive done a quick search but couldnt find a guide on how to add custom weapon effects to a mod, So i need to compile this to a class file and add it to the api Jar?

15
Modding / Re: Example Code Request: spawnEmpArc()
« on: January 17, 2013, 01:41:18 PM »
ah, so useing a function similar to the one psion did in his efffects?
Code
		List ships = engine.getAllShips();	
Iterator it = ships.iterator();
while (it.hasNext()) {
//* range checking here, pass inrantge ships into a Target vairable
}

Also it occours to me, to make a beamweapon with a lightning emp effect, couldnt we make an invisible beam weapon and give it the emp effect, but set the spawn point of the emp effect to the beam weapon emmitter? heck even haveing a faint beam that carrys the lightning would look cool. sort of like an ion beam that carrys the electric charge from your ship to the target so the lightning only shows when there is a valid target for the electricity to ground itself to (ie the beam hits something)... hmm, will have to check how to pull the emmiter location from the beam as that would look epic.

Edit: wait, is it as simple as beam.getFrom()? gona test this

Pages: [1] 2