How should I use LuaDefs stuff?

How should I use LuaDefs stuff?

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

Moderator: Moderators

Post Reply
tombom
Posts: 1933
Joined: 18 Dec 2005, 20:21

How should I use LuaDefs stuff?

Post by tombom »

I've got an SVN install of Spring and am trying to use LuaDefs to automatically set the metal values for features. I'm running into a bit of trouble. This is what I've added to the SVN defs.lua in the mod gamedata folder, just before the return:

Code: Select all

for name, ud in pairs(DEFS.unitDefs) do
	if(ud.corpse) then
		if(DEFS.featureDefs[ud.corpse]) then
			DEFS.featureDefs[ud.corpse].metal = 5
			Spring.Echo(ud.corpse)
		end
	end
end
It only prints
armbc_dead
corcrash_dead
corbhmth_dead
corgeo_dead
armgeo_dead
but there are far more corpses and units than that. The cases match up. Those corpses get their metal set correctly. What am I doing wrong?
tombom
Posts: 1933
Joined: 18 Dec 2005, 20:21

Post by tombom »

Bump because I'd really like to know what I'm doing wrong ;_;

The source is kind of confusing for this.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

-- check that ud.corpse is a string first
local corpseName = string.lower[ud.corpse] ?

To do this right, you'll probably want to make a map
of minimum values for each corpse type used by
unitDefs (just in case more than one type used the
same corpse, even if your particular mod doesn't
share corpses),
tombom
Posts: 1933
Joined: 18 Dec 2005, 20:21

Post by tombom »

I think that fixed it. Thanks :)

Here's what I have now. It should work fine on SVN builds if all your units have separate corpses and heaps. There's a lot of room for improvement obviously.

Code: Select all

local metalCorpseFactor = 0.7
local metalCrushedFactor = 0.3

local healthCorpseFactor = 0.7
local healthCrushedFactor = 0.3

for name, ud in pairs(DEFS.unitDefs) do
   if(ud.corpse) then
	local corpseName = string.lower(ud.corpse)
	DEFS.unitDefs[name].corpse = corpseName
      if(DEFS.featureDefs[corpseName]) then
         DEFS.featureDefs[corpseName].metal = ud.buildcostmetal*metalCorpseFactor
	   DEFS.featureDefs[corpseName].damage = ud.maxdamage*healthCorpseFactor
	   if(DEFS.featureDefs[corpseName].featuredead) then
	   	local featureDead = string.lower(DEFS.featureDefs[corpseName].featuredead)
	   	DEFS.featureDefs[featureDead].metal = ud.buildcostmetal*metalCrushedFactor
	   	DEFS.featureDefs[featureDead].damage = ud.maxdamage*healthCrushedFactor
		Spring.Echo(featureDead)
	   end
         Spring.Echo(corpseName)
      end
   end
end
Put that above the final return statement in defs.lua.
Post Reply

Return to “Lua Scripts”