Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
13 years ago
Auto-translated
Thank you, RedHeavenHero :) Everything is exactly as I wanted it to be :)
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
13 years ago
Auto-translated
It is practically impossible to track when a hero interacts with a garrison.
Hmm, I think that in the case of a garrison, you just need to track the hero's coordinates, because interaction with a friendly garrison occurs when the hero stands inside it. And interaction with an enemy garrison occurs at a different point, yes, but you cannot exchange troops with an enemy garrison. However, Dyrman was working on something similar in relation to a city, but it didn't lead to anything useful because the interactive point jumps relative to the point at which the city's coordinates are defined, and this is due to the rotation. But perhaps everything is fine with the garrison.
 

К А
Стикеры GBF в Telegram
User Avatar
13 years ago
Auto-translated
I'm not sure, but I found these examples of how it can be used:
Okay, I figured this one out. It takes names like BUILDING_ABANDONED_MINE, TOWN_NECROMANCY, and CREATURE_GENIE as arguments. They need to be enclosed in quotes; otherwise, the command won't work.

The function returns an array filled with adventure map references: a name if the object has one, otherwise its generic name, like "1-210-199-AdvMapDwelling-27624." You can refer to this by using the array index. For instance:

Imp_Cruc_Array=GetObjectNamesByType("BUILDING_IMP_CRUCIBLE");
GetObjectNamesByType('TOWN') - all towns on the map
GetObjectNamesByType('TOWN_DUNGEON') - all dungeon towns
GetObjectNamesByType('BUILDING_WITCH_HUT') - all witch huts.

It seems to search by a string prefix, because

GetObjectNamesByType('BUILDING_WITCH') and GetObjectNamesByType('BUILDING_WIT') give the same results as
GetObjectNamesByType('BUILDING_WITCH_HUT').
Is it really impossible to do this with such a wide variety of objects? Or could we try to output all static objects and then select those that return something meaningful with GetObjectCreatures?
 

К А
Стикеры GBF в Telegram
In reply to RedHeavenHero
User Avatar
13 years ago
Auto-translated
RedHeavenHero

GetObjectNamesByType('TOWN') will return an array with the names of all towns on the map.
It won't return that. This function only works with the hero parameter. At least, that's what the manual says, and it doesn't work for me either.
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
In reply to Nargott
User Avatar
13 years ago
Auto-translated
Manual
GetObjectNamesByType
GetObjectNamesByType — Retrieves all objects of a specified type
Syntax
GetObjectNamesByType(objectTypeName);
Description
Retrieves all objects of a specified type. For buildings, you need to specify the type (objectTypeName),
which is defined in Shared-Type. For monsters, it's Creature. For heroes, it's HeroClass. For
towns, it's TownRace. You can use substrings to specify more general types.
For example: BUILDING — all buildings. ABANDONED_MINE or BUILDING_ABANDONED_MINE — for
abandoned mines. DWELLING — for all dwellings. DWELLING_<dwelling type> —
specific dwellings. CREATURE — all monsters. CREATURE_PEASANT or simply PEASANT
— peasants. HERO — all heroes. HERO_CLASS_WIZARD — all heroes of the Academy. TOWN — all
towns. TOWN_HEAVEN — all towns of the HEAVEN race.
Where does it mention heroes here? If it's not a secret, it would be better to post the script. The error might have been elsewhere.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
13 years ago
Auto-translated
RedHeavenHero
Where does it mention heroes here? If it's not a secret, it would be better to post the script. The error might have been somewhere else.
Thank you for the hint; the error turned out to be an extra letter 's' in the variable name. The function works as it should (another manual misled me). Although it displays city names not as names in the human sense.

P.S. Sometimes it's important to simply know that it actually works, in the world of Nival's buggy functions.))

Added after 6 hours 38 minutes
How to calculate the total number of players on the map in a script?
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
User Avatar
13 years ago
Auto-translated
When I was answering you, I didn't find such a function. If it really doesn't exist, I'll have to use an indirect method: check the affiliation of all towns and heroes.
 

