Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Kavalar
User Avatar
Auto-translated
Kavalar
So, something like, if the hero's mana decreases, we check the enemy's stacks?

I had an idea for identifying a spell, for example, to extract its presence in the hero's spellbook before the battle and calculate analytically, taking into account SP and bonuses from schools, how much damage it should deal. Then just compare, and if the amount of mana spent and the damage match, record it. What do you think, could it work?
The only problem, though, is accounting for resistance, and if creatures can still be analyzed, then how to deal with hero bonuses or artifact bonuses is not yet clear.:smile32:
1. Yes, that's right.
2. That's also possible, but: many factors affect the damage from spells, as well as the cost, and each of them must be taken into account in order to adequately assess the type of spell; the damage from a spell is also difficult to calculate due to rounding to the number of creatures killed. There are also factors that cannot be identified in any way: such as the sign of fire, the rune of elemental immunity, antimagic.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
I came up with a similar algorithm, although I've put this task on hold for now, but I'll share my thoughts:

on paper, my structure is roughly like this:
if(combatReadyPerson() == "name of the desired hero")
get data about the enemy creatures using GetCreatures() and GetCreatureNumber()

then you need to find out if the hero's turn is over:
repeat
current_mana = GetUnitManaPoints("name of the desired hero")
until(isCreature(combatReadyPerson()))

next, we check if the number of mana and enemy creatures has changed, and based on this, we conclude whether a spell was cast and what its effect was

I'm not sure how accurate my assumptions are, as I've been focusing on more understandable tasks for myself)
Нет войне.
Auto-translated
local heroes = GetAllNames(0);
for i, hero in heroes do
print(i, hero);
end

When adding lines, the game crashes with an error. What could be the reason?
User Avatar
Auto-translated
landw1rt, it's not entirely clear which lines you're adding where and at what point the game crashes. It's possible that the GetAllNames() function returns a string instead of a table. Also, you can get the heroes of a specific player using the GetPlayerHeroes(PLAYER_NUMBER) function.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
Auto-translated
Jack_of_shadows
landw1rt, it's not entirely clear which lines you're adding where and at what point the game crashes. It's possible that the GetAllNames() function returns a string, not a table. Also, you can get the heroes of a specific player using the GetPlayerHeroes(PLAYER_NUMBER) function.

I'm adding the specified snippet to the script body to check if the region is unoccupied. By iterating, I determined that the game crashes after adding this snippet.

The same thing happens with the length function.
GetAllNames() prints a list of living heroes to the console, but problems start after the for loop.
I only need to count the number of values returned by GetAllNames().
User Avatar
Auto-translated
landw1rt, this version of the operator is designed to iterate through tables, but your function returns a string. Simply use GetPlayerHeroes():

local hero_cnt = 0;
for i = PLAYER_1, PLAYER_8 do
hero_cnt = hero_cnt + length(GetPlayerHeroes(i));
end

I haven't tested the code, so I might be wrong.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
Auto-translated
Jack_of_shadows
landw1rt, this version of the for operator is designed to iterate through tables, but your function returns a string. Simply use GetPlayerHeroes():

local hero_cnt = 0;
for i = PLAYER_1, PLAYER_8 do
hero_cnt = hero_cnt + length(GetPlayerHeroes(i));
end

I haven't checked the code, so I might be wrong.

Thank you!
User Avatar
Auto-translated
I decided to test these combat scripts, and immediately encountered an unclear problem – I create a script, assign it to a hero, but in the game, during combat, it doesn't work. The console shows an error: "attempt to perform arithmetic on a string value." It doesn't matter what's written in the script; even with an empty file, it gives the same error. Can anyone suggest how to fix this?
Нет войне.
User Avatar
Auto-translated
Gerter, just in case, show how you attach the script to a hero; it should be something like this: `
SetHeroCombatScript(HERO_NAME, '/combat_script.xdb#xpointer(/Script)');
`
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
User Avatar
Auto-translated
yes, I'm attaching it now, but the issue was with the file location – I moved it from map_name/Maps/SingleMissions to just map_name/ and it started working.

Added 7 hours ago
How does the combatReadyPerson() function work?

Code:
function Start()
...
currentUnit = combatReadyPerson()
if(IsHero(currentUnit)) then
...

It doesn't work because currentUnit always takes a zero value, although combatReadyPerson() should return a string with the name of the unit at the beginning of the battle.
Нет войне.
User Avatar
Auto-translated
Ideally, combatReadyPerson() should return a string with the unit's name at the beginning of the battle.
There's a suspicion that it won't work in the start() function, since
The combat will only begin after this function finishes its work.
It might be worth trying to call it from various UnitMove() functions.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
User Avatar
Auto-translated
Thank you, yes, the function works in AttackerHeroMove(), for example. Here, the guide by Novik confused me a bit, as it doesn't contain similar information, and functions like UnitMove() have a different signature and only work for AI (but in reality, this is not the case).
Нет войне.
User Avatar
Auto-translated
Hello. I have a question. I want a message to pop up, the fog of war to be revealed in a specific location, and a secondary quest to be added when clicking on the witch's hut. Here's the function... ``` function ActQgoldenArmada () MessageBox("/Maps/SingleMissions/rework (4)/golden.txt"); OpenCircleFog(206,6,0,15,PLAYER_1); sleep(2); MoveCamera(206,6,0,30,1,2,1,1); Trigger(OBJECT_TOUCH_TRIGGER, "Qgolden", nil ); end; Trigger(OBJECT_TOUCH_TRIGGER, "Qgolden", "ActQgoldenArmada" ); ``` It works, but how do I activate the secondary quest? Should it already be created on the map, but hidden, or something else? Also, I need it to be a secondary quest, not a main quest. Is there a different command for that? I think that's all. Thanks in advance for the explanation.
Автор карт:
Долина расхитителей
Выбор мира
In reply to OrnsteinDragonslayer
User Avatar
Auto-translated
OrnsteinDragonslayer
Hello. I have a question. I want a message to pop up when clicking on the witch's hut, the fog of war to be revealed in a specific location, and a secondary quest to be added. Here's the function...

function ActQgoldenArmada()
MessageBox("/Maps/SingleMissions/rework (4)/golden.txt");
OpenCircleFog(206,6,0,15,PLAYER_1);
sleep(2);
MoveCamera(206,6,0,30,1,2,1,1);

Trigger(OBJECT_TOUCH_TRIGGER, "Qgolden", nil );
end;

Trigger(OBJECT_TOUCH_TRIGGER, "Qgolden", "ActQgoldenArmada" );

It works, but how do I activate the secondary quest? It should already be created on the map, but hidden, or something? Also, I need it to be a secondary quest, not a main one. Is there a different command for that? I think that's all. Thank you in advance for your explanations.

SetObjectiveState();
Try to find it in the manual, I don't remember exactly right now.
Кампания в разработке:
Название не придумал
Выполнено 5%

Statistics

Welcome our newest member: Emil