Forged Alliance Forever Forged Alliance Forever Forums 2018-10-24T18:24:38+02:00 /feed.php?f=41&t=16823 2018-10-24T18:24:38+02:00 2018-10-24T18:24:38+02:00 /viewtopic.php?t=16823&p=168749#p168749 <![CDATA[Re: Help with limiting turret numbers.]]>
Code:
                List = GetArmyBrain(army):GetListOfUnits(categories.ALLUNITS, false, true)                   
                    for k, unit in List do
                          if (unit:GetUnitId() == 'alphaa1') then
                                self:AddBuildRestriction( categories.sbrot1expd )


needs to be SELF and nothing else. Just suplemented it for unit:AddBuildRestriction( categories.sbrot1expd ) and it worked perfectly....
I had the solution 2 days ago, in my 1.st post, if only I knew that...god damnit.
Ty for suggesting I retrace my steps, it helped me solve this :)

Statistics: Posted by DDDX — 24 Oct 2018, 18:24


]]>
2018-10-24T16:16:16+02:00 2018-10-24T16:16:16+02:00 /viewtopic.php?t=16823&p=168747#p168747 <![CDATA[Re: Help with limiting turret numbers.]]>
If yes, you can use the GetListOfUnits AI function to recover your engineer list. Then you can set the AddBuildRestriction method to all your engineers.

Statistics: Posted by Franck83 — 24 Oct 2018, 16:16


]]>
2018-10-24T13:27:08+02:00 2018-10-24T13:27:08+02:00 /viewtopic.php?t=16823&p=168745#p168745 <![CDATA[Re: Help with limiting turret numbers.]]> I did consider that at first, but seeing how I need to restrict other unit(s) to be able to build THIS turret, and I only know of this command to edit buildable categories self:AddBuildRestriction(categories.sbrot1expd), you can see how I would have a problem.

I know how to restrict building stuff from a builder's .script file, and I know how to count turret numbers and put them in my turret's script, but not how to combine the 2

I took a look at your T1ComRadar mod, however the Blueprints.lua file does not help me considering the OnStopBeingBuilt and OnDestroyed changes in the turrets .script file, pertaining to the numbers of turrets in existance because it only makes a general change to the blueprint and that is it. And I need it to be dinamic, if there's too many turrets, lose it from the build queue, if turrets die, be able to make em again.

Is there a way to add build restrictions of another unit and not just "self", from a .script file of my turret (namely, to edit the blueprint of that turret unit in general - (bp.categories) so that no further turrets can be made)? Or will I have to go another way around?

Worst case scenario I can just make the extra turret over the max number simply blow up when finished, but that is not an elegant way to do this...

Statistics: Posted by DDDX — 24 Oct 2018, 13:27


]]>
2018-10-20T12:40:48+02:00 2018-10-20T12:40:48+02:00 /viewtopic.php?t=16823&p=168634#p168634 <![CDATA[Re: Help with limiting turret numbers.]]>
If you just count turret number and if you put it in your turret scripts, you don't need an array but a simple variable.
Put it at the top.

I would suggest this kind of code in your units turrets script :

Code:
local num_Turrets = 0

local OldXEB2306 = XEB2306
XEB2306 = Class(OldXEB2306) {

   OldOnStopBeingBuilt = OldXEB2306.OnStopBeingBuilt,
   OnStopBeingBuilt = function(self, builder, layer)
      num_Turrets = num_Turrets + 1
      if num_Turrets > 5 then
         -- Your building restriction code
      end
   end,

   OldDestroyUnit = OldXEB2306.DestroyUnit,
   DestroyUnit = function(self, overkillRatio)
      num_Turrets = num_Turrets - 1
      if num_Turrets <= 5 then
         -- Your building unlocking code
      end
   
   end,
}
TypeClass = XEB2306

Statistics: Posted by Franck83 — 20 Oct 2018, 12:40


]]>
2018-10-20T01:21:40+02:00 2018-10-20T01:21:40+02:00 /viewtopic.php?t=16823&p=168625#p168625 <![CDATA[Help with limiting turret numbers.]]> The problem is as follows - I need a code that will restrict the number of a specific turrets available for build, and then unrestrict them again when they get killed.

Now the restricting i have, and it goes as follows:

Code:
    OnStopBuild = function(self, sbrot1expd, order)

        AAirUnit.OnStopBuild(self, sbrot1expd)       
        --restrict the total number of things we can build
            local army = self:GetArmy()

                List = GetArmyBrain(army):GetListOfUnits(categories.ALLUNITS, false, true)                   
                    for k, unit in List do

                        if (unit:GetUnitId() == 'sbrot1expd') then                                        --my turret that I only need 2 of at any given time
                            table.insert(num_Mizura, unit); -- add unit to special unit list     
                             if (table.getn(num_Mizura) >= 2) then
                                self:AddBuildRestriction( categories.sbrot1expd )                    -- works like a charm
                              end
                        end
                    end   
    end,


Now comes the tricky part (for noob me, at least).
unrestricting the turret when it gets killed.
Now, I tried it like this
Code:
OnStartReclaim = function(self, target)                     -- the unit is gonna do a ton of reclaiming, that's why
        AAirUnit.OnStartReclaim(self, target)
        local army = self:GetArmy()
     
           List = GetArmyBrain(army):GetListOfUnits(categories.sbrot1expd, false, true)                   
                    for k, unit in List do
                       if (table.getn(num_Mizura) <= 1) then
                            self:RemoveBuildRestriction( categories.sbrot1expd )
                             table.remove(num_Mizura, unit)                         
                        end
                    end
    end,


but what I guess is happening is that the list gets filled more and more with every OnStopBuild, instead of having only 2 units in there, for my 2 turrets...and is not getting lesser when the turrets die.
So I figured - well it should then be in OnKilled script of the actual turret...tried to make that, but failed

Code:
OnKilled = function(self, instigator, damagetype, overkillRatio)
        TStructureUnit.OnKilled(self, instigator, damagetype, overkillRatio)

        local army = self:GetArmy()

                List = GetArmyBrain(army):GetListOfUnits(categories.sbrot1expd, false, true)                   
                    for k, unit in List do

                       -- if (unit:GetUnitId() == 'sbrot1expd') then
                            table.remove(num_Mizura, 1);   -- was table.remove(num_Mizura, unit), that's why I got the whole GetArmyBrain etc... but that gave me an error, asked for numerical value...what does the num value do here?
                    end
        self:CreatTheEffectsDeath()
    end,


So now...no idea how to pull that off. (Yes i have the local num_Mizura = {}; defined at start in both script files)
Any thoughts, or at least maybe point me in a direction of a mod/map that did this with another unitand i will be able to figure it out for myself...
Thanx.

Statistics: Posted by DDDX — 20 Oct 2018, 01:21


]]>