Forged Alliance Forever Forged Alliance Forever Forums 2017-12-13T22:40:50+02:00 /feed.php?f=41&t=15558 2017-12-13T22:40:50+02:00 2017-12-13T22:40:50+02:00 /viewtopic.php?t=15558&p=157996#p157996 <![CDATA[Re: Buffs in runtime]]> Statistics: Posted by PerfectWay — 13 Dec 2017, 22:40


]]>
2017-12-12T23:42:01+02:00 2017-12-12T23:42:01+02:00 /viewtopic.php?t=15558&p=157958#p157958 <![CDATA[Re: Buffs in runtime]]>
Another way (more cpu optimized) is to create a global var that is set when you build your buff building. Then apply on each new unit the buff (unit.lua OnStopBeingBuilt function) if the var is ok.

For the radius, you just have to cover all the map. 1000 is maybe not enough, i don't know you need to try.

Statistics: Posted by Franck83 — 12 Dec 2017, 23:42


]]>
2017-12-12T22:36:48+02:00 2017-12-12T22:36:48+02:00 /viewtopic.php?t=15558&p=157956#p157956 <![CDATA[Re: Buffs in runtime]]> Statistics: Posted by PerfectWay — 12 Dec 2017, 22:36


]]>
2017-12-10T16:48:33+02:00 2017-12-10T16:48:33+02:00 /viewtopic.php?t=15558&p=157866#p157866 <![CDATA[Re: Buffs in runtime]]> ) would be to just edit your individual unit script.

For example, building a UEF radar (UEB3101_Script.lua) providing a 20% vision buff to all existing (only) units around :
Code:
local Buff = import('/lua/sim/buff.lua')
local TRadarUnit = import('/lua/terranunits.lua').TRadarUnit

UEB3101 = Class(TRadarUnit) {
   OnStopBeingBuilt = function(self,builder,layer)
      TRadarUnit.OnStopBeingBuilt(self,builder,layer)
      local units = self:GetAIBrain():GetUnitsAroundPoint(categories.MOBILE, self:GetPosition(), 1000, 'Ally') -- grab all mobile units in 1000 area distance around the radar
      BuffBlueprint {
         Name = 'VisionRadius',
         DisplayName = 'VisionRadius',
         BuffType = 'VisionRadius',
         Stacks = 'REPLACE',
         Duration = -1,
         Affects = {
            VisionRadius = {
            Mult = 1.2, -- +20% vision radius
         },
      },
      for k, unit in units do
         Buff.ApplyBuff(unit , 'VisionRadius')
      end         
   }
end,
}
TypeClass = UEB3101

Statistics: Posted by Franck83 — 10 Dec 2017, 16:48


]]>
2017-12-10T00:39:29+02:00 2017-12-10T00:39:29+02:00 /viewtopic.php?t=15558&p=157834#p157834 <![CDATA[Re: Buffs in runtime]]>
You may need this function for immediate buff on already build units :

Code:
local units = Unit:GetAIBrain():GetUnitsAroundPoint(categories.MOBILE, Unit:GetPosition(), 1000, 'Ally') -- grab all mobile units in 1000 area distance around your research center
BuffBlueprint {
         Name = MaxHealthBuff',
         DisplayName = 'MaxHealthBuff',
         BuffType = 'MaxHealth',
         Stacks = 'REPLACE',
         Duration = -1,
         Affects = {
            MaxHealth = {
                Mult = 1.2, -- 20% Max Health buff
            },
         },
}

for k, unit in units do
    -- casting your buff on each grabbed unit
    Buff.ApplyBuff(unit , 'MaxHealthBuff')
end

Statistics: Posted by Franck83 — 10 Dec 2017, 00:39


]]>
2017-12-10T00:26:52+02:00 2017-12-10T00:26:52+02:00 /viewtopic.php?t=15558&p=157833#p157833 <![CDATA[Re: Buffs in runtime]]> Statistics: Posted by PerfectWay — 10 Dec 2017, 00:26


]]>
2017-12-10T00:29:53+02:00 2017-12-10T00:13:54+02:00 /viewtopic.php?t=15558&p=157832#p157832 <![CDATA[Re: Buffs in runtime]]>
Example : adding a RESEARCHCENTER category.

Code:
Categories = {
        'RESEARCHCENTER', -- Your add
        'SELECTABLE',
...
    },



Then in your unit.lua

Code:
local OldUnit = Unit
Unit = Class(OldUnit) {
         OldOnStopBeingBuilt = Unit.OnStopBeingBuilt,
         OnStopBeingBuilt = function(Unit, builder, layer)
            Unit.OldOnStopBeingBuilt(Unit, builder, layer) -- Here you call the old function
            if Unit then
                local id = Unit:GetEntityId()
                local bp = Unit:GetBlueprint()
                if table.find(bp.Categories, 'RESEARCHCENTER') then
                    -- Cast your buff
                end
            end
         end,
}

