Weapon-Triggered activation/deactivation code

Everything about mods can be found here.

Moderator: Morax

Weapon-Triggered activation/deactivation code

Postby Dudekahedron » 28 Dec 2016, 19:33

Hi Faf,
Me needing help again!
I have a unit with three unique weapons that I would like to activate/deactivate based on what fired last. Ideally so they fire consecutively after each other.
Ie Gun1 fires, deactivates, an animation occurs to 'set up' Gun2, then Gun2 fires, etc.

This is what I have currently, except the guns never swap:
Code: Select all
    OnCreate = function(self)
        SecretUnit.OnCreate(self)
        self:SetWeaponEnabledByLabel('Gun2', false)
        self:SetWeaponEnabledByLabel('Gun3', false)
    end,

    Weapons = {
       Gun1 = Class(Secret1) {
            OnFire = function(self)
                self:Fire()
                Secret1.OnFire()
            end,
          Fire = function(self)
                self:SetWeaponEnabledByLabel('Gun1', false)
                self.Reload1 = CreateAnimator(self)
                self.Reload1:PlayAnim(self:GetBlueprint().Display.AnimationReload1, true):SetRate(1)
                self.Trash:Add(self.Reload1)
                self:SetWeaponEnabledByLabel('Gun2', true)
                self:GetWeaponManipulatorByLabel('Gun1'):SetHeadingPitch(self:GetWeaponManipulatorByLabel('Gun2'):GetHeadingPitch())
            end,
       },

        Gun2 = Class(Secret2) {
            OnFire = function(self)
                self:Fire()
                Secret2.OnFire()
            end,

            Fire = function(self)
                self:SetWeaponEnabledByLabel('Gun2', false)
                self.Reload2 = CreateAnimator(self)
                self.Reload2:PlayAnim(self:GetBlueprint().Display.AnimationReload2, true):SetRate(1)
                self.Trash:Add(self.Reload2)
                self:SetWeaponEnabledByLabel('Gun3', true)
                self:GetWeaponManipulatorByLabel('Gun2'):SetHeadingPitch(self:GetWeaponManipulatorByLabel('Gun3'):GetHeadingPitch())
            end,
        },

        Gun3 = Class(Secret3) {
            OnFire = function(self)
                self:Fire()
                Secret3.OnFire()
            end,

            Fire = function(self)
                self:SetWeaponEnabledByLabel('Gun3', false)
                self.Reload3 = CreateAnimator(self)
                self.Reload3:PlayAnim(self:GetBlueprint().Display.AnimationReload3, true):SetRate(1)
                self.Trash:Add(self.Reload2)
                self:SetWeaponEnabledByLabel('Gun1', true)
                self:GetWeaponManipulatorByLabel('Gun3'):SetHeadingPitch(self:GetWeaponManipulatorByLabel('Gun1'):GetHeadingPitch())
            end,
        },
    },


I threw in some LOG('words') in there, and it seems like the OnFire function is never actually called, what function should I be using?

Thanks!!
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron

Re: Weapon-Triggered activation/deactivation code

Postby Dudekahedron » 28 Dec 2016, 20:36

Still tinkering;
I get an error now, which is partly helpful i guess:
Code: Select all
WARNING: Error running lua script: ...nce\mods\thedairyfarm\units\secret\secret_script.lua(42): attempt to call method `PlayAnim' (a nil value)
         stack traceback:
            ...nce\mods\thedairyfarm\units\secret\secret_script.lua(42): in function <...nce\mods\thedairyfarm\units\secret\secret_script.lua:39>


The code now:

Code: Select all
    Weapons = {
       Gun1 = Class(SecretWeapon) {
            OnWeaponFired = function(self)
                SecretWeapon.OnWeaponFired()
                self:ForkThread(self.GunSwap)
                LOG('Fire gun1!')
            end,

            GunSwap = function(self)
                self.Reload1 = CreateAnimator(self) --************
                self.Trash:Add(self.Reload1)
                self.Reload1:PlayAnim('/mods/TheDairyFarm/units/secret/secret_Reload1.sca', true):SetRate(1)
                WaitSeconds(self.Reload1:GetAnimationTime())
                LOG('Gun1 deactivated')
                self:SetWeaponEnabledByLabel('Gun1', false)
                LOG('Gun2 activated')
                self:SetWeaponEnabledByLabel('Gun2', true)
                self:GetWeaponManipulatorByLabel('Gun1'):SetHeadingPitch(self:GetWeaponManipulatorByLabel('Gun2'):GetHeadingPitch())
            end,
       },

That's duplicated for Gun2 and Gun3, but it never gets past the starred line
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron

Re: Weapon-Triggered activation/deactivation code

Postby Dudekahedron » 28 Dec 2016, 20:45

If I just # out the animation lines I get the following error:
Code: Select all
INFO: Fire gun1!
INFO: Gun1 deactivated
WARNING: Error running lua script: ...nce\mods\thedairyfarm\units\secret\secret_script.lua(45): attempt to call method `SetWeaponEnabledByLabel' (a nil value)
         stack traceback:
            ...nce\mods\thedairyfarm\units\secret\secret_script.lua(45): in function <...nce\mods\thedairyfarm\units\secret\secret_script.lua:39>


Which kind of suggests to me that the weapon cannot be disabled from within itself?
heeelllppp
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron

Re: Weapon-Triggered activation/deactivation code

Postby Dudekahedron » 29 Dec 2016, 05:30

I've abandoned this approach, anything within the weapon's function/class (whatever it is) is limited in functionality. It won't accept animations or sliders, only rotations... So I'm using a Scathis-script like approach now.
gg
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron

Re: Weapon-Triggered activation/deactivation code

Postby Resin_Smoker » 08 Jan 2017, 19:03

Dudekahedron wrote:I've abandoned this approach, anything within the weapon's function/class (whatever it is) is limited in functionality. It won't accept animations or sliders, only rotations... So I'm using a Scathis-script like approach now.
gg



Scathis really uses one barrel for all firing events and just cycles thru the aninamtion per each shot fired.
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Weapon-Triggered activation/deactivation code

Postby Dudekahedron » 10 Jan 2017, 03:19

Yeah, I was a bit disappointing when I learned that lol, I was hoping it would be a more "real" solution. Ah well. My Brimstone unit resulted from this.
Check out my mod (in development): /viewtopic.php?f=41&t=13326
User avatar
Dudekahedron
Avatar-of-War
 
Posts: 118
Joined: 10 Apr 2016, 22:01
Has liked: 42 times
Been liked: 54 times
FAF User Name: Dudekahedron


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest