Battle Event in Cities
Posted: Thu Jul 25, 2019 10:41 pm
Hello everyone. Can anyone help me with creating a battle event related to a city? I want to create an event by mentioning that a particular city was first attacked by some enemy unit. Suppose, for example, that at the beginning of the war the city of Metz, in Germany, is attacked by the French.
I wrote the following code in the game_events.lua file:
--Metz Battle
function MetzBattle(attacker, defender)
if GetEvent("MetzBattle") == 0 then
if (attacker.prototype.name == "infantry" or attacker.prototype.name == "cavalry" or attacker.prototype.name == "garrison" or attacker.prototype.name == "armour") and
defender.hex.x == 89 and defender.hex.y == 29 then
SetEvent("MetzBattle", game.turn)
end
end
end
I also included this event in function TriggerCombatEvents(attacker, defender, hex)
But it did not work. The game crashed.
Where would I be going wrong?
Obs: I'm not a expert in .lua files, and I use version 1.5.1 of this game.
And sorry for my english.
Thanks!
I wrote the following code in the game_events.lua file:
--Metz Battle
function MetzBattle(attacker, defender)
if GetEvent("MetzBattle") == 0 then
if (attacker.prototype.name == "infantry" or attacker.prototype.name == "cavalry" or attacker.prototype.name == "garrison" or attacker.prototype.name == "armour") and
defender.hex.x == 89 and defender.hex.y == 29 then
SetEvent("MetzBattle", game.turn)
end
end
end
I also included this event in function TriggerCombatEvents(attacker, defender, hex)
But it did not work. The game crashed.
Where would I be going wrong?
Obs: I'm not a expert in .lua files, and I use version 1.5.1 of this game.
And sorry for my english.
Thanks!