Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: [1] 2 3 ... 6

Author Topic: Creating new Decorative "Weapons"  (Read 19706 times)

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Creating new Decorative "Weapons"
« on: January 05, 2013, 07:27:45 AM »

heres the sensordish.wpn currently in the Vanilla:

Code
{
"specClass":"beam",
"id":"sensordish",
"type":"DECORATIVE",
"size":"SMALL",
"everyFrameEffect":"com.fs.starfarer.api.impl.combat.SensorDishRotationEffect",
"turretSprite":"graphics/weapons/decorative/sensor_array_dish.png",
"hardpointSprite":"graphics/weapons/decorative/sensor_array_dish.png",
"turretOffsets":[10, 0],
"turretAngleOffsets":[0],
"hardpointOffsets":[15, 0],
"hardpointAngleOffsets":[0],
"fringeColor":[255,255,255,255],
"coreColor":[255,255,255,255],
"glowColor":[255,255,255,255],
"width":1.0,
"textureType":ROUGH,
"textureScrollSpeed":1.0,
"pixelsPerTexel":1.0,
}

Heres the code for the effect currently used in the game:

Code
package com.fs.starfarer.api.impl.combat;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
import com.fs.starfarer.api.combat.WeaponAPI;

public class SensorDishRotationEffect implements EveryFrameWeaponEffectPlugin {

private float currDir = Math.signum((float) Math.random() - 0.5f);

public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
if (engine.isPaused()) return;

float curr = weapon.getCurrAngle();

curr += currDir * amount * 10f;
float arc = weapon.getArc();
float facing = weapon.getArcFacing() + (weapon.getShip() != null ? weapon.getShip().getFacing() : 0);
if (!isBetween(facing - arc/2, facing + arc/2, curr)) {
currDir = -currDir;
}

weapon.setCurrAngle(curr);
}

public static boolean isBetween(float one, float two, float check) {
one = normalizeAngle(one);
two = normalizeAngle(two);
check = normalizeAngle(check);

//System.out.println(one + "," + two + "," + check);
if (check >= one && check <= two) return true;

if (one > two) {
if (check <= two) return true;
if (check >= one) return true;
}
return false;
}

public static float normalizeAngle(float angleDeg) {
return (angleDeg % 360f + 360f) % 360f;
}
}

Seems like it "spins" the image, might be possible to make other effects that will make it not "spin", used for lights, so i made a plugin that "suppose" to remove the "spinning", im still need to go deeper into the code and try figure out how to make it change the image everytime the inBetween "procs"
« Last Edit: January 05, 2013, 09:49:45 AM by silentstormpt »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #1 on: January 05, 2013, 08:23:26 AM »

Ah - what you want to do is:

1) Create a weapon with an animation, like the Assault Chaingun (chaingun.wpn) or the Thumper (shredder.wpn).
2) Either add "alwaysAnimate":"true" to the .wpn file, or have a script, like you're doing, and use WeaponAPI.getAnimation()'s methods (setFrame(), pause, play, a bunch of other ones).
Logged

Cycerin

  • Admiral
  • *****
  • Posts: 1665
  • beyond the infinite void
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #2 on: January 05, 2013, 08:33:53 AM »

Need... to learn... java...
Logged

maximilianyuen

  • Captain
  • ****
  • Posts: 358
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #3 on: January 05, 2013, 08:46:33 AM »

Ah - what you want to do is:

1) Create a weapon with an animation, like the Assault Chaingun (chaingun.wpn) or the Thumper (shredder.wpn).
2) Either add "alwaysAnimate":"true" to the .wpn file, or have a script, like you're doing, and use WeaponAPI.getAnimation()'s methods (setFrame(), pause, play, a bunch of other ones).

wow, you can do that?
i am so gonna add navigation light first thing first
Logged
Fleet construction in progress.

CrashToDesktop

  • Admiral
  • *****
  • Posts: 3876
  • Quartermaster
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #4 on: January 05, 2013, 08:55:55 AM »

Ah - what you want to do is:

1) Create a weapon with an animation, like the Assault Chaingun (chaingun.wpn) or the Thumper (shredder.wpn).
2) Either add "alwaysAnimate":"true" to the .wpn file, or have a script, like you're doing, and use WeaponAPI.getAnimation()'s methods (setFrame(), pause, play, a bunch of other ones).

