[Modding] new enhancements for units

Need help? This is the right place!
Note, reporting bugs and issues should be in the Tech Support forum!

Moderator: PhilipJFry

[Modding] new enhancements for units

Postby Dudekahedron » 30 Nov 2016, 19:25

Hi Faf,
Me again. Relatively simple question;
I am trying to create an enhancement for a shield generator:
Basically just adding a weapon who's muzzle is located on the shield?

From script.lua:
Code: Select all
    CreateEnhancement = function(self, enh)
       TShieldStructureUnit.CreateEnhancement(self,enh)
       local bp = self:GetBlueprint().Enhancements[enh]
       if not bp then return end
       # Restraining order
       if enh == 'RestrainingOrder' then
          local blueprint = self:GetBlueprint()
          CreateSlider(self,'muzzle', blueprint.Defense.Shield.ShieldSize, 0, 0, 1000, true)
          self:SetWeaponEnabledByLabel('PhasonBeam',true)
       elseif enh == 'RestrainingOrderRemove' then
          local blueprint = self:GetBlueprint()
          CreateSlider(self,'muzzle', -blueprint.Defense.Shield.ShieldSize, 0, 0, 1000, true)
          self:SetWeaponEnabledByLabel('PhasonBeam',false)
       end
    end,   


From unit.bp:
Code: Select all
    Enhancements = {
        RestrainingOrder = {
            BuildCostEnergy = 10000,
            BuildCostMass = 1000,
            BuildTime = 1000,
            Icon = 'cd',
            Name = 'Restraining Order',
            Slot = 'Back',
        },
        RestrainingOrderRemove = {
            BuildCostEnergy = 1,
            BuildCostMass = 1,
            BuildTime = 0.1,
            Icon = 'cd',
            Name = 'Remove Restraining Order',
            Prerequisite = 'RestrainingOrder',
            RemoveEnhancements = {
                'RestrainingOrder',
                'RestrainingOrderRemove',
            },
            Slot = 'Back',
        },
    },


The enhancement option doesn't appear for the unit, and I get weird glitchiness with the ACU (not sure if related), any ideas?
Code: Select all
WARNING: Error running '/lua/ui/game/gamemain.lua:OnSelectionChanged': ...nce\gamedata\lua.scd\lua\ui\controls\specialgrid.lua(143): attempt to call method `Hide' (a nil value)
         stack traceback:
            ...nce\gamedata\lua.scd\lua\ui\controls\specialgrid.lua(143): in function `CalcVisible'
            ...nce\gamedata\lua.scd\lua\ui\controls\specialgrid.lua(167): in function `Refresh'
            ...orever\gamedata\lua.nx2\lua\ui\game\construction.lua(367): in function `OnCheck'
            ...alliance\gamedata\mohodata.scd\lua\maui\checkbox.lua(45): in function `SetCheck'
            ...orever\gamedata\lua.nx2\lua\ui\game\construction.lua(475): in function `CreateTabs'
            ...orever\gamedata\lua.nx2\lua\ui\game\construction.lua(357): in function `OnCheck'
            ...alliance\gamedata\mohodata.scd\lua\maui\checkbox.lua(45): in function `SetCheck'
            ...orever\gamedata\lua.nx2\lua\ui\game\construction.lua(2210): in function `OnSelection'
            ...\faforever\gamedata\lua.nx2\lua\ui\game\gamemain.lua(491): in function <...\faforever\gamedata\lua.nx2\lua\ui\game\gamemain.lua:465>

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: [Modding] new enhancements for units

Postby Sprouto » 30 Nov 2016, 20:51

I can think of a couple of things that might impact you here;

You'll need to define the Slots on your unit blueprint, refer to either the ACU or SCU for that. If the slots aren't defined, then the interface will throw errors, and that's likely what you're seeing. The key hint was the function 'CreateTabs'.

Secondly, you may need to define a weapon in your blueprint, like any other, and see that it's set to a disabled state when the unit is first created. I assume that you've done that by your use of the 'SetWeaponEnabledByLabel', but I just thought I'd mention it.
Sprouto
Priest
 
Posts: 366
Joined: 08 Sep 2012, 05:40
Has liked: 54 times
Been liked: 74 times
FAF User Name: Sprouto

Re: [Modding] new enhancements for units

Postby Dudekahedron » 30 Nov 2016, 22:05

Thanks for the fast reply!
It was the slot definitions I didn't have, totally missed that! Weirdly, it doesn't seem to relate to the issues with the ACU though.
I had the weapon stuff already ;)
thanks for the help!
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: [Modding] new enhancements for units

Postby vongratz » 01 Dec 2016, 01:06

Give an extensive look at Asdrubalvect Experimental Wars.The units have lots of modifications and improvements.The model must to contain all the new"hidden" features that you will put there,as bones and pieces that will appear after.
User avatar
vongratz
Avatar-of-War
 
Posts: 192
Joined: 08 May 2012, 15:03
Has liked: 165 times
Been liked: 9 times


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest