converting tdf to lua (luadefs) Weapon - Unit Explosions

converting tdf to lua (luadefs) Weapon - Unit Explosions

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

converting tdf to lua (luadefs) Weapon - Unit Explosions

Post 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.
Last edited by Forboding Angel on 02 Nov 2009, 21:49, edited 1 time in total.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Technically this is the wrong place (combining luadefs)

Post 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.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Technically this is the wrong place (combining luadefs)

Post 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 :-)
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Re: Technically this is the wrong place (combining luadefs)

Post 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.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Technically this is the wrong place (combining luadefs)

Post 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)
Post Reply

Return to “Lua Scripts”