I tried doing the first option, but it doesn't work.  I can post the code for it here, if anyone wants to see what I screwed up.
Logged
Quote from: Trylobot
I am officially an epoch.
Quote from: Thaago
Note: please sacrifice your goats responsibly, look up the proper pronunciation of Alex's name. We wouldn't want some other project receiving mystic power.

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #5 on: January 05, 2013, 08:58:46 AM »

Ah - what you want to do is:

1) Create a weapon with an animation, like the Assault Chaingun (chaingun.wpn) or the Thumper (shredder.wpn).
2) Either add "alwaysAnimate":"true" to the .wpn file, or have a script, like you're doing, and use WeaponAPI.getAnimation()'s methods (setFrame(), pause, play, a bunch of other ones).

this? What is the value that i should be adding to weapon.setRemainingCooldownTo(); is it seconds or milliseconds

Code
package data.scripts.plugins;

import com.fs.starfarer.api.AnimationAPI;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
import com.fs.starfarer.api.input.InputEventAPI;
import java.util.List;

public class DecorativeWeaponEffects implements EveryFrameCombatPlugin {

private CombatEngineAPI engine;

public void init(CombatEngineAPI engine) {
this.engine = engine;
}

public void advance (float amount, CombatEngineAPI engine, WeaponAPI weapon) {
             //boolean IsOnlyActiveWhenFiring = true;
             animation = weapon.getAnimation();
            
                if (engine.isPaused()) return;

                /*if (weapon.isFiring() && IsOnlyActiveWhenFiring)
                    animation.play();
                else if(!weapon.isFiring() && IsOnlyActiveWhenFiring)
                    animation.reset();
                else
                {*/
                    animation.play(); // play the animation when its not paused

                    if (weapon.getCooldownRemaining() == 0f) // if the cooldown is 0, lets reset the animation
                    {
                        animation.reset();
                        weapon.setRemainingCooldownTo(weapon.getCooldown()); // set the cooldown again to restart the process, this probably is not needed.
                    }
                //}
}
}
« Last Edit: January 05, 2013, 06:44:07 PM by silentstormpt »
Logged

TheHappyFace

  • Admiral
  • *****
  • Posts: 1168
  • The critic
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #6 on: January 05, 2013, 09:28:10 AM »

I just want to make animated parts which dont show up in-game as weapons... and activate whenever i want it.
Logged
Fractalsoftworks limited edition ban hammer.

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #7 on: January 05, 2013, 09:36:15 AM »

The default ones (the sensordish) is right now automatic as in, replay when the combat is not paused (its only paused when ur setting commands to your fleet), why would you want to activate them? they are there to simply add decorative and animated parts to the hull, pressing 4 and "fire" those just so the ship lights now change color sounds really pointless...

If you meant to only activate when a certain weapon is firing then having them in the same weapon group, sounds reasonable.

since they ARE buildin weapons they will probably show on the weapon list, but i need to actually need to try setting one to see if this is true.
« Last Edit: January 05, 2013, 09:44:58 AM by silentstormpt »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #8 on: January 05, 2013, 11:09:38 AM »

since they ARE buildin weapons they will probably show on the weapon list, but i need to actually need to try setting one to see if this is true.

They will not show up.

Also, you should probably add the "SYSTEM" hint to those in weapon_data.csv, to avoid them showing up in the Codex, in weapon convoys, etc.
Logged

CrashToDesktop

  • Admiral
  • *****
  • Posts: 3876
  • Quartermaster
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #9 on: January 05, 2013, 01:34:45 PM »

Spoiler
Code
{
"specClass":"beam",
"id":"lights",
"type":"DECORATIVE",
"size":"SMALL",
"turretSprite":"graphics/weapons/decorative/lights/lights_00.png",
"hardpointSprite":"graphics/weapons/decorative/lights/lights_00.png",
"numFrames":4,
"frameRate":4,
"alwaysAnimate":"true",
"turretOffsets":[0, 0],
"turretAngleOffsets":[0],
"hardpointOffsets":[0, 0],
"hardpointAngleOffsets":[0],
"fringeColor":[255,255,255,255],
"coreColor":[255,255,255,255],
"glowColor":[255,255,255,255],
"width":1.0,
"textureType":ROUGH,
"textureScrollSpeed":1.0,
"pixelsPerTexel":1.0,
}
[close]

