Hi PerfectWay,
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: Select all
...
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: Select all
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: Select all
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: Select all
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.