Page 1 of 1
converting tdf to lua (luadefs) Weapon - Unit Explosions
Posted: 30 Oct 2009, 22:39
by Forboding Angel
I want to take all my unit explosions and stick them in a single luadef, I do not want them inside the unit files. How do I go about doing this (as in, what would the file look like and would it go in weapons or in units folders?)?
edit: changed the thread title so that it should show up in searches for similar problems.
Re: Technically this is the wrong place (combining luadefs)
Posted: 31 Oct 2009, 01:13
by FLOZi
Forboding Angel wrote:I want to take all my unit explosions and stick them in a single luadef, I do not want them inside the unit files. How do I go about doing this (as in, what would the file look like and would it go in weapons or in units folders?)?
What do you mean by unit explosions? The weapons that detonate when the unit dies or the explosion FX?
I'll presume the former considering what you said, in which case, weapons folder. I don't have an example to hand of a lua weapondef, but i imagine it is done much the same as a lua unit def. Someone was working on one recently, sorry I forget who it was, but it was for one of the new fantasy projects iirc.
Code: Select all
unitDeaths = {
smallDeath = {
name = "small death",
etc = "etc",
},
bigDeath = {
name = "big death",
andSoOn = "and so on",
},
}
return lowerkeys(unitDeaths)
is a rough guess of the syntax.
Re: Technically this is the wrong place (combining luadefs)
Posted: 31 Oct 2009, 07:59
by Forboding Angel
FLOZi wrote:What do you mean by unit explosions?
Yes, precisely

I have a new sound engineer join the project to some extent and I need to do a lot of cleanup (a la, get rid of the old TDF's).
Yes that syntax looks correct, but there are always headers and stuff at the tops and bottoms of the luadef files, and tbh I know that if I mess up the syntax, spring will outright crash on loading, so I'm wanting to avoid any obvious pitfalls if I can.
Anyone know what the header and footer of the file should look like?
Thanks FLOZi

Re: Technically this is the wrong place (combining luadefs)
Posted: 31 Oct 2009, 11:27
by SpliFF
Lua being what it is the syntax is very flexible, as long as it is valid lua, and as long as the code
returns a table and the table contains the correct keys.
Code: Select all
return {
key="value",
key2="value"
}
is as valid as:
Code: Select all
foo = {}
foo['key'] = "value"
foo['key2'] = "value"
return foo
That lowerkeys function is just a weird thing somebody (probably from CA) added to make the file a little more readable since it appears the engine wants lowercasekey="value" as table members but the person who wrote the def prefers camelCaseKey="value".
In short the file is actually a
function, not a data structure.
Re: Technically this is the wrong place (combining luadefs)
Posted: 02 Nov 2009, 21:47
by Forboding Angel
Thanks spliff, your last sentence basically answered my question and it works great
btw this was the header I needed (answered by flozi above)
--------------------------------------------------------------------------------
unitDeaths = {
and the footer needed is this:
return lowerkeys(unitDeaths)
SO basically when it's all said and done, if you were to make weapons for the "weapons" folder in your mod in luadefs it would look sorta like this:
--------------------------------------------------------------------------------
unitDeaths = {
SMALL_BUILDING = {
name = "Small building",
rendertype=4,
ballistic=1,
turret=1,
range=480,
reloadtime=3.6,
weaponvelocity=250,
areaofeffect=205,
soundstart="explode2.wav",
soundhit="explode2.wav",
explosiongenerator="custom:FACTORY_EXPLOSION_SMALL",
damage = {
default = 10,
},
},
}
return lowerkeys(unitDeaths)