Help with basic Lua

FightingGandhi

Chieftain
Joined
Dec 21, 2013
Messages
8
I'm writing my first lua script and I'm having trouble getting my function to be called, here is my code.

Code:
print("Loading: BarbCaptureCity script");

Events.EndCombatSim.Add(

	function(attackingPlayer, attackingUnit, attackingUnitDamage, attackingUnitFinalDamage, attackingUnitMaxHitPoints, defendingPlayer, defendingUnit, defendingUnitDamage, defendingUnitFinalDamage, defendingUnitMaxHitPoints)
          print("function called");
	end
)

"Loading: BarbCaptureCity" is being printed in firetuner; however, "function called never prints after combat, is there something I am not understanding about this event?

I did set "VFS: true" if that makes any difference, I don't fully understand the VFS so I may be making a mistake here, but I think it's used in this and most situations.

Edit:
I'm still curious what the answer is here and why this function isn't being called. But I have found a function much better for what I'm trying to do SerialEventCitySetDamage.
 
EndCombatSim was crippled in one of the patches pre-G&K (1.674 IIRC), it doesn't fire if one or other of the units is killed in combat - so is pretty much useless now.

You only need VFS=true for lua files that are replacements for core game lua files, see the "File Attributes" link in my sig for which file types need what settings under what conditions.
 
Thanks, another thing I found out about EndCombatSim is it doesn't fire when Quick Combat is enabled which makes it worthless.

I was unsure if I should update this thread or start a new one, but to reduce clutter I'll just post this semi-unrelated question here.

I'm trying to have a few effects when a barbarian player attacks a city. One of these is to allow a barbarian unit to capture a city, and the other is when a barb player attacks a city there is a chance it will spawn a new unit attacking the city. I've already made code that accomplishes both these events but I'm trying to clean it up. Right now I'm using a plot iterator to check if there is a barbarian unit next to a city on the event that a city is damaged (SerialEventCitySetDamage).

Questions:

1. I'd like to know which unit is attacking the city, but these functions don't appear to work: IsOutOfAttacks, IsAttacking, IsFighting, IsInCombat. all of these return a boolean value, and it's always false for the AI during SerialEventCitySetDamage(). I assume the last three may return true during RunCombatSim(), but I don't think that event fires with Quick Combat. IsOutOfAttacks() returns true for ActivePlayer, but not for AI (or at least Barbarian AI, haven't tested for others). I can make an educated guess about which unit attacked based on num of attacks on the city, and what units are damaged next to the city. Is there something I'm missing that would let me know which unit is attacking?

2. Does anyone know anything about the Barbarian leader programming after it captures a city? I haven't done much testing, there is a Leader table for them that includes Leader_Flavors, I've updated these but they don't seem to effect anything. Another thing to note is the file for the Barbarian leader is only in the core game assets folder and not in the expansion folders, if a file is not in an expansion folder is it not used? I think I'm going to have to code the city to do things, but I'm curious if anyone knows anything before I get started.

3. Can I make a promotion that fires a custom lua function when the unit attacks?
 
Back
Top Bottom