Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
#3565
Auto-translated
while 1 do pfonix = GetHeroCreatures( "Main_Hero", CREATURE_PHOENIX); if pfonix >= 5 then SetObjectiveState("dzad3", OBJECTIVE_COMPLETED); SetObjectiveState("dzad2", OBJECTIVE_FAILED); break; end; sleep(1) end ``` There's a missing `sleep` in the last cycle, so if the condition `pfonix >= 5` is not met (correctly spelled as "phoenix" in English, not "pfonix"), the game will crash after the first iteration. Something like that.
С уважением, }{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
#3566
Auto-translated
}{0TT@6bI4
while 1 do
pfonix = GetHeroCreatures( "Main_Hero", CREATURE_PHOENIX);
if pfonix >= 5 then
SetObjectiveState("dzad3", OBJECTIVE_COMPLETED);
SetObjectiveState("dzad2", OBJECTIVE_FAILED);
break;
end;
sleep(1)
end

The last loop is missing a sleep command, so if the condition pfonix >= 5 (correctly spelled phoenix, not pfonix in English) is not met, the game will crash after the first iteration. Something like that.

Now everything is clear. Thank you very much!
Сценарий: "Наследие прошлого"
Кампании:
"
Новый порядок", "Серый Альянс""Поиски Истины"

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

In reply to Andrei_21
User Avatar
#3567
Auto-translated
What script is needed so that in buildings where creatures are recruited, creatures can be recruited only once throughout the entire game?
User Avatar
#3568
Auto-translated
In the function for the new day:
if GetDate(DAY_OF_WEEK)==0 then
SetObjectDwellingCreatures("City Name", creature ID, 0)
end

If there are several such creatures, then create an array of IDs:
if GetDate(DAY_OF_WEEK)==0 then
local id_table = {id1, id2, id3, ....}
for key, id in id_table do
SetObjectDwellingCreatures("City Name", id, 0)
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
User Avatar
#3569
Auto-translated
What script is needed to trigger multiple quests after a dialogue?
In reply to Alinksolo
User Avatar
#3570
Auto-translated
By the way, how does the sleep script actually work? I just can't seem to understand it.
In reply to Григорий Ковалев
User Avatar
#3571
Auto-translated
Grigory Kovalev
By the way, how does the sleep script actually work? I just can't seem to understand it.

Grigory, this is how the delay between scripts works:
Your code
sleep(1) - the time delay is specified in parentheses. Keep in mind that sleep(1) is equal to 200ms.
Your code

This function is very useful if you first need to, for example, play a beautiful effect, and after it finishes, destroy some object.
Сценарий: "Наследие прошлого"
Кампании:
"
Новый порядок", "Серый Альянс""Поиски Истины"

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

In reply to Andrei_21
User Avatar
#3572
Auto-translated
So, if I understand correctly, the `sleep` command introduces a delay between scripts? If that's the case, I'm going to try it out.
User Avatar
#3573
Auto-translated
Give it a try, Grigory. Knowing where to place the `sleep` function is one of the most important concepts in Lua.
Сценарий: "Наследие прошлого"
Кампании:
"
Новый порядок", "Серый Альянс""Поиски Истины"

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

In reply to Alinksolo
User Avatar
#3574
Auto-translated
Alinksolo
What script is needed to issue several quests after a dialogue?
Quests are issued using this command: SetObjectiveState('quest_name', state, playerID = PLAYER_1); You can write this command several times to issue different quests.
In reply to John_Lock
User Avatar
#3575
Auto-translated
User01322342
The task is assigned using this command: SetObjectiveState('task_name', state, playerID = PLAYER_1); You can write this command several times to assign different tasks.
If it is set as manually controlled.
In reply to Григорий Ковалев
#3576
Auto-translated
Help, kind people! Does anyone happen to know how to write a separate script for a garrison gate? I haven't come across anything like that before, but this model has a Script tab. Isn't it a simple script, without any introductions? I want only the owner of a specific castle and another specific castle to be able to pass through the gate, meaning two conditions. How do I write that?
In reply to Марта
User Avatar
#3577
Auto-translated
Martha
Help, kind people.
Does anyone happen to know how to write a separate script for the gates of a garrison?
I haven't come across anything like that before, and yet, in this model, there is a Script tab.
Surely, it's not a function; you just need to write it directly, without any introductions, right?
I want only the owner of a specific castle and another specific castle to be able to pass through the gates, that is, two conditions.
How is this written?

You can create a region where the garrison is located. Then, using a script, block the region with SetRegionBlocked. SetRegionBlocked("region name", true or false, 1)
True blocks, false unblocks.
1 is the player number, i.e., red. The second is blue, and so on.
User Avatar
#3578
Auto-translated
There's a simpler option.
function GarrisonBlock()
while 1 do
if GetObjectOwner("Castle2")==GetObjectOwner("Castle1") then --Your condition is true only if both castles belong to the same player
SetObjectEnabled("Garrison", 1, GetObjectOwner("Castle1")) --Unlock the garrison for the owner of both castles
while not IsObjectEnabled("Garrison") do sleep(1) end
end
for i=1,8 do
if GetPlayerState(i)==PLAYER_ACTIVE and i~=GetObjectOwner("Castle1") and i~=GetObjectOwner("Castle2") and IsObjectEnabled("Garrison") then --If the player is active and is not the owner of both castles, but the garrison is unlocked for him, then
SetObjectEnabled("Garrison", nil, i) --Lock the garrison for him
end
end
sleep(1)
end

startThread(GarrisonBlock)

Yes, the script isn't very elegant; you could have put the names in variables to avoid writing it 5 times, and even better, put them in function arguments. You could also use a trigger for changing the castle owner and a check at the start of the map to avoid an unnecessary loop.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
#3579
Auto-translated
Thanks, I'll try it now.

Added 36 minutes later
Hottabych, the script doesn't seem to be working. The script editor immediately started giving errors, but I added another "end" before "sleep," and it stopped. However, now, when I try to load the map, the game freezes completely at the "press any key" message, and I have to exit using Ctrl + Alt + Del; there's no other way. Did I understand correctly that I need to write the script in the Map Script, and not on the gates themselves? And this line confuses me: while not IsObjectEnabled("Garnizon_1") do sleep(1)end I don't understand Lua or scripts at all, but this is the first time I've encountered writing "end" just like that at the end – is that how it should be, "do sleep(1)end," or should it be written on a new line or two lines?

Statistics

Welcome our newest member: dodoD0D0