Page 1 of 1

Why this mod of french african army event don't works?

Posted: Sat Jul 28, 2018 2:59 pm
by Kossatx
Hi people, I've mod a little this event, but it don't works and I don't know why :| The idea is to eliminate three garrison units, replace them with small garrisons, and then deploy an infantry unit in hex 76, 55. But when is played (by human or CPU), the three garrisons remain and are not eliminated and replaced by smallgarrisons. The infantry unit is deployed, but in hex 78, 55!!!! Why?

Code: Select all

function FrenchArmyOfAfrica()
  local france = game:GetFactionById(0)
  local germany = game:GetFactionById(2)
  if GetEvent("FrenchArmyOfAfrica") == 0 then
    if game.date.year == 1914 and math.random(0,4) <= game.turn and game.turn <= 3 then 
      if player.alliance.id == 1 or game.type == Game.TYPE_SINGLE then
		local hex = GetHex(54, 62)
		hex.unit:Kill()	
		local hex = GetHex(77, 55)
		hex.unit:Kill()	
		local hex = GetHex(89, 54)
		hex.unit:Kill()	
		SpawnUnit(21, france, 54, 62, 0, 100)
		SpawnUnit(21, france, 77, 55, 0, 100)
		SpawnUnit(21, france, 89, 54, 0, 100)
		SpawnUnit(1, france, 76, 55, 0, 100)
		elseif player.alliance.id == 2 then
		local hex = GetHex(54, 62)
		hex.unit:Kill()	
		local hex = GetHex(77, 55)
		hex.unit:Kill()	
		local hex = GetHex(89, 54)
		hex.unit:Kill()			
		SpawnUnit(21, france, 54, 62, 0, 100)
		SpawnUnit(21, france, 77, 55, 0, 100)
		SpawnUnit(21, france, 89, 54, 0, 100)
		SpawnUnit(1, france, 76, 55, 0, 100)		
		end
      SetEvent("FrenchArmyOfAfrica", game.turn, hex)

Re: Why this mod of french african army event don't works?

Posted: Wed Aug 01, 2018 9:08 am
by Robotron
I assume that's caused by the possibility of the event getting triggered on turn 0 which is a bad idea because it might conflict with the setup file.
Also I don't know what else you have changed in your mod, so alas after a certain point you are on your own since subtle changes elsewhere in the scripts can act up in bizarre ways with no obvious relation.

Try this:

if game.date.year == 1914 and math.random(0,4) <= game.turn and game.turn >= 1 then


Also note you should avoid spawning Entente land units in sea/port hexes as the game might crash with no error report.

That's all I can think about now, got a little bit rusty about the finer points of modding the game.

Re: Why this mod of french african army event don't works?

Posted: Wed Aug 01, 2018 11:53 am
by Kossatx
Robotron wrote: Wed Aug 01, 2018 9:08 am I assume that's caused by the possibility of the event getting triggered on turn 0 which is a bad idea because it might conflict with the setup file.
Also I don't know what else you have changed in your mod, so alas after a certain point you are on your own since subtle changes elsewhere in the scripts can act up in bizarre ways with no obvious relation.

Try this:

if game.date.year == 1914 and math.random(0,4) <= game.turn and game.turn >= 1 then


Also note you should avoid spawning Entente land units in sea/port hexes as the game might crash with no error report.

That's all I can think about now, got a little bit rusty about the finer points of modding the game.
I've tried to do what you say, but it still don't work. Thanks again anyway :)