Connection ErrorBad RequestSession ExpiredSign in requiredForbiddenNot FoundToo Many RequestsServer ErrorBad GatewayService UnavailableGateway TimeoutHTTP Version Not Supported
Session Expired
Your session has expired. Please log in to continue.
Sign in required
You need an account to do that. Sign in or create one — it only takes a minute.
Request Failed
We encountered an issue while processing your request.
Please check your internet connection and try again.
SetHeroCombatScript(heroname, script) heroname - the script name of the hero, script - an xdb file specifying the lua file. All that remains is to loop it with a condition or place it on a PLAYER_ADD_HERO_TRIGGER.
Ment
13 years ago
Auto-translated
What about linking a battle script to a hero? The thing is, I would like to be able to hire such a hero, say, in a tavern, but in this case, he appears on the map without the linked script and loses his functions.
You can write your function in a general combat script (as a mod), with a check for the hero's name. I think that would work. --- Ah, well, the RedHaven option is probably easier.
What about linking a battle script to a hero? The thing is, I would like to be able to hire such a hero, say, in a tavern, but in this case, he appears on the map without the linked script and loses his functions. Is there a function that, if such a hero appears on the map, automatically links the battle script to him? Or is there another way?
SetHeroCombatScript(heroname, script)
is not the best option. The script will only work if the hero is under AI control, and it will also be reset if the hero is lost.
I already described it in the neighboring topic:
it is done by adding a few lines of script to the 'combat-common.lua' file - this file is launched by the game when any battle starts.
If needed, I can explain it in more detail. But as always, the best option is to study other people's maps that use battle scripts.
Yes, it will be reset, but this can be fixed using a loop or a trigger, and the function works normally with the player's hero as well.
Is there an error in the manual, or is Google translating incorrectly?
This function allows you to specify which scenario will be executed when fighting this hero. The script only works if the hero is under the control of the AI players, and no other scenarios are set in the location where the battle takes place (town, garrison, etc.). The scenario is automatically reset when the player loses this hero in some way.
The manual contains a lot of information, but not all of it is true. Although, perhaps the patches fixed this issue, while the manual remained as it was.
Heroist
13 years ago
Auto-translated
Thanks for the answers, and I found a very interesting old map called "Refugee" and played it a bit =) ---
a) SetHeroCombatScript(heroname, script) – does this mean it applies a combat trigger to your hero for the rest of their life? Because I have a hero with a combat trigger as the main one, so even if he dies, it will still be loooooose, so if I apply it once at the beginning of the game, that's what I need. b) Regarding 'combat-common.lua', I still couldn't find any explanations in that thread. What exactly is considered "a few lines"? I would like more details, if possible.
SetHeroCombatScript attaches a script to a hero for as long as they are on the map.
Heroist
13 years ago
Auto-translated
SetHeroCombatScript('Alaric', CombatScript.lua) --- doesn't work. It gives an error: value was nil.
In the manual, it says to write .lua, but I tried .xdb as well, and it still doesn't work.
Therefore, the file path should be enclosed in quotes and include a forward slash.
'/CombatScript.xdb#xpointer(/Script)'
Heroist
13 years ago
Auto-translated
SetHeroCombatScript('Alaric', 'CombatScript.lua') --- the script doesn't exist, or something like that. The same applies to the .xdb extension. Maybe you need to specify a longer path?
Regarding 'combat-common.lua', I couldn't find any explanations in that thread. What exactly is considered "a few lines"? I would like more details, if possible.
1. In the main file 'MapScript.lua', we define the strings. (let's introduce the variable 'vasya')
2. Create a new lua file in the map archive in the 'scripts' folder. Let it be 'battle.lua' 3. Copy the 'combat-common.lua' file into the map archive and add a few lines.
sleep(1);
vasya = GetGameVar("vasya");
if GetHeroName(GetAttackerHero()) == vasya then
doFile("/scripts/battle.lua");
print("Vasya has entered the battle!");
else if GetHeroName(GetDefenderHero()) == vasya then
doFile("/scripts/battle.lua");
print("Vasya has entered the battle!");
end;
end;
4. Open the created file 'battle.lua' and write the following:
vasya = GetGameVar("vasya");
if GetHeroName(GetAttackerHero()) == vasya then
human = ATTACKER;
comp = DEFENDER;
human_hero = GetAttackerHero();
print("player - attacker");
else human = DEFENDER;
comp = ATTACKER;
human_hero = GetDefenderHero();
print("player - defender");
end;
The variables 'human', 'comp', 'human_hero', 'comp_hero' are introduced for convenience - they will be needed in almost all functions of the combat script, regardless of whether the player is attacking or defending. Also, for convenience, print statements are used to output information to the console. All that remains is to add additional conditions and their consequences in the Prepare() or Start() functions - this is where the map author's creativity comes into play :)
Ps: From point 3, it is clear that the combat script will not run if the hero 'vasya' is not involved in it.
Pss: This approach is more versatile than SetHeroCombatScript, in which the loss of a hero can also be considered as him fleeing the battlefield and then being ransomed in the tavern.