Jump to content


Photo

LUA and scripting fun


  • Please log in to reply
16 replies to this topic

#1 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 15 January 2009 - 01:36 PM

I thought I'd create a topic to discuss the coolness that is LUA.
So if you have a cool LUA script or would like help with one post here.
(This is another one of my everything goes here topics that I like)

LUA is a very powerful modding tool that can expand what is possible from coding and really expands what mods can do.
LUA is used for simple things like hiding subobjects like Forged Blades.
It can be used to randomise weapons or models or used to trigger fear the possibilities are vast,I hope by having a topic like this we can learn more about LUA and it's capabilities.

I have been playing with a scripting that allows Gimli to get temporarily stronger when facing lots of enemies.
I haven't got the script ready yet but basically it works like this.
The script reads the amount of nearby enemies and when it surpasses a certain number it triggers a special power similar to
Blade Master that makes him stronger.
For this check out Gandalf's Telekinetic push script.

Another script I am working on is a random critical damage weapon.
I will get into that once I worked it out more fully.

Another cool thing is using map scripts to trigger power.
These allow a lot of freedom in coding adding a lot of different options I got this idea from RJ's camera power thing and the Day/Night transition thing.

Basically a script is made in worldbuilder that when triggered will fire a special power.
Using "fake" special powers that trigger map script events can create a lot of great things.
Just think of firing of a spawning spell at a special waypoint or having a special power that evacuates all units from transports all instakills everything.
Script/Coding (we should come up with a name for it) of course has to be added to all maps for it to be universal a drawback but if your power is really cool it is worth the extra effort.

I don't think mapping and modding are seperate things and the 2 can really support each other.
So let's see what we can come up with.

