Jump to content


Awesome stuff!


4 replies to this topic

#1 Deathstrike

    Brilliant (but modest)

  • Gold Member
  • 928 posts
  • Projects: C&C Shockwave

Posted 23 January 2006 - 20:32

So I was just browsing through the BFME2 code, and I found some references to Lua... My first thought was "OMFG... that can't be true..." But yes it was, EA has implemented the Lua Scripting language into BFME2!!

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=&#34;OnDamaged&#34; /> <!-- OnDamaged&#40;self, other&#41; other is attacking object, may be nil -->
        <InternalEvent Name=&#34;OnDestroyed&#34; /> <!-- OnDestroyed&#40;self&#41; No parameters. Note that self is dead, but name and team are still valid. -->
        <InternalEvent Name=&#34;OnArrived&#34; /> <!-- OnArrived&#40;self&#41; Arrived at the end of a waypoint path.  No parameters. -->
        <InternalEvent Name=&#34;OnUnitEntered&#34; /> <!-- OnUnitEntered&#40;self, areaName&#41; Unit entered an area. Name of area is parameter. -->
        <!-- disabled since its really slow and nobody is using it... &#91;mh, 5/7/2004&#93;--><InternalEvent Name=&#34;OnTeamEntered&#34; /> <!-- OnTeamEntered&#40;self, areaName&#41; Sent to the last unit of a team entering an area. -->
        <InternalEvent Name=&#34;OnUnitExited&#34; /> <!-- OnUnitExited&#40;self, areaName&#41; Unit left an area. Name of area is parameter. -->
        <!-- disabled since its really slow and nobody is using it... &#91;mh, 5/7/2004&#93; --><InternalEvent Name=&#34;OnTeamExited&#34; /> <!-- OnTeamExited&#40;self, areaName&#41; Sent to the last unit of a team leaving an area. -->
        <InternalEvent Name=&#34;OnTeamDestroyed&#34; /> <!-- OnTeamDestroyed&#40;self&#41; Sent to the last unit of a team as it is destroyed. -->
        <InternalEvent Name=&#34;BeScary&#34; /> <!-- Broadcast to a unit when he uses a power that makes him radiate scariness.. -->
  <InternalEvent Name=&#34;OnAflame&#34; /> <!-- OnAflame&#40;self&#41; Broadcast to allies that I am on fire &#58;&#41; -->
  <InternalEvent Name=&#34;OnQuenched&#34; /> <!-- OnQuenched&#40;self&#41; Broadcast to allies that I am no longer on fire &#58;&#41; -->
  <InternalEvent Name=&#34;OnCreated&#34; /> <!-- OnCreated&#40;self&#41; sent when an object has been constructed -->
  <InternalEvent Name=&#34;OnBuildingComplete&#34; /> <!--OnBuildingComplete sent when an object has completed building. IE construction complete-->
  <InternalEvent Name=&#34;DamageIncoming&#34; /> <!-- DamageIncoming&#40;self, other, delay, amount&#41; other is shooter, delay is when the damage should hit, amount is how much.  So we can do a defense, or a &#34;Oh heck&#34; animation -->
        <InternalEvent Name=&#34;OnSlaughtered&#34; /> <!-- OnSlaughtered&#40;self, slaughterer&#41;. -->
        <InternalEvent Name=&#34;OnGenericEvent&#34; /> <!-- self, string -->
        <InternalEvent Name=&#34;OnBuildVariation&#34; /> <!-- 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&#40;self,data&#41;
	local str = ObjectCapturingObjectPlayerSide&#40;self&#41;
	if str == nil then
  str = ObjectPlayerSide&#40;self&#41;
	end


	ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_ISENGARD&#34;, true&#41;
	ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_MORDOR&#34;, true&#41;
	ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_WILD&#34;, true&#41;
	ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_MEN&#34;, true&#41;
	ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_ELVES&#34;, true&#41;
	ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_DWARVES&#34;, true&#41;

	if str == &#34;Isengard&#34; then
  ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_ISENGARD&#34;, false&#41;
	elseif str == &#34;Mordor&#34; then
  ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_MORDOR&#34;, false&#41;
	elseif str == &#34;Men&#34; then
  ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_MEN&#34;, false&#41;
	elseif str == &#34;Dwarves&#34; then
  ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_DWARVES&#34;, false&#41;
	elseif str == &#34;Elves&#34; then
  ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_ELVES&#34;, false&#41;
	elseif str == &#34;Wild&#34; then
  ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_WILD&#34;, false&#41;
	else
  ObjectHideSubObjectPermanently&#40; self, &#34;FLAG_NEUTRAL&#34;, false&#41;
	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!
