Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
13 years ago
Auto-translated
Well, I worded it a bit incorrectly. I meant all buildings, i.e., level 1 buildings in general. Although, to be honest, the aforementioned function would still be useful, and I would have to ask about it separately. So, everything is fine =)

Whatever
In reply to Heroist
User Avatar
13 years ago
Auto-translated
How can I use a script to move an object to a specific Z coordinate?
Мои карты:
Town
Готовится:Чума (40%), Сосиска(42%), Война Грааля
User Avatar
13 years ago
Auto-translated
I've been wondering for a while:
-How will the AI behave if it encounters an object/trigger with message/question boxes and answer choices, for example, after which a battle will begin? I always do a check for the current player in this case, but is there another way...?

Whatever
In reply to Heroist
User Avatar
13 years ago
Auto-translated
No matter what message box appears, it will still be displayed to the human player. The battle will then start as usual.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
13 years ago
Auto-translated
So, will all these boxes be addressed to a single player? And if there are multiple players, will each of them receive one? Hmm... that's disappointing. I thought we could avoid the need for verification...

Whatever
User Avatar
13 years ago
Auto-translated
Is it possible to remove elements from an array while simultaneously reducing the array's length by the number of elements removed?
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
13 years ago
Auto-translated
It can be done like this:
function cut(array, index)
local ar
for i, e in array do
if i ~= index then
ar= e
end
end
return ar
end
For example, the operation mass=cut(mass, 0) will remove the element with index 0, and the length function for this array will return a number that is 1 less.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
13 years ago
Auto-translated
RedHeavenHero
You can do it like this:
function cut(array, index)
local ar
for i, e in array do
if i ~= index then
ar= e
end
end
return ar
end

But this isn't quite right: the element isn't removed from the original array.
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
13 years ago
Auto-translated
Here's a function that will work: ```lua function cut(array, index) local ar = {} for i, e in array do if i ~= index then ar[i] = e end end return ar end ``` mass=cut(mass, 0)
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
13 years ago
Auto-translated
RedHeavenHero
Would something like this work?
function cut(array, index)
	local ar = {}
	for i, e in array do
		if i ~= index then
			ar[i] = e
		end
	end
	return ar
end
So, there isn't a standard function for this? Iterating through an array is already a resource-intensive operation. And what if you need to add an element to the array later? Would you have to manually write the shift? )))
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
13 years ago
Auto-translated
There isn't a standard one.
length is also not standard.
function length(array)
	local count = 0
	for index, element in array do
		count = count + 1
	end
	return count
end
It is defined this way in common.lua.
What if you add an array element later? Will you have to manually write the shift? )))
Why?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
13 years ago
Auto-translated
RedHeavenHero

Why?
Something like this:
function add(array, index, change)
local ar = {}
local f = 0;
for i, e in array do
if i == index then
ar= change;
f = 1;
end
if f == 1 then
ar[i+1]= e;
else
ar= e;
end;
end
return ar
end


Added 4 minutes later
RedHeavenHero
There isn't a standard one.
That's a shame :( You can write anything by hand, but it's not the same...
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
13 years ago
Auto-translated
Dyrman
Something like this:
function add(array, index, change)
local ar = {}
local f = 0;
for i, e in array do
if i == index then
ar= change;
f = 1;
end
if f == 1 then
ar[i+1]= e;
else
ar= e;
end;
end
return ar
end
In other words, is an array needed where all indices are integers, differing from each other by 1, and where it would be possible to insert new elements between others and delete old ones with a shift?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
13 years ago
Auto-translated
RedHeavenHero
So, you need an array where all indices are integers, differing from each other by 1, and it should be possible to insert new elements between others and delete old ones with shifting?
Correct. But it's not that difficult to write yourself, but it would be great if there was a way to use a match table or some library... :rolleyes:

Added 5 minutes later
And can the index be a string?
Like this:
array = {"Chupa" = 0, "Lapa" = 2,"Nuba" = 0, "Roma" = 2}
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
13 years ago
Auto-translated
Dyrman
That's right. But it's not difficult to write it yourself, but it would be great to have the ability to use a match table or some kind of library... :rolleyes:

Added 5 minutes later
Can the index be assigned as a string?
Yes, but it is highly undesirable to mix strings with numbers, and to put values with indices "0" and 0 into the same array. A string index can be assigned in two ways:
array["string"] = element
array.string = element
but in the second case, string must conform to the standards of ordinary variable names.

array = {["Chupa"] = 0, ["Lapa"] = 2, ["Nuba"] = 0, ["Roma"] = 2}
or
array = {Chupa = 0, Lapa = 2, Nuba = 0, Roma = 2}
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4

Statistics

Welcome our newest member: recijeb