Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Марта
User Avatar
#3701
Auto-translated
Martha
What should I even do about this problem? Will I have to create another region for the REGION_ENTER_AND_STOP_TRIGGER and somehow get the main character there?
The trigger might have been defined incorrectly.
There is such a thing as threads. This is, in essence, a function that is executed periodically.
However, if you don't put a delay (i.e., sleep) in it, the game will crash.
Example:
-- in general, you need to pass all parameters to this function and try to make everything as parameterized as possible,
-- but we're not launching into space, so let's stick to old-school methods
function checkState()
while(1) do
if(GetObjectiveProgress("Quest_Zubec",player) == 3) then
-- Do things
break -- if you don't put a break, it will be painful.
end
sleep(5) -- You can wait longer, it all depends on the needs
end
startThread("checkState")

This method is suitable for checking artifacts or something else non-trivial. In your case, a trigger should be enough (in theory):

Trigger(OBJECTIVE_STATE_CHANGE_TRIGGER ,"Quest_Zubec_Handler","Quest_Zubec")

function Quest_Zubec_Handler(player)
if(player == 1 and GetObjectiveProgress("Quest_Zubec",1) == 3) then
-- Do things
end
end

It is possible that the function called by the trigger is passed the name of the quest, and it doesn't need to be written again, but I have never tested this. Try it.



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

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


                                                                                       
In reply to Jewily
#3702
Auto-translated
Jewily, thank you, I'll try it now.


Added 27 minutes ago
If we're talking about writing this:

function Quest_Zubec_Handler(player)
  if(player == 1 and GetObjectiveProgress("Quest_Zubec",1) == 3) then
MessageBox ("/Maps/SingleMissions/L1/Parol_Zubec1.txt");
sleep(2);
 end
end
Trigger(OBJECTIVE_STATE_CHANGE_TRIGGER ,"Quest_Zubec_Handler","Quest_Zubec")

And nothing else anywhere, then I only managed to load the map (the quest hasn't been taken yet), and the game already gives me this:

(Script) Error: Objective with name "Quest_Zubec_Handler" is not exists

It seems there's no point in checking? There's a fight that lasts at least half an hour, even with cheats.
I'll try the first option, with the thread.

Added 12 minutes ago
Regarding the first option - the starting video didn't even play because I put that version at the very top.

Here's the script:

function checkState()
  while(1) do
   if(GetObjectiveProgress("Quest_Zubec",player) == 3) then
    MessageBox ("/Maps/SingleMissions/L1/Parol_Zubec1.txt");
    break
   end
   sleep(8) 
  end
  end
  startThread("checkState")

The game says:
(Script) Error: StartTread first parameter must be a function

It seems I'm cursed today). Either the map glitched, and I spent the whole night figuring out how to restore it (I didn't know that the editor could somehow delete files for Map Properties and not allow restoring them, even in earlier versions of the map), or now this...

Added 9 minutes ago
Stop, stop. In the version without a thread, it seems the function and quest names are mixed up.
But if I write

Trigger(OBJECTIVE_STATE_CHANGE_TRIGGER ,"Quest_Zubec","Quest_Zubec_Handler")

take the quest, and immediately use it on SetObjectiveProgress("Quest_Zubec", 3, 1);
then the game doesn't react at all, and doesn't write anything.

In reply to Марта
User Avatar
#3703
Auto-translated
Martha
Jewily, thank you, I'll try it now.


Added 27 minutes ago
If the goal is to write this:

function Quest_Zubec_Handler(player)
  if(player == 1 and GetObjectiveProgress("Quest_Zubec",1) == 3) then
MessageBox ("/Maps/SingleMissions/L1/Parol_Zubec1.txt");
sleep(2);
 end
end
Trigger(OBJECTIVE_STATE_CHANGE_TRIGGER ,"Quest_Zubec_Handler","Quest_Zubec")

And nothing else anywhere, then I only managed to load the map (the quest hasn't been taken yet), and the game already writes:

(Script) Error: Objective with name "Quest_Zubec_Handler" is not exists

Apparently, it doesn't make sense to go and check? There's a battle that lasts at least half an hour, even with cheats.
I'll try the first option, with the thread.

Added 12 minutes ago
Regarding the first option - the starting video didn't even load because I put that option at the very top.

Here's the script:

function checkState()
  while(1) do
   if(GetObjectiveProgress("Quest_Zubec",player) == 3) then
    MessageBox ("/Maps/SingleMissions/L1/Parol_Zubec1.txt");
    break
   end
   sleep(8) 
  end
  end
  startThread("checkState")

The game writes:
(Script) Error: StartTread first parameter must be a function

It seems I'm cursed now). Either the map glitched, and I spent the whole night figuring out how to restore it (I didn't know that the editor could somehow delete files for Map Properties and not allow restoring them, even in earlier versions of the map), or now this.


