Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Долгий
User Avatar
Auto-translated
Dolgy

IsAIPlayer(Player_ID)

If the player is human, it returns 0; if it's AI, it returns 1.
Thank you.
Once again, I'm puzzled: what kind of document is lying around in the game folder?
I (as you noticed) don't have that again...
Although, I can find a line in the document.
Next time, I'll intuitively guess the function name and hope for the best. :)

Added 1 minute ago
Azgalor
Among the official ones, I only noticed IsHuman and IsComputer in combat scripts. But, as I understand it, you need functions for a non-combat script?
Yes, I wanted it for an adventure map. In general, I know how to check it through some convoluted process, but it takes 10 lines for a simple action.
Dolgy, it seems, found it on a topic about undocumented functions.


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       
User Avatar
Auto-translated
Jewill, you use a script editor, right? In the desired location of the file, click, then press Ctrl+SPACE. A context window will open – it contains all the functions + undocumented ones (about 99%). There you can also find IDs.

If you place the cursor in the properties of a function where you need to insert an ID, for example, after Trigger(, then the IDs of triggers (or the IDs needed for the function) will immediately appear in the context menu.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
User Avatar
Auto-translated
}{0TT@6bI4
Jewill, you use a script editor, right? In the right place in the file, you click, then press Ctrl+SPACE. A context window will open – it contains all the functions + undocumented ones (about 99%). There you can also find the IDs.

If you place the cursor in the properties of a function where you need to insert an ID, for example, after Trigger(, then the IDs of triggers (or the IDs needed for the function) will immediately appear in the context menu.
Thank you, it really is more convenient to work this way.
I also managed to integrate the script editor into VS Code after some tweaking, but some things still don't work.
If I figure it out, would anyone be interested?
It's also not a problem to connect the file structure through a script for automatic archiving.
But that's tedious, and I don't know if anyone would need it.


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       
User Avatar
Auto-translated
So, the idea is to open the script editor code in Visual Studio or turn Visual Studio into a Heroes script editor? It would be interesting to know what functionality would be available then. For now, the advantages of working in VS are not very clear, so I won't ask you to share it yet...
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
User Avatar
Auto-translated
}{0TT@6bI4
So, the idea is to either open the script editor code in Visual Studio or turn Visual Studio into an editor for Heroes scripts, right? I'm curious to know what functionality would be available then.

For now, the advantages of working in VS aren't very clear, so I won't ask you to share it...
No, there aren't any advantages, except for habit. For me, it's like getting into my favorite old car: it's just for the soul. But for newcomers who haven't seen code in text documents or on paper, it might be convenient. But there are very few of them, unfortunately. And functionally, the abbreviation system doesn't work there (you have to manually rearrange the functions, change their descriptions (encoding issues arise), it's a lot of tedious work), and the problem that, as you know, in Heroes, there's one version of Lua, and in the editor, it's slightly newer, hasn't been resolved yet.


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       
In reply to }{0TT@6bI4
User Avatar
Auto-translated
Does anyone know the name of the function that controls the creature growth rate in dwellings? My idea is this: if the condition is not met, then when a new week begins in the daily function (the one called NEW_DAY_TRIGGER), the dwelling's growth rate is 0. P.S. I've already found SetObjectDwellingCreatures. Strangely, it doesn't work on dwellings, only on towns. Is there a similar function that works on dwellings?
In reply to Долгий
User Avatar
Auto-translated
Long
Does anyone know the name of the function that regulates the creature growth in dwellings? My idea is this: if the condition is not met, then when a new week arrives in the daily function (the one called NEW_DAY_TRIGGER), the dwelling growth is equal to 0.

P.S. I've already found SetObjectDwellingCreatures. Strangely enough, it doesn't work on dwellings, only on cities. Is there a similar function that works on dwellings?
To be honest, it seems like a trivial task, and I couldn't find a solution myself at the time. The described function only works with cities, that's true. And I didn't find another one, nor did I see it in the documentation.


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       
Auto-translated
Hottabych, even though you haven't been here for a couple of months, maybe you'll answer.
(Or someone, please help, kind people).

You once taught me how to write a combat script for ГГ. Here it is, if you remember:
------------------------------------------------------------------------------------------------------
function Start()

Level_R = ceil(GetGameVar("LevR") + 0)

    if GetHeroName(GetAttackerHero()) == 'Raelag' then
        local mana = GetUnitManaPoints(GetAttackerHero());
        SetUnitManaPoints(GetAttackerHero(), 200);
        repeat sleep(1) until GetUnitManaPoints(GetAttackerHero())==200;
        sleep(1);
         if Level_R < 20 then
           for i, creature in GetDefenderCreatures() do
             startThread(UnitCastAimedSpell, GetAttackerHero(), 4, creature);
                 end;
               SetUnitManaPoints(GetAttackerHero(), mana);
            else
              for i, creature in GetDefenderCreatures() do
               startThread(UnitCastAimedSpell, GetAttackerHero(), 226, creature);
                end
                 SetUnitManaPoints(GetAttackerHero(), mana);
                   end
    else
    if GetHeroName(GetDefenderHero()) == 'Raelag' then
        local mana = GetUnitManaPoints(GetDefenderHero())
        SetUnitManaPoints(GetDefenderHero(), 200);
        repeat sleep(1) until GetUnitManaPoints(GetDefenderHero())==200
        sleep(1);
         if Level_R < 20 then
           for i, creature in GetAttackerCreatures() do
            startThread(UnitCastAimedSpell, GetDefenderHero(), 4, creature);
             end;
              SetUnitManaPoints(GetDefenderHero(), mana);
             else
               for i, creature in GetAttackerCreatures() do
                startThread(UnitCastAimedSpell, GetDefenderHero(), 226, creature);
                  end;
                  SetUnitManaPoints(GetDefenderHero(), mana);
                     end
                   end;
                  end;
                end;
------------------------------------------------------------------------------------------------------

How do I add another script to the combat script, for the enemy?
I've tried everything.
I tried writing something like:

------------------------------------------------------------------------------------------------------
if GetHeroName(GetAttackerHero()) == 'Shadwyn' then
      if GetHeroName(GetDefenderHero()) == 'Nur' then
            local mana = GetUnitManaPoints(GetDefenderHero())
        SetUnitManaPoints(GetDefenderHero(), 200);
        repeat sleep(1) until GetUnitManaPoints(GetDefenderHero())==200
        for i, creature in GetAttackerCreatures() do
          startThread(UnitCastAimedSpell, GetDefenderHero(), 3, creature)
        end;
        SetUnitManaPoints(GetDefenderHero(), mana);
         
        else
        if GetHeroName(GetAttackerHero()) == 'Shadwyn' then
        local mana = GetUnitManaPoints(GetAttackerHero());
        SetUnitManaPoints(GetAttackerHero(), 200);
        repeat sleep(1) until GetUnitManaPoints(GetAttackerHero())==200;
        sleep(1);
         if Level_R < 20 then
           for i, creature in GetDefenderCreatures() do
             startThread(UnitCastAimedSpell, GetAttackerHero(), 4, creature);
                 end;
               SetUnitManaPoints(GetAttackerHero(), mana);
            else
              for i, creature in GetDefenderCreatures() do
               startThread(UnitCastAimedSpell, GetAttackerHero(), 279, creature);
                end
                 SetUnitManaPoints(GetAttackerHero(), mana);
                   end
------------------------------------------------------------------------------------------------------

And so on, then for the defender - it still doesn't work. Although Nazir reliably casts lightning on my Illia, but in other battles she can't use Ice Block, it says "ERROR: Wrong type of argument 1, when calling function GetHeroName".

I tried changing the order of if GetHeroName(GetAttackerHero()) == 'Shadwyn' then and if GetHeroName(GetDefenderHero()) == 'Nur' then - it's the same.

I tried to specify Nazir together with Illia in MapScript:

path = '/'..GetMapDataPath()
main_hero = 'Shadwyn'
MagHero = 'Nur'

SetHeroCombatScript('Shadwyn', path.."CombatScript.xdb#xpointer(/Script)");
SetHeroCombatScript('Nur', path.."CombatScript.xdb#xpointer(/Script)");

- it doesn't help either.
I even tried to assign a separate CombatScript to Nazir - but it seems the game doesn't even see it.

In general, is it possible to assign combat scripts to multiple heroes, and how to do it?
User Avatar
Auto-translated
Martha, hello. Why haven't you been around for a few months? I visit the forum at least twice a week due to my duties. It's not very convenient to understand code on a phone; I'll take a look on my computer tomorrow evening.

I'll say this right away: if two heroes with attached combat scripts meet in battle, the combat script of the attacking hero is used.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
Auto-translated
Hottabych, - there wasn't one because last time I drew a huge, very detailed, and high-relief map, but it turned out that playing on it was a real pain).
So, I gave up and stopped, sorry - I wasted so much effort.
Now it's easier; I've learned from my past mistakes. Let me know how you can help - I still have a long way to go before I finish drawing the main boss, and the second combat unit needs a script.
User Avatar
Auto-translated
local defH, attH = GetDefenderHero(), GetAttackerHero()
if defH then --If a defending hero is present (an attacking hero is always present), then...
if GetHeroName(defH) == ".." and GetHeroName(attH) = "...." then --If a specific hero is defending, and another specific hero is attacking, then...
--Further actions with the heroes; defH contains the name of the defending hero, attH contains the name of the attacking hero
--Also, for this second script, remove the check if Level_R>20 (and its else and end) — is this a check for Raileigh's level?
--Your code...
end
end
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
Auto-translated
The error "Wrong type of argument 1, when calling function GetHeroName()" is related to the fact that when there is no defending hero (battle with neutral creatures), GetDefenderHero returns nil, and GetHeroName must receive a hero's name as its first parameter. When nil is passed to it, it throws an error. Therefore, a check is needed to ensure that the variable is not nil (code above).
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
Auto-translated
Hottabych, please be a bit more straightforward with the explanation). I didn't understand anything because I've never studied programming.

