Skip to content
User Avatar
#4084
Auto-translated
Azgalor
Hello! Has anyone here got a code for an additional buff for buff-granting objects? For example, I want to give an object, the "Tattered Flag" (which provides bonuses to morale and luck for 1 battle), another bonus, say, a speed buff. Naturally, the buff will work the same way as the original, i.e., through GiveHeroBattleBonus(). It will be applied to everyone who touches the object and will not be reapplied until the hero fights someone. Currently, I'm thinking of writing a code that will add everyone who touches the object to a list and give them a tag like allow_touch = 0 (if 0, then the buff will not be applied upon re-touch), and then, in the function from COMBAT_RESULTS_TRIGGER, track who finished the battle, and if it's one of our visitors, give them permission (change 0 to 1) to be re-buffed by the flag. But maybe there's an easier way?
I was writing code for a modified pathfinding: for every point of luck, there's a 10% chance of getting a double bonus from buffs.
    arrayBuffTouched = {[1] = {0,0,0,0,0,0,0,0},
                        [2] = {0,0,0,0,0,0,0,0},
                        [3] = {0,0,0,0,0,0,0,0},
                        [4] = {0,0,0,0,0,0,0,0}}
allFreeBuffs = {1,2,3,4,5,2,6,1,3,1,4,5,7,6}
for i = 1,14 do
    Trigger(OBJECT_TOUCH_TRIGGER,"Buff"..i,"TouchBuff")
end
function TouchBuff(hero,obj)
    local i = GetObjectOwner(hero)
    for j = 1,14 do
        if obj == "Buff"..j then
            if arrayBuffTouched[allFreeBuffs[j]] == 0 then
                HasFortunateAdventurer(i,obj)
                arrayBuffTouched[allFreeBuffs[j]] = 1
            end
        end
    end
end
function HasFortunateAdventurer(i,obj)
    if HasHeroSkill(heroT,33) == not nil and random(10)+1 <= GetHeroStat(heroT,5) then
        local bufftype = 0
        for j = 1,14 do
            if obj == "Buff"..j then
                bufftype = j
            end
        end
        if allFreeBuffs[bufftype] == 1 then
            GiveHeroBattleBonus(heroT,1,1)--morale
            GiveHeroBattleBonus(heroT,0,1)--luck
        elseif allFreeBuffs[bufftype] == 2 then
            if GetDate(DAY_OF_WEEK) == 7 then
                GiveHeroBattleBonus(heroT,1,2)--morale
            else
                GiveHeroBattleBonus(heroT,1,1)--morale
            end
        elseif allFreeBuffs[bufftype] == 3 then
            if GetDate(DAY_OF_WEEK) == 7 then
                GiveHeroBattleBonus(heroT,1,1)--morale
                GiveHeroBattleBonus(heroT,0,1)--luck
            elseif GetDate(DAY_OF_WEEK) == 1 or GetDate(DAY_OF_WEEK) == 3 or GetDate(DAY_OF_WEEK) == 5 then
                GiveHeroBattleBonus(heroT,0,1)--luck
            else
                GiveHeroBattleBonus(heroT,1,1)--morale
            end
        elseif allFreeBuffs[bufftype] == 5 then
            if GetDate(DAY_OF_WEEK) == 1 then
                GiveHeroBattleBonus(heroT,2,3)--offence
            elseif GetDate(DAY_OF_WEEK) == 2 then
                GiveHeroBattleBonus(heroT,1,1)--morale
            elseif GetDate(DAY_OF_WEEK) == 3 then
                GiveHeroBattleBonus(heroT,3,3)--defence
            elseif GetDate(DAY_OF_WEEK) == 4 then
                GiveHeroBattleBonus(heroT,0,1)--luck
            elseif GetDate(DAY_OF_WEEK) == 5 then
                GiveHeroBattleBonus(heroT,5,1)--initiative
            elseif GetDate(DAY_OF_WEEK) == 6 then
                GiveHeroBattleBonus(heroT,2,2)--offence
                GiveHeroBattleBonus(heroT,3,2)--defence
            elseif GetDate(DAY_OF_WEEK) == 7 then
                GiveHeroBattleBonus(heroT,6,1)--speed
            end
        elseif allFreeBuffs[bufftype] == 6 then
            GiveHeroBattleBonus(heroT,1,1)--morale
        elseif allFreeBuffs[bufftype] == 7 then
            if GetDate(DAY_OF_WEEK) == 7 then
                GiveHeroBattleBonus(heroT,0,2)--luck
            else
                GiveHeroBattleBonus(heroT,0,1)--luck
            end
        end
    end
end

and update after the battle
arrayBuffTouched= {0,0,0,0,0,0,0,0}

Мои карты: Белый Храм, Поменяться местами, Судьба королевства, Стихийные острова.