Posted Image
Like me? Put this in your sig then!
Posted Image

Posted Image <- That's me!

#2 Cryptkeeper

    secret experment 142-2

  • Member
  • 4199 posts
  • Projects: shockwave,rise of the reds

Posted 23 January 2006 - 22:43

interesting i never said ea sucks but they do have there share of problems like any companys just alot of companies problems are covered up by there fan base look at blizzard for example

#3 00agent111

    Visitor

  • Member
  • 49 posts

Posted 23 January 2006 - 22:50

sounds looks complicated.....lmao!

#4 Deathstrike

    Brilliant (but modest)

  • Gold Member
  • 928 posts
  • Projects: C&C Shockwave

Posted 24 January 2006 - 09:57

I did some more dissection of the (little bit of) available code, and these functions will be available (along with speculated effect):

There will be more functions than these few probably, but at least these are confirmed.

ExecuteAction(action, object)
This executes an action, not sure which actions are possible but this one is valid: "NAMED_KILL", which would kill the unit in variable 'object'.

ObjectBroadcastEventToAllies(object, event, radius)
Not sure, but I believe these things can be called to activate a Frenzy-like power... The last parameter assigns the radius of the event. This one affects Allies only.


ObjectBroadcastEventToEnemies(object, event, radius)
Same as above, though for affecting your enemy.

ObjectHideSubObjectPermanently(object, object, flag)
This hides (if flag == true) or shows (if flag == false) a subobject on the model of the specified object. If set to true, it will never show up, even when actively called to show in the Art code (guess)

ObjectHideSubObject(object, object, flag)
Same as above, though it doesn't override Art code hide/show things. (guess)

ObjectGrantUpgrade(object, upgrade)
Give an object an upgrade. I guess these can only be of the OBJECT_UPGRADE type.

ObjectRemoveUpgrade(object, upgrade)
This removes an upgrade from the assigned object.

ObjectDoSpecialPower(object, power)
The object executes the given special power, if it has the ability to do so. It'll probably only work on powers that don't need a target position...

ObjectSetGeometryActive(object,geometry,flag)
I think this activates and deactivates geometry tags... So, basically, buildings can have non-square geometry. In the few scripts available it is used for object upgrades where the new building is larger than the original one.

ObjectCreateAndFireTempWeapon(object, weapon)
Not entirely sure what this does, but I think it makes an object fire a specified weapon at its current location.

print(text)
Simple text print command, standard in Lua. Dunno how it is actually shown in-game.

ObjectDescription(object)
I guess this shows the name and some information about the given object...

ObjectPlaySound(object, sound)
Plays a sound as if it's coming from the specified object.

ObjectEnterFearState(object, other, flag)
Makes the 'object' fear the thing 'other', if flag == true. If flag == false, the fear state is ended.

BecomeUncontrollablyAfraid(object,other)
Same as above I think, though it doesn't take a flag as argument so I guess it subsides after a few seconds...

ObjectEnterCowerState(object,other)
Makes the 'object' afraid of 'other', but makes it hide instead of flee.

ObjectEnterRunAwayPanicState(object, other)
Makes 'object' flee away from 'other'.

ObjectSetEnragedState(object, flag)
This will make the 'object' furious if flag == true, else the anger will subside.

ObjectEnterAlertState(object)
Makes the defined object alert for enemy threats (same as Guard in C&C Generals methinks)

ObjectEnterRampageState(object)
I guess this makes things go berserk... I like. I like a lot ;)



Well, that was about it. I guess we'll just have to wait patiently for BFME2 to be released before we can really experiment with this. It's gonna be awesome!
Posted Image
Like me? Put this in your sig then!
Posted Image

Posted Image <- That's me!

#5 Chrizz

    E-Studios™ 2012

  • Gold Member
  • 2012 posts
  • Projects: C&C3: Tiberium Icestorm

Posted 25 January 2006 - 15:31

Also i have tested some stealth stuff in the game and works to.

i hope the release of the xbox 360 will read custom ini files of the PC hehe that will be great!



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users