Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
Set/GetGameVar saves data on a too global scale; it can be used to transfer data between adventure and battle modes, as well as between maps. Within a single map, everything is much simpler:
function foo()
  local var1 = 1; -- var1 is local and only visible within this function
  var2 = 2; -- var2 is global and can be used anywhere
end
It is, of course, better to declare all variables within functions as local, and declare global variables outside, say at the beginning of the file:
hero_level = 1;

function foo()
  hero_level = GetHeroLevel('hero');
end

function bar()
  local some_variable = hero_level;
end
User Avatar
Auto-translated
I don't quite understand what's happening in the second example.
hero_level = 1; -- does this assign a value to the variable?

function foo()
hero_level = GetHeroLevel('hero'); -- does the variable equal the hero's level within the function?
end

function bar()
local some_variable = hero_level; -- is a local variable for the function equal to the global variable? (1?)
end
Всё, что сейчас происходит во мне, тоже является частью Вселенной. (с) Иванов Александр.
Цикл кампаний "Дыхание Смерти" из трёшки в четвёртом исполнении
Учебная карта
Астралия
За Королеву!
Подземелья и Дьяволы
Отголоски войны
Освобождение
User Avatar
Auto-translated
-- initialize a variable with some default state.
-- Not required, but very useful, as if we accidentally access it before
-- creating it, the script will crash. Initialization at the beginning of the file
-- guarantees that the variable will always exist.
hero_level = 1; -- assign a value to the variable?

-- when the need arose to remember the current hero's level,
-- we call this function, and the global variable remembers its value
-- until it is reassigned again.
function foo()
hero_level = GetHeroLevel('hero'); -- in the function, the variable is equal to the hero's level?
end

-- at any subsequent moment from any other function, we can use this value.
-- let's say a more meaningful example - give the hero as many peasants as he has level:
function bar()
AddHeroCreatures('hero_name', CREATURE_PEASANT, hero_level);
end
User Avatar
Auto-translated
In a multiplayer map, I used the MoveCamera function in a script. For the player who activated the trigger, everything worked perfectly, but when the second player's turn came, the camera moved to the specified point again. Is this how it's supposed to work, or can it be fixed?
и немедленно выпил...
User Avatar
Auto-translated
It would be helpful to have at least an approximate text of the script. Was the trigger after the camera pass reset to zero? Jack_of_shadows Thank you very much. It turned out to be simpler than I thought. It turns out I made a small mistake. I created my script with that variable, and it works.
Всё, что сейчас происходит во мне, тоже является частью Вселенной. (с) Иванов Александр.
Цикл кампаний "Дыхание Смерти" из трёшки в четвёртом исполнении
Учебная карта
Астралия
За Королеву!
Подземелья и Дьяволы
Отголоски войны
Освобождение
User Avatar
Auto-translated
function mummytalk() Trigger(REGION_ENTER_AND_STOP_TRIGGER, 'mummy1', nil) CreateMonster('monster1', CREATURE_MATRIARCH, 1, 55, 77, 0, MONSTER_MOOD_FRIENDLY, MONSTER_COURAGE_ALWAYS_JOIN, 180) sleep(2) CreateMonster('monster2', CREATURE_MATRIARCH, 5, 54, 74, 0, MONSTER_MOOD_WILD, MONSTER_COURAGE_ALWAYS_FIGHT, 180) MoveCamera(55, 77, 0, 40, 0.7, 5, 0, 0); sleep(5) for m = 1, 3 do ShowFlyingSign(dir..'MATRIARCH'..m..'.txt', 'monster1', -1, 3) sleep(5) end end Trigger(REGION_ENTER_AND_STOP_TRIGGER, 'mummy1', 'mummytalk') For the player who triggers this, everything works correctly, but at the start of the next turn, the second player's camera is moved to this point, and the entire list of FlyingSign messages pops up. I think we could try forcibly centering the camera on the player at the beginning of each turn. It's a workaround, of course, but how else can we solve this problem?
и немедленно выпил...
User Avatar
Auto-translated
There seems to be a function called MoveCameraForPlayers. Also, for the flying message, you just need to replace -1 with the player's number.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
It's a workaround, of course, but how else can we bypass this problem?
Before running any scripts, add a check for the player number. It's simple. The player number should match the player who owns the hero that activated the trigger.
There's a function called MoveCameraForPlayers, I think. And for the flying message, you just need to replace -1 with the player number.
Oh, that might even be easier.
 

К А
Стикеры GBF в Telegram
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
There seems to be a function called MoveCameraForPlayers. Also, for the flying message, you just need to replace -1 with the player's number.
Yes, it worked as expected, thanks for the quick response. And MoveCameraForPlayers is like a secret function; I started looking for information about it and found a lot of interesting things about patch 3.1. I recommend it to everyone.
и немедленно выпил...
User Avatar
Auto-translated
I've been racking my brain, and I can't figure out how the QuestionBoxForPlayers function works.
Does it return a value, or is it simply supposed to trigger one of two functions?
Could you explain the principle of its operation in more detail?
и немедленно выпил...
User Avatar
Auto-translated
Medyan, there are concepts like modal and non-modal windows.
Modal - the script will wait on the line where the window is called until the user closes it (this is how MessageBox works).
Non-modal - the script will open the window and continue executing further, forgetting about it (this is how QuestionBox works).
The command to open a non-modal window cannot return anything because the user will press a button on it when it has long since finished executing. Therefore, it uses a different mechanism - the names of functions corresponding to the answer options are passed, and the window itself calls these functions after the user presses one of the buttons.
User Avatar
Auto-translated
Thank you, Jack, for explaining it so clearly. It turned out that the function wasn't working for me not because I misunderstood the principle, but because I made a spelling mistake... it happens. I have a question: can the amount of Dark Energy a Necromancer has be influenced in any way (or at least simply counted)? Also, is it possible to influence the number of creatures available for training for the Knights in any way, perhaps by changing it with scripts?
и немедленно выпил...
User Avatar
Auto-translated
Dark energy can only be tracked using the GetPlayerNecroEnergy(player_number) function.
The number of creatures available for training cannot be directly influenced by scripts. As an alternative, you could create a separate building that, when visited, allows the player to train additional creatures.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
thank you, and another question:
is there a way to determine if a cell on the map has been excavated?
or if a hero excavated at a specific moment?
so far, the only thing that comes to mind is to determine the player's position and monitor the change in action points, and if the position does not change, and the action points are reset, it means that the hero was excavating (and at the same time, it is necessary to monitor whether he summoned creatures from the castle, because in this case, action points are also spent).
и немедленно выпил...
In reply to Medyan
User Avatar
Auto-translated
I have a question. How can I use scripts to play a video after completing a quest?:confused: So, I complete the quest, watch the video, and continue playing. By the way, regarding videos... How can I add my own voiceover? I have the necessary format, but I can't insert it into the dialogue scene. Thank you in advance!

Statistics

Welcome our newest member: Emil