What I meant was that when attacking the main villain (let's say, Nazir), he will cast lightning spells on the attacking Ilia, even though in a normal battle, she casts an ice block spell on everyone.

Is all of this written in the combat script? And do I need to create a new function and write it under the first one?
It seems to be giving me an error:

-------------------------------------------------------------------------------------------
function Nur_battle()

local defH, attH = GetDefenderHero(), GetAttackerHero()

if GetHeroName(defH) == "Nur" and GetHeroName(attH) = "Shadwyn" then
local mana = GetUnitManaPoints(GetDefenderHero())
SetUnitManaPoints(GetDefenderHero(), 200);
repeat sleep(1) until GetUnitManaPoints(GetDefenderHero())==200
for i, creature in GetAttackerCreatures() do
startThread(UnitCastAimedSpell, GetDefenderHero(), 3, creature)
end;
SetUnitManaPoints(GetDefenderHero(), mana);
elseif
if GetHeroName(defH) == "Shadwyn" and GetHeroName(attH) = "Nur" then
local mana = GetUnitManaPoints(GetAttackerHero())
SetUnitManaPoints(GetAttackerHero(), 200);
repeat sleep(1) until GetUnitManaPoints(GetAttackerHero())==200
for i, creature in GetDefenderCreatures() do
startThread(UnitCastAimedSpell, GetAttackerHero(), 3, creature)
end;
SetUnitManaPoints(GetAttackerHero(), mana);
-------------------------------------------------------------------------------------------
and so on.

The editor gives an error on the line
if GetHeroName(defH) == "Nur" and GetHeroName(attH) = "Shadwyn" then

If you write
if defH then
if GetHeroName(defH) == "Nur" and GetHeroName(attH) = "Shadwyn" then
then it gives an error on the line if defH then.

I understand that I'm being slow, but I can't help it). Please answer when you have time; it's not urgent for me right now.

In reply to Марта
User Avatar
Auto-translated
Martha

The Editor is giving an error on the line:
if GetHeroName(defH) == "Nur" and GetHeroName(attH) = "Shadwyn" then

If you write:
if defH then
if GetHeroName(defH) == "Nur" and GetHeroName(attH) = "Shadwyn" then
then it gives an error on the line if defH then.

I understand that I'm being slow, but I can't help it. Answer when you have time, it's not urgent for me.

Specifically, the error here is because GetHeroName(attH) = "Shadwyn" contains one equals sign, but it should be two.
Read the guides in the Khottabych group; combat scripts are not the simplest thing in Heroes. I, for example, with sufficient experience in writing global map scripts, won't be able to help you much - because I don't have experience writing combat scripts, I might give you bad advice.


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       

Statistics