Added 9 minutes ago
Stop-stop. In the option without a thread, it seems that the function and quest names are mixed up.
But if you write

Trigger(OBJECTIVE_STATE_CHANGE_TRIGGER ,"Quest_Zubec","Quest_Zubec_Handler")

take the quest, and immediately use it on SetObjectiveProgress("Quest_Zubec", 3, 1);
then the game doesn't react at all, and doesn't write anything.

I made a slight mistake with the thread; there are probably extra quotes there.
You just need to specify the function name.
I can't help with the rest for now because, as you can see, without a computer, typos and blunders happen.


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

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


                                                                                       
In reply to Jewily
#3704
Auto-translated
Woo, it worked!

function checkState()
  while(1) do
   if (GetObjectiveProgress("Quest_Zubec", 1) == 3) then
    MessageBox ("/Maps/SingleMissions/L1/Parol_Zubec1.txt");
    break
   end
   sleep(8)
  end
  end
  startThread(checkState)

I'm so confused – I've been working on this script for almost a day, and I initially wrote ("Quest_Zubec", player).
But if you keep trying, something will eventually work out, I guess.
Thank you).
In reply to Марта
User Avatar
#3705
Auto-translated
Martha

But if you suffer for a long time, something will eventually work out.
.
Per aspera ad astra.
I'm looking forward to your map; it's great that you're working hard on the scripts :)


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

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


                                                                                       
In reply to Jewily
#3706
Auto-translated
Heh, I'll probably be working on it for another six months, if it doesn't crash in the meantime. I got carried away with the details again, with scripts that are kilometers long, textures, and so on. But I'll try to finish it anyway.
User Avatar
#3707
Auto-translated
It won't crash. At most, it might lag during map loading.

Sometimes, it's easier to use obvious workarounds than to overcomplicate things. To solve this problem without regions and triggers (and generally, without any settings for a garrison, even without assigning it a name), you'll need a brief introduction to OOP, a discussion of several new, complex functions, and an understanding of tables in Lua.

Jewilly, if you're interested in an elegant solution, I'll just say what it's based on:
Using the IsTilePassable function, you can check the location of blocked cells relative to the center of the object (for a garrison, one is above, one is below). After identifying the garrison's orientation, the hero is simply moved to the other side using SetObjectPosition with teleportation type 0 (without animation) if the hero's owner is not a banned player (all of this is done through a touch trigger).

