Skip to content

Posts from Scripts for beginners.

4.5 (2 ratings)
User Avatar
Auto-translated
Hello everyone. Maybe someone can help me with a script where all mines only provide resources if a certain number of, for example, level 1 units are stationed in them (in the garrison – inside the mine).
Auto-translated
My dear friends! Could anyone spare a few minutes to help me out?
I'm trying to create a script that doubles the army size. I borrowed the script from "Random Wars" as a base.
[spoiler=This works, but only for one hero]
function incom()
local day = GetDate(3)
if day == 2 then
        local hero = GetPlayerHeroes(5)[0]
        local types = {}
        types[0], types[1], types[2], types[3], types[4], types[5],types[6] = GetHeroCreaturesTypes(hero)
        for i = 0, 6 do
        if HasHeroCreature(hero, types)
        then
                --local stack = GetCreatureById(types)
                local amount = GetHeroCreatures(hero, types)
                AddHeroCreatures(hero, types, amount, i)
            end
        end
    end
end

Trigger(NEW_DAY_TRIGGER, "incom")
[/spoiler]

I want to implement a scheme with multiple heroes, but I don't know how to write it correctly.
[spoiler=Doesn't work]
function incom()
local day = GetDate(3)
if day == 2 then
    local hero = {}
    hero[0], hero[1], hero[2], hero[3] = GetPlayerHeroes(5)
    for k = 0, 3 do
    if IsHeroAlive(hero)
    then
        local types = {}
        types[0], types[1], types[2], types[3], types[4], types[5],types[6] = GetHeroCreaturesTypes(hero)
        for i = 0, 6 do
        if HasHeroCreature(hero, types)
        then
                local stack = GetCreatureById(types)
                local amount = GetHeroCreatures(hero, types)
                AddHeroCreatures(hero, types, amount, i)
                end
                end
            end
        end
    end
end

Trigger(NEW_DAY_TRIGGER, "incom")
[/spoiler]
The function IsHeroAlive(hero) produces an invalid argument #1, i.e., instead of 'hero', something inedible appears.
User Avatar
Auto-translated
The thing is, the GetPlayerHeroes function itself returns an array, so the values of the array fields "heroes" from 2 to 5 are nil, and the first one is a table. The same applies to the "hero" table itself, so in your case, both IsHeroAlive(hero) and IsHeroAlive(hero[k]) will fail – with the error you specified. Therefore, you need to copy the table from the GetPlayerHeroes function into a local array called "heroes," then iterate through the array and perform the specified actions. ```lua function incom() local day = GetDate(3) if day == 2 then local heroes = GetPlayerHeroes(5) for k, hero in heroes do if IsHeroAlive(hero) then local types = {} types[0], types[1], types[2], types[3], types[4], types[5], types[6] = GetHeroCreaturesTypes(hero) for i = 0, 6 do if HasHeroCreature(hero, types[i]) then local stack = GetCreatureById(types[i]) -- If you copied this from RW, I hope you also copied the GetCreatureById function. local amount = GetHeroCreatures(hero, types[i]) AddHeroCreatures(hero, types[i], amount, i) end end end end end end Trigger(NEW_DAY_TRIGGER, "incom")
С уважением, }{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
I bow to you, Most Wise Wizard! Without a ready-made script, I wouldn't have understood anything, as I am uneducated. And yes, the function exists, but I have removed (commented out?) the local stack because it is unnecessary.
In reply to sspi
User Avatar
Auto-translated
sspi
  My deepest respect to you, Most Wise Wizard! Without a ready-made script, I wouldn't have understood anything, as I am uneducated.
And yes, the functions are there, but I have removed (commented out?) the local stack as it is not needed.
I advise you to follow the link in the signature of the respected Wizard; in the Files section, you will find an invaluable library of Scripting (and other) Arts, authored by Hottabych and other Atlantean mapmakers.


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

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


                                                                                       
Auto-translated
Hello! Can anyone tell me how to create a script so that on a specific day, a creature building of a certain level is constructed in a town, if this building was previously prohibited. (i.e., for example, creatures of level 7 cannot be built in a town, but after 2 weeks, it becomes possible, and the building is constructed automatically, or the building becomes available). If such scripts can be made, of course. Thank you. Sorry, I don't understand anything about scripts...
In my case, I want to make it so that after 14 days, it becomes possible to build Titans in the Academy, even though creatures of level 7 could not be built before.
P.S. I apologize for my noob question, but I have reviewed all the previous pages and did not find such a question or script.
User Avatar
Auto-translated
function NewDay() if GetDate(DAY) == 14 then UpgradeTownBuilding("Town", TOWN_BUILDING_DWELLING_7, level) -- 0 - not built, 1 - built, 2 - upgraded end end Trigger(NEW_DAY_TRIGGER, "NewDay")
С уважением, }{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
}{0TT@6bI4
function NewDay()
if GetDate(DAY) == 14 then
UpgradeTownBuilding("Town", TOWN_BUILDING_DWELLING_7, level) --0— not built, 1 — built, 2 — upgraded
end
end

Trigger(NEW_DAY_TRIGGER, "NewDay")
Thank you very much, boss!
User Avatar
Auto-translated
Good day! Could someone suggest a script that, upon capturing a Haven city, would delete that city and replace it with a ruined city?
In reply to BlueHeavenHero
User Avatar
Auto-translated
BlueHeavenHero
Good day! Could someone suggest a script that, when a Haven town is captured, the town is removed and replaced with a ruined town?
There is a script command called RazeTown("script name of the town"). It can be used by default to destroy the castles of Humans and Demons. For the castles of other factions, you need to make some adjustments.
Сценарий: "Наследие прошлого"
Кампании:
"
Новый порядок", "Серый Альянс""Поиски Истины"

Трейлер №2 кампании "Дыхание Пустоты": https://www.youtube.com/watch?v=XkHKXk5BctA&ab_channel=%D0%90ndrei_21

In reply to Andrei_21
User Avatar
Auto-translated
Andrei_21
There is a script command RazeTown("script name of the town"). With its help, you can destroy Haven and Dungeon castles by default. For castles of other factions, you need to make some adjustments.
Could you explain? I searched through the game files and found this script, but unfortunately, I didn't understand anything.
Thank you in advance.
User Avatar
Auto-translated
function CaptureTown()
RazeTown('your town name')
end

Trigger(OBJECT_CAPTURE_TRIGGER, 'your town name', 'CaptureTown')
It's simple: you assign a script name to the town in the map editor, and then you write something like this function in the script editor.
Сценарий: "Наследие прошлого"
Кампании:
"
Новый порядок", "Серый Альянс""Поиски Истины"

Трейлер №2 кампании "Дыхание Пустоты": https://www.youtube.com/watch?v=XkHKXk5BctA&ab_channel=%D0%90ndrei_21

In reply to Andrei_21
User Avatar
Auto-translated
Could someone explain how to use the SetObjectiveState script? Many people suggested using it when I asked how to create an object that gives a quest.
Ideally, with examples, because I won't understand much without them.
In reply to BlueHeavenHero
User Avatar
Auto-translated

BlueHeavenHero
Can someone explain to me how to use the SetObjectiveState script? Many people suggested using it when I asked how to create an object that gives a quest.
Ideally, with examples, because I won't understand much without them.
SetObjectiveState changes the state of a quest with the name objectiveName for a specific player. For quests belonging to a specific player, the playerID parameter is ignored. For global quests, if the playerID parameter is specified, it indicates for which player the quest state should be changed; otherwise, the quest state is changed for the first player.

In simple terms, the script activates a quest, completes/fails it.

SetObjectiveState("prim1", OBJECTIVE_ACTIVE) -- the first parameter is the quest name, the second is the status.
function PRIM3_COMPL()
Trigger(REGION_ENTER_AND_STOP_TRIGGER, '4', nil)
if GetCurrentPlayer()==1 then
SetObjectiveState("prim3", OBJECTIVE_COMPLETED) -- the same, but with a different quest status.
print("32")
end
end

Trigger(REGION_ENTER_AND_STOP_TRIGGER, '4', 'PRIM3_COMPL')

На дальней станции сойду...
Трава по пояс,
Зайду в траву, как в море босиком...
User Avatar
Auto-translated

BlueHeavenHero,

OBJECTIVE_ACTIVE - makes a quest active, meaning it can be completed and will be displayed to the player(s).

OBJECTIVE_COMPLETED - completes a quest.

OBJECTIVE_FAILED - fails a quest.

The OBJECTIVE_UNKNOWN status is also used for various situations, mainly in the GetObjectiveState function, to check if the quest has already been issued, in other words, if it doesn't have one of the previously mentioned statuses.

P.S. I can also add that you can set the "CanUncomplete" property of quests to "true," which will allow you to restart quests, i.e., make completed quests active again.

Statistics

Welcome our newest member: Emil