If you don't know what it is, Lua is a scripting language used by a few games and mods, to include additional moddability and flexibility to them. I have coded in Lua for quite a while, with Garry's Mod for HL2. I was just thrilled to see it being used in BFME2 aswell, it opens up so much possibilities.
From what I can gather, every unit can have a set of "events" attached to them, which are called when the unit meets the conditions for that event. Here are a few examples, taken directly from the game (data.big/scriptevents.xml)
<InternalEvent Name="OnDamaged" /> <!-- OnDamaged(self, other) other is attacking object, may be nil --> <InternalEvent Name="OnDestroyed" /> <!-- OnDestroyed(self) No parameters. Note that self is dead, but name and team are still valid. --> <InternalEvent Name="OnArrived" /> <!-- OnArrived(self) Arrived at the end of a waypoint path. No parameters. --> <InternalEvent Name="OnUnitEntered" /> <!-- OnUnitEntered(self, areaName) Unit entered an area. Name of area is parameter. --> <!-- disabled since its really slow and nobody is using it... [mh, 5/7/2004]--><InternalEvent Name="OnTeamEntered" /> <!-- OnTeamEntered(self, areaName) Sent to the last unit of a team entering an area. --> <InternalEvent Name="OnUnitExited" /> <!-- OnUnitExited(self, areaName) Unit left an area. Name of area is parameter. --> <!-- disabled since its really slow and nobody is using it... [mh, 5/7/2004] --><InternalEvent Name="OnTeamExited" /> <!-- OnTeamExited(self, areaName) Sent to the last unit of a team leaving an area. --> <InternalEvent Name="OnTeamDestroyed" /> <!-- OnTeamDestroyed(self) Sent to the last unit of a team as it is destroyed. --> <InternalEvent Name="BeScary" /> <!-- Broadcast to a unit when he uses a power that makes him radiate scariness.. --> <InternalEvent Name="OnAflame" /> <!-- OnAflame(self) Broadcast to allies that I am on fire :) --> <InternalEvent Name="OnQuenched" /> <!-- OnQuenched(self) Broadcast to allies that I am no longer on fire :) --> <InternalEvent Name="OnCreated" /> <!-- OnCreated(self) sent when an object has been constructed --> <InternalEvent Name="OnBuildingComplete" /> <!--OnBuildingComplete sent when an object has completed building. IE construction complete--> <InternalEvent Name="DamageIncoming" /> <!-- DamageIncoming(self, other, delay, amount) other is shooter, delay is when the damage should hit, amount is how much. So we can do a defense, or a "Oh heck" animation --> <InternalEvent Name="OnSlaughtered" /> <!-- OnSlaughtered(self, slaughterer). --> <InternalEvent Name="OnGenericEvent" /> <!-- self, string --> <InternalEvent Name="OnBuildVariation" /> <!-- self, real -->
These events can be linked to functions, which can in turn modify, influence, and undo actions which are happening. For instance,
function OnCaptureFlagGenericEvent(self,data) local str = ObjectCapturingObjectPlayerSide(self) if str == nil then str = ObjectPlayerSide(self) end ObjectHideSubObjectPermanently( self, "FLAG_ISENGARD", true) ObjectHideSubObjectPermanently( self, "FLAG_MORDOR", true) ObjectHideSubObjectPermanently( self, "FLAG_WILD", true) ObjectHideSubObjectPermanently( self, "FLAG_MEN", true) ObjectHideSubObjectPermanently( self, "FLAG_ELVES", true) ObjectHideSubObjectPermanently( self, "FLAG_DWARVES", true) if str == "Isengard" then ObjectHideSubObjectPermanently( self, "FLAG_ISENGARD", false) elseif str == "Mordor" then ObjectHideSubObjectPermanently( self, "FLAG_MORDOR", false) elseif str == "Men" then ObjectHideSubObjectPermanently( self, "FLAG_MEN", false) elseif str == "Dwarves" then ObjectHideSubObjectPermanently( self, "FLAG_DWARVES", false) elseif str == "Elves" then ObjectHideSubObjectPermanently( self, "FLAG_ELVES", false) elseif str == "Wild" then ObjectHideSubObjectPermanently( self, "FLAG_WILD", false) else ObjectHideSubObjectPermanently( self, "FLAG_NEUTRAL", false) end end
I haven't really digged into the actual "code" part of this yet, but I have found this, which connects a unit to a set of InternalEvents as described above:
Behavior = AIUpdateInterface ModuleTag_03 AILuaEventsList = GondorArcherFunctions End
I still can't believe it, this will make coding / modding BFME2 sooooo much better
:easucks: <- This is now proven untrue! EA RULES!