(Solved) Defense and Magnetic Fields Not Visible?

I’ve try adding the ability for a defense field on a ship, but I have been unable to actually see the field. I’ve tried editing the ships .events file as well as making a .madstate file with no progress.

I don’t know the programming for custom luas or madstate files, so any help here is greatly appreciated.

Do you mean that the field is working but invisible, or just not working? I have not tried it yet, but I read somewhere that you have to have a MAD animation with it, but I don’t know if that is true. The easiest way to test that might be to copy the hgn one and remove the MAD and madstate files…

Yes, the field works but without any visual representation.

The issue with the hiigaran ships is that there are arm animations in the mad file as well. The taiidan field frigate’s mad file is pretty bare bones, but I can’t seem to get it visually working in another ship.

I just tried this - it worked, but with no visualisation. So it looks like you need a MAD animation before the effect will be triggered.

Yeah, that’s what I found too. I don’t know why, but I can’t seem to get this working. I’ll pick up again tomorrow though.

Did you copy the Tai Field Frigate “On” entry from it’s events file as well?

Yes, with no difference. I have been unable to get a visual field working for the desire ship, however I can swap the Taiidan frigate and Hiigaran frigates visual effects. Maybe only ships that have a default madstate file will work?

There is a visual FX that is fired from the ship’s event file.

    animation9 =
    {
        name = "On",
        length = 1,
        loop = 1,
        parent = "",
        minimum = 0,
        maximum = 0,
        markers = {""}
    },

    event15 =
    {
        { "anim", "On" },
        { "animtime", "-1" },
        { "marker", "root" },
        { "sound", "SP_ELEMENTS/HGN_DEFENSEFIELDFRIGATE_ON" },
		{ "fx", "defensefield_sphere_spray" },
		{ "fx_scale", "1200" },
    },

Also, MAD states are in effect also:

HGN_DEFENSEFIELDFRIGATE_DefenseFieldActivate_OnSet = function(ship)
    -- unset the state, we'll set it when the animation is fully complete
    setState(ship, "DefenseFieldActivate", 0)
    -- if we're not already doing the animation
    if(isAnimRunning(ship, "Open") == 0) then
        startTime = 0
        -- if we're doing the close animation then we want to start the open at
        -- the right place, open and close are the same length
        if(isAnimRunning(ship, "Close") ~= 0) then
            startTime = getAnimLength(ship, "Close") - getTime(ship, "Close")
            stopAnim(ship, "Close")
            endEffect(ship, "Close")
        end
        startAnim(ship, "Open")
        startEffect(ship, "Open")
        setTime(ship,"Open",startTime)
        -- apparently we are supposed to use a 'big number' to mean pause at end, 1000 is apparently 'big' enough
        setPauseTime(ship, "Open", 1000)
    else
        setState(ship, "DefenseFieldActivate", 1)
    end
end

HGN_DEFENSEFIELDFRIGATE_DefenseFieldActivate_OnPause = function(ship)
    -- the open animation has finished, now we can set the state to active
    setState(ship, "DefenseFieldActivate", 1)
    endEffect(ship, "Open")
    startEffect(ship, "On")

end

HGN_DEFENSEFIELDFRIGATE_DefenseFieldDeActivate_OnSet = function(ship)
    -- stop the open and work animations, they may be running
    if(isAnimRunning(ship,"Close") == 0) then
        startTime = 0
        if(isAnimRunning(ship, "Open") ~= 0) then
            startTime = getAnimLength(ship, "Open") - getTime(ship, "Open")
            stopAnim(ship, "Open")
            endEffect(ship, "Open")
        end
        endEffect(ship, "On")
        startEffect(ship, "Close")
        startAnim(ship, "Close")
        setTime(ship,"Close",startTime)
        setPauseTime(ship, "Close", 1000)
    end
    setState(ship, "DefenseFieldDeActivate", 1)
end

There is also a difference between the Taiidan’s Field Frigate event file and the Hiigaran’s. The TFF uses ‘fieldOn’ as opposed to the ‘event15’ ,has a very minimalistic .madstate file.

