Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Haw3k
User Avatar
8 months ago
Auto-translated
Haw3k
Hello, could you please tell me if it's possible to use scripts to block the ability to acquire a specific skill or two when selecting a skill?

It's not possible with scripts; you would need to create a mod.
User Avatar
8 months ago
Auto-translated

Hello!

Unfortunately, no.

In reply to }{0TT@6bI4
User Avatar
7 months ago
Auto-translated
Happy New Year to everyone! While working on the specialization "hero learns Dark Magic spells as they level up," I encountered a problem: if the hero is hired in a tavern instead of being chosen at the start, their specialization won't work. Perhaps something needs to be added to the code?
function IsoldaS()
local hero="Isolda"
local lvl=GetHeroLevel("Isolda")
if lvl == 3 then
    TeachHeroSpell(hero, 12)
elseif lvl == 5 then
    TeachHeroSpell(hero, 11)
elseif lvl == 8 then
    TeachHeroSpell(hero, 15)
elseif lvl == 10 then
    TeachHeroSpell(hero, 14)
elseif lvl == 15 then
    TeachHeroSpell(hero, 13)
elseif lvl == 18 then
    TeachHeroSpell(hero, 17)
elseif lvl == 20 then
    TeachHeroSpell(hero, 18)
elseif lvl == 23 then
    TeachHeroSpell(hero, 212)
elseif lvl == 25 then
    TeachHeroSpell(hero, 210)
elseif lvl == 28 then
    TeachHeroSpell(hero, 215)
elseif lvl == 30 then
    TeachHeroSpell(hero, 214)
elseif lvl == 33 then
    TeachHeroSpell(hero, 211)
elseif lvl == 35 then
    TeachHeroSpell(hero, 213)
elseif lvl == 38 then
    TeachHeroSpell(hero, 21)
elseif lvl == 40 then
    TeachHeroSpell(hero, 20)
end
end

Trigger(HERO_LEVELUP_TRIGGER, "Isolda", "IsoldaS")
User Avatar
7 months ago
Auto-translated

Your code only runs at the start of the map. Therefore, you need to attach the trigger not only at the start but also when the hero appears:

function UpdateHeroSpecs(hero)
if hero == 'Isolda' then
Trigger(HERO_LEVELUP_TRIGGER, hero, 'IsoldaSpec')
elseif hero == 'AnotherHero' then
--...
else
--...
end
end

for pl = PLAYER_1, PLAYER_8 do
if GetPlayerState(pl) == PLAYER_ACTIVE then
Trigger(PLAYER_ADD_HERO_TRIGGER, pl, 'UpdateHeroSpecs')
end
end
In reply to }{0TT@6bI4
User Avatar
7 months ago
Auto-translated
and again, I seem to have done something wrong.
function IsoldaSpec()
local hero="Isolda"
local lvl=GetHeroLevel("Isolda")
if lvl == 3 then
    TeachHeroSpell(hero, 12)
elseif lvl == 5 then
    TeachHeroSpell(hero, 11)
elseif lvl == 8 then
    TeachHeroSpell(hero, 15)
elseif lvl == 10 then
    TeachHeroSpell(hero, 14)
elseif lvl == 15 then
    TeachHeroSpell(hero, 13)
elseif lvl == 18 then
    TeachHeroSpell(hero, 17)
elseif lvl == 20 then
    TeachHeroSpell(hero, 18)
elseif lvl == 22 then
    TeachHeroSpell(hero, SPELL_BLIND)
elseif lvl == 23 then
    TeachHeroSpell(hero, 212)
elseif lvl == 25 then
    TeachHeroSpell(hero, 210)
elseif lvl == 28 then
    TeachHeroSpell(hero, 215)
elseif lvl == 30 then
    TeachHeroSpell(hero, 214)
elseif lvl == 33 then
    TeachHeroSpell(hero, 211)
elseif lvl == 35 then
    TeachHeroSpell(hero, 213)
elseif lvl == 38 then
    TeachHeroSpell(hero, 21)
elseif lvl == 40 then
    TeachHeroSpell(hero, 20)
end
end

function UpdateHeroSpecs(hero)
  if hero == 'Isolda' then
    Trigger(HERO_LEVELUP_TRIGGER, hero, 'IsoldaSpec')
  end
end

for pl = PLAYER_1, PLAYER_8 do
  if GetPlayerState(pl) == PLAYER_ACTIVE then
    Trigger(PLAYER_ADD_HERO_TRIGGER, pl, 'UpdateHeroSpecs')
  end
end
User Avatar
7 months ago
Auto-translated
What isn't working, and what does the console say? Visually, I don't see any obvious errors, but it might just be that it's past midnight.
In reply to }{0TT@6bI4
User Avatar
7 months ago
Auto-translated
}{0TT@6bI4
What isn't working, and what does the console say? Visually, I don't see any obvious errors, but maybe it's just half past midnight.
The spell is NOT being granted.
User Avatar
7 months ago
Auto-translated
Is it not given at the start or when hiring a hero?
In reply to }{0TT@6bI4
User Avatar
7 months ago
Auto-translated
}{0TT@6bI4
It isn't given at the start or when hiring a hero, right?
In both cases.
User Avatar
7 months ago
Auto-translated
Okay, I'll test it tomorrow.
User Avatar
6 months ago
Auto-translated
Hello! Has anyone created a code for adding an extra buff to buff-granting objects? For example, I want to give an object, like the "Tattered Flag" (which provides bonuses to morale and luck for one battle), an additional bonus, say, a speed buff. Naturally, the buff would work the same way as the original, i.e., through GiveHeroBattleBonus(). It would be applied to everyone who touches the object and would not be reapplied until the hero fights someone. Currently, I'm thinking of writing a code that would add everyone who touches the object to a list and assign them a tag like allow_touch = 0 (if 0, then the buff will not be applied upon repeated contact), and then in the function from COMBAT_RESULTS_TRIGGER, track who completed 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 a simpler way?
In reply to Азгалор
User Avatar
6 months ago
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}

User Avatar
6 months ago
Auto-translated
Dolgy, interesting, thank you! And what is the heroT character(s)? Is this the complete code for the mechanics?
In reply to Азгалор
User Avatar
6 months ago
Auto-translated
Azgalor
Dolgy, interesting, thank you! And what are the heroT characters? Is this the complete code for the mechanics?
This is an array of hero names.
User Avatar
5 months ago
Auto-translated
Dear users, here is the code:
-- Pyramid
function golemhouse()
    StartDialogScene("/DialogScenes/DefiantMage/S1/DialogScene.xdb#xpointer(/DialogScene)");
    MessageBox(quest1);
    SetObjectiveState("sec1", OBJECTIVE_ACTIVE, p1);
    local gems = GetPlayerResource(p1, GEM)
    if gremlins >= 1000 and gems >= 100 then
        QuestionBox(pyramidpath, "yes", "no");
    end
end
Trigger(OBJECT_TOUCH_TRIGGER, golem, "golemhouse")
function yes()
    RemoveHeroCreatures(hero, CREATURE_GREMLIN, 1000);
    SetPlayerResource(p1, GEM, gems - 100);
end
function no()
    print("cancel")
end
How can I make it so that when interacting with the object, the cut-scene and message are displayed only once, while the check for fulfilling the requirements is continuous?

Statistics

Welcome our newest member: recijeb

Users Online 2 users 1331 guests