(can someone pin this one,this can be an important resource for coders it's always good to have a one stop shop for these things)

Break dancing into the hearts of millions


#2 Phil

Phil

    Force Majeure

  • Network Leaders
  • 7,971 posts
  • Location:Switzerland
  • Projects:Revora, C&C:Online
  •  Thought Police
  • Division:Revora
  • Job:Network Leader
  • Donated
  • Association

Posted 15 January 2009 - 07:01 PM

I actually believe nobody here has fully taken advantage of LUA scripting. From a technical point of view the possibilities are very limited, however the options it adds to the (limited) pool of overall possibilities in BFME are interesting. The point is though that LUA alone cannot do much... the power it gives you is only useful if you can combine it with standard items like powers, upgrades and model states.

I myself once planned to expand on the typical random-subobject scripts and create truly random units by assigning units upgrades (something you can do in LUA), so you can have random skins, subobjects, weapons, armors, powers, etc. Still a very limited use, but already interesting gameplay-wise.
The other idea I had involved a chain of LUA broadcasts, states and upgrades. Unfortunately all I remember is that it involved Frodo and the Nazgûl :wink_new:

revorapresident.jpg
My Political Compass

Sieben Elefanten hatte Herr Dschin
Und da war dann noch der achte.
Sieben waren wild und der achte war zahm
Und der achte war's, der sie bewachte.


#3 Sûlherokhh

Sûlherokhh

    Sagacious Engineer

  • Project Team
  • 3,754 posts
  • Location:Central Germany
  • Projects:S.E.E., Sage A.I., Code Advisor
  •  'Axe'er of the Gordic Knot

Posted 15 January 2009 - 07:11 PM

I actually believe nobody here has fully taken advantage of LUA scripting. From a technical point of view the possibilities are very limited, however the options it adds to the (limited) pool of overall possibilities in BFME are interesting. The point is though that LUA alone cannot do much... the power it gives you is only useful if you can combine it with standard items like powers, upgrades and model states.


But i did!

SuperModding
SuperDuperModding

Thanks to you, remember?

Credits:
Dark Lord of the Sith For hinting at the 'scriptevents.xml'


Edit: of course i didn't use everything. But i am using everything useful to me. Broadcasting can also be done by coding for example. :wink_new:

bannerreal01mittelit3.jpg
Axed Head and A.I. Coder for S.E.E. and ... stuff

".. coding is basically boring. What's fun is finding out how things work, take them apart and then put them together in ways that were not intended nor even conceived."


#4 robnkarla

robnkarla

    title available

  • Hosted
  • 1,849 posts
  • Location:California
  • Projects:RJ-RotWK
  •  crazy coder

Posted 15 January 2009 - 07:19 PM

I definitely want to use LUA scripting much more than I currently am using it, but it's those blasted object upgrade limits that are driving me crazy. I've already hit the limit 3 times and had to re-write a whole set of upgrades just to re-gain them.

They are the whole basis for what I'm doing with the ring and many other ideas I've had. Blast you, CAH, and your 500 object ugprades that I need to re-do!!! :wink_new:

Seriously, there is so much that you can do along the lines that Sul has outlined in his articles that really is so very tempting :crazed:

Robert J.

#5 Lauri

Lauri

    Let us remember foREVer

  • Hosted
  • 10,419 posts
  • Location:Norway
  • Projects:'The 4th Age' and 'Shadow and Flame'
  •  The very worst T3A Team Chamber Member

Posted 15 January 2009 - 07:26 PM

I love LUA... I'd love to use it more, and not only for random equipment... My favorite part about random equipment though, as different animation sets for them (using spears and swords in same horde for example..)

I tried to nail a broadcast Mount for the slave Guards for a hero, when he mounts, they mount... problem was, only 2 out of 4 did :wink_new:

LUA's still great great fun though, but may I ask, is it possible to change skin via it? I've never looked into that :crazed:

Shadow and Flame BETA 0.6 RELEASED - Link


#6 Phil

Phil

    Force Majeure

  • Network Leaders
  • 7,971 posts
  • Location:Switzerland
  • Projects:Revora, C&C:Online
  •  Thought Police
  • Division:Revora
  • Job:Network Leader
  • Donated
  • Association

Posted 15 January 2009 - 08:16 PM

I actually believe nobody here has fully taken advantage of LUA scripting. From a technical point of view the possibilities are very limited, however the options it adds to the (limited) pool of overall possibilities in BFME are interesting. The point is though that LUA alone cannot do much... the power it gives you is only useful if you can combine it with standard items like powers, upgrades and model states.


But i did!

SuperModding
SuperDuperModding

Gee, I'm so sorry :wink_new:
Seriously, I totally forgot about that first article of yours. I've never even read the second because working with the AI never interested me. So I'll take back most of what I said about LUA not being used effectively. Still, I believe that there is a lot more potential.

revorapresident.jpg
My Political Compass

Sieben Elefanten hatte Herr Dschin
Und da war dann noch der achte.
Sieben waren wild und der achte war zahm
Und der achte war's, der sie bewachte.


#7 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 17 January 2009 - 04:06 AM

I don't think this is working anyone have any ideas?

function GimliUseMadAxes(self, other, delay, amount)
	-- Or, if we are being hit and there are alot of guys arround, do our cool pushback power
	if tonumber(ObjectCountNearbyEnemies(self, 50)) >= 4 then
		ObjectDoSpecialPower(self, "SpecialAbilityGimliMadAxe")
		return
	end
end

<EventList Name="GimliFunctions" Inherit="InfantryFunctions">
		<EventHandler EventName="DamageIncoming" ScriptFunctionName="GimliUseMadAxes" DebugSingleStep="false"/>
	</EventList>

The AI Update all looks right and the special power too it's a simple modified Blade master power.
It looks right to me but i'm not sure.

Break dancing into the hearts of millions


#8 ched

ched

    .

  • Undead
  • 4,431 posts
  • Location:Angers (France)
  • Projects:Rhovanion Alliance
  •  T3A Team Chamber Member
  • Division:BFME
  • Job:Previous Division Leader

Posted 20 January 2009 - 09:42 PM

It may have to do with the KindOf. I've found myself stuck trying to trigger special powers using lua.
Software is like sex; it's better when it's free ~Linus Torvald

#9 Lauri

Lauri

    Let us remember foREVer

  • Hosted
  • 10,419 posts
  • Location:Norway
  • Projects:'The 4th Age' and 'Shadow and Flame'
  •  The very worst T3A Team Chamber Member

Posted 21 January 2009 - 04:02 PM

function EldaravirSummon(self)
	--This spawns Citadel Guards when Eldaravir is near death... despite the power name
 ObjectDoSpecialPower(self, "SuperweaponSpawnOrcs")
end

<EventList Name="EldaravirFunctions" Inherit="BaseScriptFunctions">
	   <EventHandler EventName="ReallyDamaged"			ScriptFunctionName="EldaravirSummon" DebugSingleStep="false"/>
	</EventList>
that works :p
Then again, it could be your tonumber thingy that's got problems...

Shadow and Flame BETA 0.6 RELEASED - Link


#10 Nertea

Nertea

    ...lo sa raptor!

  • Hosted
  • 3,349 posts
  • Location:Vancouver, Canada
  • Projects:Star Villains and Space heroes, The Dwarf Holds
  •  T3A Chamber Member
  • Division:BFME/Unity

Posted 21 January 2009 - 05:18 PM

Try defining the result of tonumber(args) in a variable first and comparing that in the if statement, lua is sometimes funny like that. It's also possible that the function needs a self declaration in front. If standard lua we'd use
self:ObjectDoSpecialPower('"SpecialAbilityGimliMadAxe')
but from what Lauri posted, it looks like your syntax is fine, so I don't know.

sig.png
I really don't do requests and my Arnor Soldier is not fit for BFME. Don't ask me for either.


#11 Nertea

Nertea

    ...lo sa raptor!

  • Hosted
  • 3,349 posts
  • Location:Vancouver, Canada
  • Projects:Star Villains and Space heroes, The Dwarf Holds
  •  T3A Chamber Member
  • Division:BFME/Unity

Posted 26 July 2009 - 06:29 PM

Has anyone actually used ObjectTestModelCondition(self, condition) and had it work? I've been trying things all day with no success - won't trigger on a USER, WEAPONSET, WEAPONSTATE, DAMAGED, etc...

sig.png
I really don't do requests and my Arnor Soldier is not fit for BFME. Don't ask me for either.


#12 Kwen

Kwen

    Vileartist

  • T3A Staff
  • 4,837 posts
  • Location:Korea I wish
  • Projects:It'sa secreeet
  •  T3A's First N00b
  • Division:BFME
  • Job:T3A Expert
  • Donated

Posted 11 August 2009 - 10:55 PM

I've never found a working tutorial or someones explanation on how to use LUA to code in random weapons and stuff.

                           https://www.twitch.tv/vileartist - Yes shameless self-promotion

          ----------------------------------------------------------------------------------------------------------------------

                            "Old modders never die, they just fade away" ~ Hostile


#13 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 12 August 2009 - 01:55 AM

http://www.the3rdage...tem-147?addview
Try that one


CODE
function EldaravirSummon(self)
--This spawns Citadel Guards when Eldaravir is near death... despite the power name
ObjectDoSpecialPower(self, "SuperweaponSpawnOrcs")
end


CODE
<EventList Name="EldaravirFunctions" Inherit="BaseScriptFunctions">
<EventHandler EventName="ReallyDamaged" ScriptFunctionName="EldaravirSummon" DebugSingleStep="false"/>
</EventList>

that works wink.gif
Then again, it could be your tonumber thingy that's got problems...


I forgot to try that out I am now looks like it should work

I tried it worked thanks Lauri.

Edited by Radspakr, 12 August 2009 - 02:17 AM.

Break dancing into the hearts of millions


#14 Nertea

Nertea

    ...lo sa raptor!

  • Hosted
  • 3,349 posts
  • Location:Vancouver, Canada
  • Projects:Star Villains and Space heroes, The Dwarf Holds
  •  T3A Chamber Member
  • Division:BFME/Unity

Posted 18 November 2009 - 07:59 AM

After discovering that BFME can indeed handle lua tables, and thus useful helper functions, I've written a small tutorial (really more of a code resources) on doing that. Check it out and let me know if it's useful!

Writing random model code just got a whole lot easier for me...

sig.png
I really don't do requests and my Arnor Soldier is not fit for BFME. Don't ask me for either.


#15 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 15 March 2010 - 02:25 PM

Some Lua I'm working on.
At the moment it doesn't work I haven't yet figured out if it's the code or the Lua.

Here's how it works.

When Thorin gets hit there is a 1/4 chance that he will counter hit with the Counterhit spell.
As far as I can tell everything looks alright.
As for the power it's a simple weapon fire type based on Word of power.
I'm going to run some more tests but I thought it'd be good to have my Lua a looking over by you guys.

function Counterhit (self, other, delay, amount)
	if tonumber(delay) > 1 then
		if tonumber(amount) >= 10 then
	   if counterhit <= 0.25 then
	   ObjectDoSpecialPower(self, "SpecialAbilityCounterhit")
	   return
elseif counterhit <= 0.4 then
	nil
	return
elseif counterhit <= 0.6 then
	nil
	return
elseif counterhit <= 0.8 then
	nil
	return
   end
end

Break dancing into the hearts of millions


#16 Nertea

Nertea

    ...lo sa raptor!

  • Hosted
  • 3,349 posts
  • Location:Vancouver, Canada
  • Projects:Star Villains and Space heroes, The Dwarf Holds
  •  T3A Chamber Member
  • Division:BFME/Unity

Posted 15 March 2010 - 03:30 PM

There are quite a few things that *could* be wrong with that. It would be better if you posted the scriptevents code and the unit power code as well - most enums don't seem to work with the ObjectDoSpecialPower trigger.

Code-wise, a few problems. One is that counterhit is not defined anywhere, so if counterhit <= 0.25 then won't work. You're also missing some trailing Ends, a lua if statement goes

if
elseif
end

Your structure has, essentially

if
-if
--if
--elseif
--elseif
--elseif
--end
-end

So you're missing an end for the first If statement, then also the End for your function. I'd also like to note that I've never got the DamageIncoming flag to work reliably, so I've used OnDamaged instead for a similar function:

function DainDoSuper(self,other)
	local chance  = GetRandomNumber()
	if chance <= 0.25 then
		ObjectBroadcastEventToEnemies(self, "BeTerrified", 250)
		ObjectDoSpecialPower(self, "SpecialPowerBlockAttack" )
	end
end

This I know works :p.

sig.png
I really don't do requests and my Arnor Soldier is not fit for BFME. Don't ask me for either.


#17 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 16 March 2010 - 12:09 AM

Ah Ok I'll have a look at that right after my cup of tea :shiftee2:
I'll post back with the results.

Thanks Nert I got it working now I can start on all the other new powers :p

Edited by Radspakr, 16 March 2010 - 12:52 AM.

Break dancing into the hearts of millions





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users