I’ve tried copying and editing both ship’s event files and .madstate to get the desired visual effect, but it just turns up blank in the ship I’m adding the field to. Even the Taiidan Defense Fighter mirrors the TFF, so I’m not sure why it isn’t working for other ship.

Can someone test adding a magnetic field (because its simpler) to another ship and see if it works visually?

I’m now at the point of trying to rig the taiidan republic defense field platform. Was the conclusion of this that it must have an animation? What is the difference between a defense field and a magnetic field?

I’ve been away for the week, so I don’t know about a final how-to. I can say that something must be present in the ship effects file, and a mad file must be present. Take a list look at the Taiidan frigate for simplicities sake, as that mad file is very simple.

There are a few distinctive differences as far as I can tell.

  1. Visual Effects

  2. Defense field is an activated ability, while the magnetic field is passive.

  3. Both fields have a separate field penetration value. If you wanted to, you could have different weapon ‘types’ that penetrate different fields better than others (I’ve done this recently for a custom mod, its really interesting!).

Were you able to get it working on a different ship then? Or still not?

Note that you don’t actually have to have an animation (i.e. a mad file does not have to be present).

Defense Field:

addAbility(NewShipType,"DefenseFieldAbility",1,0,1200,200,200,0.7,0.6,0,"defensefield_sphere_spray");
addAbility(NewShipType,"DefenseFieldShieldAbility",0,1200,0,0);

SHIP_DefenseFieldActivate_OnSet = function(ship)
    startEffect(ship, "DefFieldEffect")
end

SHIP_DefenseFieldDeActivate_OnSet = function(ship)
    endEffect(ship, "DefFieldEffect")
end

Magnetic field:

addMagneticField(NewShipType, "MagneticField", 1000, 99, "defenseField_generic", 15, "defenseField_generic", 99, "plasma_hit_spray_MagneticField", "defensefield_sphere_spray_TFF");

SHIP_MagneticFieldActivate_OnSet = function(ship)
    startEffect(ship, "MagFieldEffect")
end
SHIP_MagneticFieldDeActivate_OnSet = function(ship)
    endEffect(ship, "MagFieldEffect")
end

I don’t remember the right file, was it called mad state or something? You are correct in that animations are not necessary.

@sastrei, I’ve been out for the week, so no further attempts have been made on my end. I’ll mention something if I get it working. Wish there was an easier way.

Seems pretty straightforward, using the Tai_FieldFrigate as a starting point. I copied it over to one of our BSG ships.

add this to the .ship file:

addMagneticField(NewShipType,"MagneticField",1000,99,"defenseField_generic",15,"defenseField_generic",99,"plasma_hit_spray_MagneticField","defensefield_sphere_spray_TFF");’

make sure your .events file includes this:

effects =
{
    animations =
    {
        animationOn =
        {
            name = "On",
            length = 1,
            loop = 1,
            parent = "",
            minimum = 0,
            maximum = 0,
            markers = {""}
        },
    },
    events =
	{			
        fieldOn =
        {
            { "anim", "On", },
            { "animtime", "-1", },
            { "marker", "root", },
            { "fx", "defensefield_sphere_spray_TFF", },
            { "fx_scale", "1000", },
        },
    }
}

nick the .madstate file and edit it appropriately:

HUR_CIV_CLOUDNINE_MagneticFieldActivate_OnSet = function(ship)
    startEffect(ship, "On")
end
HUR_CIV_CLOUDNINE_MagneticFieldDeActivate_OnSet = function(ship)
    endEffect(ship, "On")
end

and presto. :slight_smile:

Hope this helps!

Ah, I think I was missing the animations bit in the events file. I’ll edit this post today after I’ve tried it out.

Edit: Wow, that was the reason. I don’t know how that kept going past my head. Thanks to everyone who helped out here!

In the end, it looks like a .madstate file is needed as well as the ‘animationOn’ and ‘fieldOn’ events.

2 Likes