Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Dogenator
User Avatar
Auto-translated
Dogenator

Hello everyone!

I have the following problem:

I installed a script to change day and night, and it works, but...

When the daytime lighting changes to nighttime, the hero menu becomes unavailable, and only for player #1.

What could be the problem?

Here is the code:

curr_light = 'day'

function DayNight()
if curr_light == 'day' then
SetAmbientLight(GROUND, 'NIGHT', 1, 5.0)
curr_light = 'night'
else
SetAmbientLight(GROUND, 'DAY', 1, 5.0)
curr_light = 'day'
end
end

Does this only happen when launching the map through Multiplayer? Is everything normal in single-player? I had a similar bug when calling showFlyingSign(), until the notification appears on the screen for all players, there will be no access to the hero menu, or rather, there will be, but when you click on the hero icon, the menu will open for the last player (I set all players to be controlled by a human and tested). Basically, there are functions that need to be displayed on the screen of each human player to work correctly. PEST fixes this in Multiplayer
Мои карты: Белый Храм, Поменяться местами, Судьба королевства, Стихийные острова.
In reply to Долгий
User Avatar
Auto-translated

Yes, this happens when launching in multiplayer mode, but with the second player controlling the game.

So, do I understand correctly that when night falls for me, it's still daytime for the second player, which causes this desynchronization?

Tomorrow I'll try playing with a friend, see how it works, and let you know.

In reply to Dogenator
User Avatar
Auto-translated

Finally, I was able to test this script online.

You are right, Pest solves this problem, everything works.

Thank you for your help!

In reply to Dogenator
User Avatar
Auto-translated

Hello everyone!

I have the following task: to grant the "Haste" spell through a script when the "Speed Magic" skill is leveled up during an attack. And to remove it if the skill was unlearned from a mentor. This is necessary because I changed the tier of the "Haste" spell from 1 to 3, and when "Speed Magic" is leveled up, the spell becomes unavailable in battle.

I found a couple of functions in the script files that are responsible for this:

HasHeroSkill(heroName, skillID); - checks for the presence of a skill

TeachHeroSpell(heroName, spell); - grants a spell

How to remove a spell - ?

The only thing that worries me is the script name of the hero. If I want this function to work for all heroes, how should I proceed?

 

And a separate question, does the trigger work from the very beginning, or can it be set to work from a certain point?

 

 

User Avatar
Auto-translated
Dogenator, you need to create a separate thread that will iterate through all the player's heroes: ```lua while(1) do local heroes = GetPlayerHeroes(ID_игрока); for i, hero in heroes do if(HasHeroSkill(hero, ID_скилла) and (not KnowHeroSpell(hero, ID_спелла))) then TeachHeroSpell(hero, ID_спелла); end end sleep(50); end ``` But it seems there is no function to remove a spell; maybe it can only be done with a cheat?
Dogenator
Does the touch trigger work from day one, or can you set it to work from a specific day?
You can check what day it is in the touch trigger handler, or you can set the touch trigger to not activate immediately at the start, but in a new day trigger when the desired day arrives. The trigger works from the moment the Trigger() function is executed.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
User Avatar
Auto-translated
If a spell is unavailable for a faction (insufficient level of light magic), then even if it is granted by a script, it will not be cast, unfortunately.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to Jack_of_shadows
User Avatar
Auto-translated

I did as you said, and it worked.

But for some reason, all my other scripts placed in the new day function stopped working. What could be the problem?

This is the function that is triggered by NEW_DAY_TRIGGER.

function new_day_trigger()
haste_p1()
haste_p2()
if (GetDate(ABSOLUTE_DAY) == 2) then
Spawn_army()
end
if (GetDate(ABSOLUTE_DAY) == 3) then
day_3rd()
mentor_off()
Trigger(OBJECT_TOUCH_TRIGGER, 'mentor_1', 'mentor_message_p1');
Trigger(OBJECT_TOUCH_TRIGGER, 'mentor_2', 'mentor_message_p2');
end
end

And this is the function you sent me, which breaks everything above.

