Choose one, download, stick into the \LuaRules\Gadgets\ of your mod, and edit the lines at the top to suit your mod.
- 1) Automatic version: You edit the two conditions and the number at the top, and then it automatically find the unit matching them and manage the prerequisite relationship. The provided makes it mandatory to have built 3 radars before getting access to defense turret. Lower down that thread is a similar one locking out factories until three mexxes are built. The beauty of it is that you don't have to list out all the name or ID of all defense, mexx or factories you want the gadget to be applied to, which makes it indepent from the mod. For instance, to lock out ressurectors until you have constructors, change the top of it to:
Code: Select all
local n = 2 -- Including the commander local function isUnlocker(ud) return UnitDefs[ud].isBuilder end local function isLocked(ud) return UnitDefs[ud].canResurrect end function gadget:GetInfo() return { name = "Rez requires "..n.." cons", desc = "Lock resurrector from build menu until you have "..n.." constructors",
- 2) Simple Tech: One single "research lab", unlock a batch of units. It's a one shot upgrade, that you keep even after the "research lab" is destroyed. Make sure to edit the top of it to make it match your own unitnames.
- 3) Single Tech, with count: Many unit act as "research lab", but they all unlock the same tech, the same batch of units. As soon as N are completed, and as long as you have them. As an exemple, I lock out all heavy laser defense until you have 5 light laser tower, but of course you should edit the unitname at the top of the gadget to suit your own unitset. Comes with automatic tooltip edition of the locked out unit. It act opposite of the the previous reguarding giving units to another team.
- 4) Intermediate version: A whole range of tech level, from 0 to as high as you want. You can have different units enabling the same tech level. When a tech level is reached, every unit of that level and of below levels are unlocked. It's the act of building and completing the specified structures (or mobile units, if you fancy) that grants the tech level: There's no research button, you just build the research lab the way you'd build any other building.
The tooltips of lockeds and unlockers are edited by the gadget, but I should have chosen another name than "tech level", for Spring already calculate its own "tech level" and show it in tooltip, and it is confusing to see two different kinf of "tech level" in tooltips.
You can tie not only units builbuttons, but also any commands, to a tech level. Like, D-Gun locked out until you build a tech 3 research center. Though there's likely a bug with enqueued orders staying after you lose the tech level.
Losing research lab of course make you lose the associated tech level, unless you have other labs. When you lose a tech, units already under construction can be finished, but enqueued units won't get built.
Skipping tech level is possible, if you build a tech 10 lab right away you'll jump straight from tech 0 to tech 10. And having tech 10 automatically enable all the lower tech 1,2,3,4,5,6,7,8,9.
It's limited to a mono-dimensional ladder, cannot do branching trees. - 5) Advanced version: The tech are not labelled by a simple number, but can bear any name. It is no more one dimensionnal, you can have all the branching out you like, even self-sustaining tech or tech pathes looping back on themselves. The gadget does not need to be changed to suit a mod. The technology name, the units that grant or require a tech, are defined in FBI. More precisely, by a RequireTech=..; and a ProvideTech=..; tag in the [CustomParams] section of [UnitInfo] in a FBI. A single unit can provide multiple tech (comma separated), or require multiple tech (comma separated). Advanced user can use lua hook to slave any command to a tech from a different gadget. Though it has the same bug as previous gadget with already queued commands not deleted when tech is lost. And as for the two others gadgets, read the comment at top of the .lua file for details.
- 6) Ultimate version: Like multi tech, but with the addition of count and range. So, as many named "tech" as you want. Each "tech" has a level. Building more "research lab" increase that level. A given "research lab" unit can increase several "tech" at once, and each by a different amount. "research lab" optionnaly have a limited area of effect. Negative providetech can be used to implement shared unitlimits. All doable via custom FBI tags, if you want ease of use. Or can also be done by calling hooks from other gadgets, if you prefer a more dynamic approach. Some more info about it some posts below.
Yeah, I know many other mods have research already, and some done more prettily. So there's nothing new or grounbreaking here. But I was asked to code some simple research system, then got carried away and felt a sudden urge to write up three research gadgets showing the progression from a quick one up to a full fledged one. But since I don't feel like building three whole mods just to showcase them, I decided to just post here. Hopefully, one or two modders looking for a tech system will find them useful. While you could use every five of those gadget in this mod (but not 5 and 6 together), there will be conflict if two of them try to handle a lock on the same unit. For instance, (1) and (3) don't play well together because (1) unlock the heavy laser tower despite (3) wanting them still locked. Anyway, (6) can do everything the others do, and more.