Skip to content

Posts from Scripts

4.8 (8 ratings)
Auto-translated
Hello!
Could you please provide some guidance on scripts?
There's a video on YouTube showing how to make it so that 200 peasants join a hero every Wednesday.
Here's the script:
function Armia()
local day=GetDate(3)
if day==3 then
AddHeroCreatures("Raelag, 1,200);
end;
end;

Trigger (NEW_DAY_TRIGGER "Armia")

I want to expand this function so that random creatures from a selection are added every Wednesday.
That is, a variable like "random" is introduced, and depending on its values, the function performs certain actions.
For example, if it's 1, add peasants; if it's 2, add archers; if it's 3, add swordsmen, and so on. What exactly is added is determined randomly, and each week it's determined anew, rather than the variable taking a value from the selection at the beginning of the game and always adding archers.
How can I do this correctly? Please provide the syntax.
I understand that I need to define a "random" variable in the function and put a condition if then inside the if then condition.
User Avatar
Auto-translated
I'll immediately warn you that "random" is already a reserved variable name; it's the name of a function.
function Armia()
local creatures = {{id1, quantity}, {id2, quantity}, etc}
if GetDate(3)==3 then
creature = creatures[random(length(creatures))+1] --We take a random creature
local id = creature[1] --We get its ID
local amount = creature[2] --And the quantity for this type
CODE that operates with the random ID and quantity
end
end
С уважением, }{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
Let me warn you right away that "random" is already a reserved variable name; it's also the name of a function.
function Armia()
local creatures = {{id1, quantity}, {id2, quantity}, etc}
if GetDate(3)==3 then
creature = creatures[random(length(creatures))+1] -- We take a random creature
local id = creature[1] -- We get its ID
local amount = creature[2] -- And the quantity for this type
CODE that operates with the random ID and quantity
end
end
Thank you very much for the quick response!
And would it be possible to implement it this way?
function Armia()
local day=GetDate(3)
if day==3 then (
local id = random (4)
if id=0 then
AddHeroCreatures("Raelag, 1,200)
elseif id=1 then
AddHeroCreatures("Raelag, 2,50)
elseif id=2 then
AddHeroCreatures("Raelag, 3,30)
and so on.
end;
end;
end;

I'm sure there are syntax errors, but I think the meaning of the question is clear
User Avatar
Auto-translated
Yes, but the IDs probably won't be in order. For example, ID 0 doesn't exist, 1 is peasants, 2 is militia, 3 is swordsmen, 4 is armored infantry, etc. The parenthesis after "then" is unnecessary, and a double equal sign is used in the comparison: ...if id == 1 then ... elseif id == 2, etc.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
Auto-translated
I would also add that after "Raelag" you don't have a comma, which will definitely cause the script to produce an error. Also, there is no comma in the line "Trigger (NEW_DAY_TRIGGER "Armia")" after the word "TRIGGER".
User Avatar
Auto-translated
Tobito, in general, I recommend using this script editor (by VAlex) => https://disk.yandex.ru/d/W6cz5UBu3SGAvb

It will immediately highlight all errors, such as missing commas and quotation marks, or single equals signs in conditions.
С уважением, }{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
Everything worked out, thank you for your help!
Auto-translated
Hello, please help me write the following script, as I don't understand how. The red player can open the Red Gate if the green and orange players have been defeated.
User Avatar
Auto-translated
function OpenRedBoard(hero, obj) if GetObjectOwner(hero) == PLAYER_1 then if not (GetPlayerState(Green Player Number) == PLAYER_ACTIVE or GetPlayerState(Orange Player Number) == PLAYER_ACTIVE)) then SetObjectEnabled(obj, 1) Trigger(OBJECT_TOUCH_TRIGGER, obj, nil) end end end SetObjectEnabled("Border Guard Name", nil) Trigger(OBJECT_TOUCH_TRIGGER, "Border Guard Name", "OpenRedBoard") ``` Try something like this.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
Auto-translated
Well, I tried, but in the end, the gate still requires a key even after defeating 2 key players.
https://disk.yandex.ru/i/MIFLpv7heo7i1g
In reply to Shiroyasha2910
User Avatar
Auto-translated
Shiroyasha2910
Well, I tried, but in the end, the gate still requires a key even after defeating the 2 key players. https://disk.yandex.ru/i/MIFLpv7heo7i1g
The editor already indicated where the error is.
На дальней станции сойду...
Трава по пояс,
Зайду в траву, как в море босиком...
In reply to Shiroyasha2910
User Avatar
Auto-translated
Shiroyasha2910
Well, I tried it, but in the end, the gate still requires a key even after defeating 2 key players. https://disk.yandex.ru/i/MIFLpv7heo7i1g
The script shows that there is an error in the 3rd line, which causes it to reach that line and break, failing to load the remaining lines of code and not performing the assigned functionality. The error is probably due to an extra parenthesis here: == PLAYER_ACTIVE) ) then
User Avatar
Auto-translated

Hello. I'm writing about what seems like a simple issue. After the QuestionBox, when the OK option is selected, a battle should start (this battle should take place with the hero who made the choice, not with a specific hero). But the console throws an error and says something like: Hero "1" does not exist. I understand that I've made a mistake somewhere with the hero variable and probably don't know something about all of this. I would like to know what I forgot to add to the scripts this time. Thank you in advance.

function DwarfCombat(hero)
StartCombat(hero, nil, 4, CREATURE_STONE_DEFENDER, 175, CREATURE_BERSERKER, 65, CREATURE_FLAME_KEEPER, 45, CREATURE_WARLORD, 35, nil, 'ringfound', nil)
end;
Сценарий: "Наследие прошлого"
Кампании:
"
Новый порядок", "Серый Альянс""Поиски Истины"

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

Statistics

Welcome our newest member: Emil