Skip to content
#907
Auto-translated
Heroist

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')
vasya = "Scripted hero name";
SetGameVar("vasya", 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.

Statistics

Welcome our newest member: artem

Users Online 2 users 1554 guests