Code for blinking lights.  I made sure the lights_00.png and all that follow were named correctly.  What am I doing wrong?
« Last Edit: January 05, 2013, 01:36:24 PM by The Soldier »
Logged
Quote from: Trylobot
I am officially an epoch.
Quote from: Thaago
Note: please sacrifice your goats responsibly, look up the proper pronunciation of Alex's name. We wouldn't want some other project receiving mystic power.

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #10 on: January 05, 2013, 01:48:10 PM »

Spoiler
Code
{
"specClass":"beam",
"id":"lights",
"type":"DECORATIVE",
"size":"SMALL",
"turretSprite":"graphics/weapons/decorative/lights/lights_00.png",
"hardpointSprite":"graphics/weapons/decorative/lights/lights_00.png",
"numFrames":4,
"frameRate":4,
"alwaysAnimate":"true",
"turretOffsets":[0, 0],
"turretAngleOffsets":[0],
"hardpointOffsets":[0, 0],
"hardpointAngleOffsets":[0],
"fringeColor":[255,255,255,255],
"coreColor":[255,255,255,255],
"glowColor":[255,255,255,255],
"width":1.0,
"textureType":ROUGH,
"textureScrollSpeed":1.0,
"pixelsPerTexel":1.0,
}
[close]

Code for blinking lights.  I made sure the lights_00.png and all that follow were named correctly.  What am I doing wrong?

Ah - what you want to do is:

1) Create a weapon with an animation, like the Assault Chaingun (chaingun.wpn) or the Thumper (shredder.wpn).
2) Either add "alwaysAnimate":"true" to the .wpn file, or have a script, like you're doing, and use WeaponAPI.getAnimation()'s methods (setFrame(), pause, play, a bunch of other ones).
Logged

CrashToDesktop

  • Admiral
  • *****
  • Posts: 3876
  • Quartermaster
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #11 on: January 05, 2013, 01:50:16 PM »

...which is what I did.  I've been making weapons for awhile now, I think I know how to read directions. :P This is, it's not working.

EDIT:
Just to prove something's off, I tried it using the Thumper's code (oddly called "Shredder" in the code, hm) and it still doesn't work.
« Last Edit: January 05, 2013, 01:55:24 PM by The Soldier »
Logged
Quote from: Trylobot
I am officially an epoch.
Quote from: Thaago
Note: please sacrifice your goats responsibly, look up the proper pronunciation of Alex's name. We wouldn't want some other project receiving mystic power.

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #12 on: January 05, 2013, 01:56:30 PM »

...which is what I did.  I've been making weapons for awhile now, I think I know how to read directions. :P This is, it's not working.

Sorry the code box somehow is only showing 2 lines so when i scrolled down didnt see some lines,

first question, do you have 4 images of the lights_00.png (lights_01.png, lights_02.png, lights_03.png) in the same folder since its 4 frames you need
Logged

CrashToDesktop

  • Admiral
  • *****
  • Posts: 3876
  • Quartermaster
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #13 on: January 05, 2013, 02:01:07 PM »

Yup.  I made sure of that the first time I got an error.  All correct.
Logged
Quote from: Trylobot
I am officially an epoch.
Quote from: Thaago
Note: please sacrifice your goats responsibly, look up the proper pronunciation of Alex's name. We wouldn't want some other project receiving mystic power.

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Creating new Decorative "Weapons"
« Reply #14 on: January 05, 2013, 02:03:05 PM »

Im sure its because it expects to "fire" them, thats how the animated weapons so far worked right?
So... im guessing the custom script is still needed for this,

Here i was thinking it was easy to change it, god how i was so wrong, somehow ive been messing around trying to get a script that makes what the animations are supposed to do without the actual need to "fire" them
« Last Edit: January 05, 2013, 02:46:36 PM by silentstormpt »
Logged
Pages: [1] 2 3 ... 6