Statistics: Posted by Franck83 — 10 Dec 2017, 00:13


]]>
2017-12-09T23:56:00+02:00 2017-12-09T23:56:00+02:00 /viewtopic.php?t=15558&p=157831#p157831 <![CDATA[Re: Buffs in runtime]]>
\Mods\YourModName\Hook\lua\sim\unit.lua

So then you need to create an empty lua file called unit.lua.

This the hook code to add in your unit.lua (you need to hook the class and the function) :

Code:
local OldUnit = Unit
Unit = Class(OldUnit) {
     OldOnStopBeingBuilt = Unit.OnStopBeingBuilt,
     OnStopBeingBuilt = function(Unit, builder, layer)
         Unit.OldOnStopBeingBuilt(Unit, builder, layer) -- Here you call the old function
         -- Add here your code.
     end,
}


So the engine will execute your code after executing the original OnStopBeingBuilt function.

Good luck !

Statistics: Posted by Franck83 — 09 Dec 2017, 23:56


]]>
2017-12-09T23:17:15+02:00 2017-12-09T23:17:15+02:00 /viewtopic.php?t=15558&p=157829#p157829 <![CDATA[Re: Buffs in runtime]]> Now I have a small question about the hooking mechanism: I have to create a full copy of the file and add the code to the desired function or I can make a file with the same name, but change only the function that I need, for example OnStopBeingBuilt in Unit.lua?

Statistics: Posted by PerfectWay — 09 Dec 2017, 23:17


]]>
2017-12-10T00:01:00+02:00 2017-12-07T00:17:01+02:00 /viewtopic.php?t=15558&p=157689#p157689 <![CDATA[Re: Buffs in runtime]]>

You need some prerequisites to do what you want :

Ui (all user interface tools) and sim (all units, weapons and projectiles methods...) are running in different threads. So data exchanging is not automatic.

For example, if you want to click on a ok button of a dialog (Ui) and trigger a buff (sim), you need to use simcallbacks (this will send your data from ui to sim) :

(I assume you know how to create a dialog or a button in Ui)

Let's do it for a buildrate bonus :

Code:
...
okBtn.OnClick = function(self)
...
   SimCallback   ({Func= 'SetBuildingSpeed', Args = {id = _id, BuildingRate = Your building rate}})
   dialog:Close()
end



You need to register your callback by hooking SimCallbacks.lua and type your function path :

Code:
Callbacks.SetBuildingSpeed = import('/Mods/Heroes_Reloaded/Modules/UiToSim.lua').SetBuildingSpeed



Then in your file UiToSim.lua (you can type another path or file name) :

Code:
function SetBuildingSpeed(Unit)
    local id = Unit.id
    local unit = GetUnitById(id)
    unit:SetBuildingRate(Unit.BuildingRate)
end



Then you need to hook unit.lua and add a function :

Code:
SetBuildingRate = function(self, BuildRate)
       BuffBlueprint {
         Name = 'BuildingRateBuff',
         DisplayName = 'BuildingRateBuff',
         BuffType = 'BuildingRateBuff',
         Stacks = 'REPLACE',
         Duration = -1,
         Affects = {
            BuildRate = {
               Add = BuildRate or 0,
               Mult = 1,
            },
         },
   }
      Buff.ApplyBuff(self, 'BuildingRateBuff')
end,


You can do the same thing with other affects DamageRadius, Regen, MaxHealth....

I didn't test the code but i use theses features a lot in my mod.

For the buffs when you create a building, i recommend you to hook the OnStopBeingBuilt function in unit.lua.
Here you can test the kind of building made and if it's ok you can trigger your SetBuildingRate function in unit.lua.
Maybe your need to test it when it is destroyed to remove the buff.

Hope this will help, good luck !

Edit : i corrected a code error.

Statistics: Posted by Franck83 — 07 Dec 2017, 00:17


]]>
2017-12-06T21:26:15+02:00 2017-12-06T21:26:15+02:00 /viewtopic.php?t=15558&p=157681#p157681 <![CDATA[Re: Buffs in runtime]]> Alliance of Heroes mod can do
maybe franck83 can lend you a hand

Statistics: Posted by PhilipJFry — 06 Dec 2017, 21:26


]]>
2017-12-06T21:03:59+02:00 2017-12-06T21:03:59+02:00 /viewtopic.php?t=15558&p=157680#p157680 <![CDATA[Buffs in runtime]]> I want to learn how to add some bonuses to units in the game. For example, + 10% to health or + 10% to damage.
I know how to do this before starting the game by modifying the blueprints
Code:
function ModBlueprints(all_bps)
...
but I need it so that it can be done taking into account some condition, for example, pressing a button or building a certain structure, as in ExperimentalWar 2.8. For example, we are building a structure that raises the health of all mobile units by 50%, so after its completion, the characteristics of all existing units must be recalculated, and the characteristics of new units should take into account this bonus.
How can I implement such functionality? Maybe someone has already used this? I will be grateful for any advice.

Statistics: Posted by PerfectWay — 06 Dec 2017, 21:03


]]>