Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
There's an issue with the script. Here's the map script (in its entirety):
SetRegionBlocked("Block1", true, 2);
SetRegionBlocked("Block2", true, 2);
SetObjectiveVisible("killall", nil);

function am()
	while 1 do
		local count = 0
		for i=36,43 do
			count = count + (HasArtefact("Muscip", i) or 0)
		end;
		if count < 8 then
			SetObjectiveState("obj", OBJECTIVE_ACTIVE);
		end;
		sleep(5);
	end;
end;

function killallactive()
	SetObjectiveVisible("killall", true);
	startThread (am);
end;

function winF()
	Win();
end;

function obj()
	local old = 0
	while 1 do
		local count = 0
		for i=36,43 do
			count = count + (HasArtefact("Muscip", i) or 0)
		end
		if count == 8 then
			print("Player 1 has all artifacts")
			SetObjectiveState("obj", OBJECTIVE_COMPLETED)
			QuestionBox(GetMapDataPath().."complete-game.txt", "killallactive", "winF");
			break
		end
		if count ~= old then
			print("Player 1 has "..count.."/8 artifacts")
			SetObjectiveProgress("obj", count)
			old = count
		end
		sleep(5)
	end
end

startThread (obj);
For testing, I removed one of the artifacts from a hero and gave it to another hero. The objective reset to 0, and the console displayed an error: (Script) ERROR: Objective "obj" is active, so can only complete or fail it What does this mean?
502 Bad Gateway
__________________________________
nginx/0.8.54
In reply to Warrior777
User Avatar
Auto-translated
Okay, here's the deal. `GetPlayerState` returns:
1 - the player is participating
2 - the player won
3 - the player lost
4 - the player wasn't present initially.
The manual is full of mistakes.
Whether to use constants or not is up to you.
Regarding the unclear expression: everything is on the Lua language developer's website, lua.org, including operator precedence. I just used the available features, and ten extra parentheses won't make a difference.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
2RedHeavenHero:
Whether to use constants or not is up to you.
Of course. The question was why the numbers are "magical," and I provided a detailed answer. Whether to use constants or not is a personal matter for everyone. Essentially, it's just a matter of legible or illegible handwriting.
Regarding the unclear expression: everything is on the language developer's website, lua.org, including the order of operations. I just used the available features, and ten extra parentheses won't make a difference.
No one will memorize the order of operations, as such implementation details vary in different programming languages. And referring to reference materials to decipher the code is also not very good. Therefore, parentheses are needed for human readability (it's like punctuation in "to execute or not to execute"), if they help understand the order of operations. If parentheses are not used, don't be surprised by such questions.

If you understand what is written in that expression, then please explain what
GetPlayerState(...) == 1 or 0
means? Does it mean that the number is compared with both 0 and 1, and the operation returns true (1) if it is equal to one of them? In this case, what does the status PLAYER_NOT_IN_GAME = 0, which was used in the comparison, have to do with it? In other words, why is zero here?
RedHeavenHero
Here's the deal. GetPlayerState returns:
1 - player is participating
2 - player won
3 - player lost
4 - they weren't there at the beginning.
There are many mistakes in the manual.
But in the file advmap-startup.lua, which is connected to the game, it says:
-- Player states
--
PLAYER_NOT_IN_GAME = 0
PLAYER_ACTIVE = 1
PLAYER_WON = 2
PLAYER_LOST = 3
And there is no 4. So, was the number 4 obtained manually? And, after all, what is better to use, comparing the status with 1 (0?) or with 4? Or does it not matter?
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
In reply to Nargott
User Avatar
Auto-translated
GetPlayerState(i) == 1 or 0
If the function returns 1 (player is alive), then "==" will return 1, and this 1 will be added to n; otherwise, it will return nil. But nil cannot be added, and the "or" operation replaces it with 0.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
GetPlayerState(i) == 1 or 0
If the function returns one (the player is alive), then "==" will return 1, and this 1 will be added to n; otherwise, it will return nil. But nil cannot be added, and the "or" operation replaces it with 0.
I understand, so this is a drawback of the construction.
n = n + (isCondition or 0)

Therefore, I advise using a more readable alternative instead (instead of trying to add numbers with logic):
if (isCondition) then
n = n + 1
end

And it will not cause any questions.
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
User Avatar
Auto-translated
hey guys, help me out:smile41:
502 Bad Gateway
__________________________________
nginx/0.8.54
In reply to Warrior777
User Avatar
function am()
local old = 8
while 1 do
local count = 0
for i=36,43 do
count = count + (HasArtefact("Muscip", i) or 0)
end
if count ~= old then
if old == 8 then
SetObjectiveState("obj", OBJECTIVE_ACTIVE)
end
if count == 8 then
SetObjectiveState("obj", OBJECTIVE_COMPLETED)
else
SetObjectiveProgress('obj', count)
end
old = count
end
sleep(5)
end
end
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
RedHeavenHero, is this definitely the correct script? It should only execute SetObjectiveState("obj", OBJECTIVE_ACTIVE) if the number of required artifacts drops below 8.
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
Auto-translated
I'll repeat the error message:
(Script) ERROR: Objective "obj" is active, so can only complete or fail it
I don't think it's related to the `am` function, especially considering the location where you made the change.
The original version from Nival:
function am()
while 1 do
local heroes = GetPlayerHeroes(PLAYER_1);
local count = 0
h = "Maahir";
if HasArtefact(h, ARTIFACT_RING_OF_MAGI) then
count = count + 1;
end;
if HasArtefact(h, ARTIFACT_CROWN_OF_MAGI) then
count = count + 1;
end;
if HasArtefact(h, ARTIFACT_ROBE_OF_MAGI) then
count = count + 1;
end;
if HasArtefact(h, ARTIFACT_STAFF_OF_MAGI) then
count = count + 1;
end;
if count < 4 then
SetObjectiveState("obj1", OBJECTIVE_ACTIVE);
startThread (objective_1);
end;
sleep(3);
end;
end;
502 Bad Gateway
__________________________________
nginx/0.8.54
In reply to Warrior777
User Avatar
Auto-translated
This is related to this specific location, and the developers also encounter the same error at this location. ;) Do I need to explain?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
I understand everything. So, is it impossible to update a task if the art assets are lost?
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
Auto-translated
What about this? ```html
function am()
	local old = 0
	while 1 do
		local count = 0
		for i=36,43 do
			count = count + (HasArtefact("Muscip", i) or 0)
		end;
		if count ~= old then
			if old < 8 then
				SetObjectiveState("obj", OBJECTIVE_ACTIVE);
				startThread(obj);
			end;
			old = count
		end;
		sleep(5);
	end;
end;
502 Bad Gateway
__________________________________
nginx/0.8.54
In reply to Warrior777
User Avatar
Auto-translated
Warrior777
What about this?
function am()
	local old = 0
	while 1 do
		local count = 0
		for i=36,43 do
			count = count + (HasArtefact("Muscip", i) or 0)
		end;
		if count ~= old then
			if old < 8 then
				SetObjectiveState("obj", OBJECTIVE_ACTIVE);
				startThread(obj);
			end;
			old = count
		end;
		sleep(5);
	end;
end;
It uses a loop within a loop, and another loop.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

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

Statistics

Welcome our newest member: Emil