К А
Стикеры GBF в Telegram
In reply to Ment
User Avatar
13 years ago
А как же GetPlayerState?
function GetPlayers()
local n = 0
for i=1,8 do
n = n + (GetPlayerState(i) == 1 or 0)
end
return n
end
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
13 years ago
Auto-translated
RedHeavenHero
And what about GetPlayerState?
function GetPlayers()
local n = 0
for i=1,8 do
n = n + (GetPlayerState(i) == 1 or 0)
end
return n
end
Yeah, I already used it to solve the problem.
But instead of the "magic" numbers 1 and 0, I used the constant PLAYER_ACTIVE (which, apparently, corresponds to 1).
-- Getting the number of players in the game
function getTotalPlayers()
local total = 0
for playerID = PLAYER_1, PLAYER_8 do
if GetPlayerState(playerID) == PLAYER_ACTIVE then
total = total + 1
end
end
return total
end

And why use the value PLAYER_NOT_IN_GAME (0)?
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
In reply to Nargott
User Avatar
13 years ago
Auto-translated
Nargott
Yeah, I already managed to solve the problem using it.
Only instead of the "magic" numbers 1 and 0, I used the constant PLAYER_ACTIVE (which, apparently, corresponds to 1).
-- Getting the number of players in the game
function getTotalPlayers()
local total = 0
for playerID = PLAYER_1, PLAYER_8 do
if GetPlayerState(playerID) == PLAYER_ACTIVE then
total = total + 1
end
end
return total
end
Why "magic"?
And why use the value PLAYER_NOT_IN_GAME (0)?
Where? Besides, players who are not in the game are designated as 4.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
13 years ago
Auto-translated
RedHeavenHero
Why "magical"?
Because in the world of programming, using some vague ("magical") numbers is bad practice, making it difficult to read, understand, and modify the code. What is 0? What is 1? Nobody knows, and it's not clear from the context. It's a different story when using named constants, pre-compiled in a separate location (in this case, the developers have already provided such constants), where they can be centrally changed if necessary.

An exception might be, for example, counters, such as total = total + 1, where one represents the minimum step. In this case, its role is obvious to everyone, and therefore it is not considered "magical" in this context.
RedHeavenHero
Where? Besides, players outside the game are indicated by 4.
Judging by the manual:
PLAYER_NOT_IN_GAME -- Player is not in the game
PLAYER_ACTIVE -- Player is active
PLAYER_WON -- Player won
PLAYER_LOST -- Player lost
Usually, in such lists of constants, the values range from 0 and above, i.e., the value 4, apparently, does not correspond to any of the constants and, probably, indicates players outside the game (again, due to "magical" numbers, one can only make assumptions). But I haven't checked it in practice.

The number 0 is taken from here:
n = n + (GetPlayerState(i) == 1 or 0)
I completely don't understand what it does here, and due to the lack of parentheses, it is not even clear how this construct will be executed, whether the equality check will be performed first, and then OR, or vice versa.
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
User Avatar
13 years ago
Auto-translated
I also wanted to ask about this half an hour ago: isn't "player out of the game" and "player lost" the same thing? If there are 5 players on the map, then player 6 cannot (should not) exist by default; if you check for their presence using the number 4. On the other hand, in the same situation, the losing player 5 may very well "appear" when you try to check for them using 0 - i.e., they are now "not in the game." This is also interesting.

Whatever
User Avatar
13 years ago
Auto-translated
Apparently, a separate constant PLAYER_NOT_EXIST = 4 should be created, and we should work with it. It is unclear how the constant PLAYER_NOT_IN_GAME works, because it should indicate that the player is not in the game; however, when generating a map for 2 players, checking the statuses of PLAYER_3..8 for equality with this constant does not pass.
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат

Statistics

Welcome our newest member: recijeb