And for aesthetics, you can create a "Garrison" class with methods like BanPlayer, UnbanPlayer, and other similar things if you want to add any effects, additional messages, and so on.
С уважением, }{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
#3708
Auto-translated
}{0TT@6bI4
It won't crash. At most, it might lag when loading the map.

Sometimes it's easier to use obvious workarounds than to overcomplicate things. To solve this problem without regions and triggers (and generally, without any settings for a garrison, even without assigning it a name), you'll need a brief introduction to OOP, a discussion of several new, complex functions, and an understanding of tables in Lua.

Jewilly, if you're interested in a more elegant solution, I'll just say what it's based on:
Using the IsTilePassable function, you can check the location of blocked cells relative to the center of the object (for a garrison, one is above, one is below). After identifying the garrison's orientation, the hero is simply moved to the other side using SetObjectPosition with teleportation type 0 (without animation), if the hero's owner is not a banned player (all of this is done through a touch trigger).

And for aesthetics, you can create a "Garrison" class with methods like BanPlayer, UnbanPlayer, and other such things, if you want to add any effects, additional messages, etc.
Excellent solution, indeed. It maximizes the use of the game's mechanics.
When I first started writing the script for the map, with great ambitions, I started implementing my own structures and inventing patterns, essentially incorporating the main principles of OOP into my code.
However, since the map is not an RPG and various mechanics are not very deeply developed, I realized that I spend 2-3 days (as you know, there isn't always time to tinker with Heroes) creating some interesting functionality, considering 1) all the rules of clean code, 2) all the textbook postulates, 3) my creativity, and 4) the main concept of OOP, and I do everything beautifully. Then this functionality is used in the form of 30-40 lines of code, and then it just sits there as a dead file.
I estimated the time it would take to write the script in this way, and considering that a very large part of the map development is extremely tedious (at least, I find it difficult to come to terms with the very limited functionality of the scripting library), I decided to write everything using adequate, but still somewhat hacky methods. Like playing around with global variables back and forth, and so on. Besides, refactoring my Heroes code is difficult, hence some of the functionality lies as dead weight because there is no time to redo it (It works like a charm, and it's a pity to delete it!!!).
I don't know why I'm saying all this, I guess it's just been building up. However, I am writing documentation for the script, and I hope that some newbie will be able to copy and paste some cool things from it later.


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

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


                                                                                       
In reply to Jewily
#3709
Auto-translated
Tell me, Hottabych, is the teleportation effect absolutely necessary, or can I avoid using these tables?
Right now, I want to remove this effect.
In my story, a ghost transforms into a living person.
I simply remove the ghost, but I have to teleport the knight model from the dungeon – I would put him in a reserve, but he appears facing away from the player character, which is completely wrong).
As far as I understand, it's impossible to place a model from a reserve at the correct angle, so I have to teleport it, and that's where this effect comes in.
Can't I just remove it?
In reply to Марта
User Avatar
#3710
Auto-translated
Martha
Tell me, Hottabych, is it absolutely necessary to use these tables if I want to remove the teleportation effect?
Right now, I want to remove this effect.
In my story, a ghost transforms into a living person.
I simply remove the ghost, but I have to teleport the knight model from the dungeon, - I would put him in a reserve, but he appears facing away from the player character, which is completely wrong).
As far as I understand, it's impossible to place a model from the reserve at the correct angle, so I have to teleport it, and that's where this effect comes in.
Can't I just remove it?
SetObjectPosition takes an effect as the last argument; one of the values (I don't remember which, from -1 to 4) removes the effect.


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

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


                                                                                       
User Avatar
#3711
Auto-translated

-1 or nil — default
0 — disabled
1 — warp
2 — simple teleport
3 — astral travel
4 — portal to town

Martha, for the SetObjectPosition table, no parameters are needed; just specify 0 or the desired number as the third parameter.

Jewilly, I understand you. In S.T.A.L.K.E.R., I'm reworking all the scripts to be more beautiful, but there (!) everything is used, thank goodness. And the mega-elaborate dialogue and NPC system allows you to create an NPC with just 7 lines of parameters, and a dialogue in a minute.

And the system for NPCs, dialogues, anomalies, and events can be safely used in any future RPG map — it will greatly simplify the work.
Therefore, I hope that after finishing work on this map, you will start a new RPG where you can apply all the created classes to more than just a couple of objects... wink

P.S. Postulates. Bookish, yes.
С уважением, }{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
#3712
Auto-translated
}{0TT@6bI4

That’s why I hope that after finishing this map, you will start a new RPG where you can apply all the created classes to more than just a couple of objects... wink

P.S. Postulates. Bookish ones, yes.
Yes, thank you for the correction; unfortunately, I don’t always remember how certain words are spelled – the nonsense is getting stronger with each generation.
As for the RPG, I don’t know. When I finish the current one (hopefully by mid-summer!), I’ll probably be experiencing nausea from the script editor, so I won’t make any promises.
I want to, but only in an abstract way; whether I’ll actually get to it – I don’t know, I don’t know :)


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

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


                                                                                       
User Avatar
#3713
Auto-translated
Good evening, everyone. If anyone enjoys analyzing other people's maps, could you recommend a map where the AI is well-managed? Regular testing of the functions didn't yield the desired result, and my gut tells me that some specific adjustments are needed. (Using the functions doesn't raise any questions, and I only need advice on how to use them most effectively.) In general, the task is to make the bot stop what it's doing at a certain point and focus on what I need it to do. (I've written the conditions for suspending the priority, but the priority is either too low or too high.) My idea is to give the bot a "path" where its priority will be updated along the way. But it might be a bad idea, so maybe someone knows of a good map where this is applied (in the well-known games, everything is hardcoded, and there's nothing interesting).


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

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


                                                                                       
User Avatar
#3714
Auto-translated

Hello! I would like to create a script that tracks the number of creatures killed. Let's say I define "enemieskilledcounter = 0" in the map script. Will this variable be updated if I increment it in the combat script? I read the introduction to Lua, and it says that if you don't specify "local" for a variable, it will be accessible to all functions. But I'm not sure if this applies to a separate script or not. Or should I use SetGameVar to update the counter in the map script from the combat script?

User Avatar
#3715
Auto-translated
Only through SetGameVar can you transfer data, however. There is a trigger for the end of the battle, which passes the battle index to a function. And using the battle index, you can get all the information about the destroyed creatures using GetSavedCombat.... This is in the tutorial and also on the forum, where Jack of Shadows explained it (searching for GetSavedCombatArmy site:heroesworld.ru should give you results).
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________

Statistics

Welcome our newest member: Emil