function haste_p1()
while(1) do
local heroes = GetPlayerHeroes(PLAYER_1);
for i, hero in heroes do
if(HasHeroSkill(hero, 143) and (not KnowHeroSpell(hero, SPELL_HASTE))) then
TeachHeroSpell(hero, SPELL_HASTE);
end
end
sleep(50);
end
end

Perhaps I placed the haste function incorrectly, and the script processing simply doesn't reach all the other functions?



Added 2 minutes ago

}{0TT@6bI4
If the spell is not available for casting (insufficient level of light magic), then even if it is granted by the script, it will not be cast, unfortunately.

Strangely enough, it works, but the spell is only cast at the expert level of the school of light, even though there is no light in the skill tree.

But it breaks all the other scripts for some reason.

User Avatar
Auto-translated
Constructions like while(1) do ... end are loops. If there is no command to exit the loop within them, it becomes an infinite loop. When you call haste_p1(), the script runs inside this function infinitely. For such tasks, you should use separate threads, using the function startThread(function name). Launch it once, perhaps right at the start of the map, and it will run forever.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
User Avatar
Auto-translated

Jack_of_shadows
Constructions of the type while(1) do ... end are loops. If there is no command to exit the loop within them, it becomes an infinite loop. When you call haste_p1(), the script runs inside this function infinitely. For such things, you need to use separate threads, using the function startThread(function name). Launch it once, you can do it right at the start of the map, and it will run forever.

Thank you, now everything works as it should.

Auto-translated
Hello everyone! Please tell me how to implement a check for the creature's level. The idea is as follows: when an enemy hero dies, the AI re-hires him, and he is given an army of his faction, with the number of creatures and their level corresponding to those in the player's hero's army.
User Avatar
Auto-translated
_BlackKnight_, as far as I know, there isn't a ready-made function for that. As an alternative, you could create a table that maps each player unit to its corresponding AI unit and use that to calculate the values.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
Auto-translated
Jack_of_shadows
_BlackKnight_, as far as I know, there isn't a ready-made function for this. As an alternative, you could create a table that maps a player's creature to a corresponding AI creature and use that to calculate the values.
I don't quite understand how this can be done; I would like to see an implementation with a specific example.
User Avatar
Auto-translated
_BlackKnight_, for example, if a player strictly plays as a Knight, and the AI strictly plays as a Demon, then:
-- table of correspondences, only added a couple of creatures, the rest by analogy
creatures_conversion_table =
{
  {CREATURE_PEASANT, CREATURE_FAMILIAR},
  {CREATURE_MILITIAMAN, CREATURE_IMP},
  {CREATURE_LANDLORD, CREATURE_QUASIT},
};

-- checking function, without the wrapper regarding when to call it
-- the names of the player's and AI's heroes are passed as input.
function CheckCreaturesConversion(hero_player, hero_enemy)
  for i, cr in creatures_conversion_table do
    local cr_num = GetHeroCreatures(hero_player, cr[1]);
    if (cr_num > 0) then
      AddHeroCreatures(hero_enemy, cr[2], cr_num);
    end
  end
end
If the castles are random, then, of course, everything will be a little more complicated. I haven't checked the code; I might have made a mistake somewhere.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
Auto-translated
Jack_of_shadows, the script works, thank you, but I'll have to list all the creatures. Since the map has castles of all factions. Slightly off-topic: I downloaded the latest version of Heroes 5.5, and the scripts refuse to work on it, but everything works fine on the old version. I'm trying to figure out what the problem is.
Auto-translated
Another question. Let's say a hero enters a garrison, places creatures, and a prompt appears offering to transform these creatures into creatures of the corresponding tier and grade. Creatures of tiers 5, 6, and 7 are available for transformation. Creatures can only be obtained from factions whose alignment matches the player's. The alignment is determined by the starting hero. A fee is charged for the transformation, which is calculated based on the cost of the resulting creature. For Necropolis creatures of tier 7, 50% more are required to obtain the same number of creatures from other factions. I would like to see an implementation using creatures from evil factions as an example. Therefore, hypothetical angels could be transformed into devils, cyclops, and the like.

Statistics

Welcome our newest member: Emil