Page 1 of 1

[Solved] How to add new enemy type to spawners, without overwriting?

Posted: Fri Nov 23, 2018 10:08 am
by Schallfalke
Hi all,

I am thinking of adding a single new type to spawners, and I found the following code for splitter-spawner in enemies.lua:

Code: Select all

    result_units = (function()
                     local res = {}
                     res[1] = {"small-biter", {{0.0, 0.3}, {0.35, 0}}}
                     res[2] = {"small-spitter", {{0.25, 0.0}, {0.5, 0.3}, {0.7, 0.0}}}
                     res[3] = {"medium-spitter", {{0.4, 0.0}, {0.7, 0.3}, {0.9, 0.1}}}
                     res[4] = {"big-spitter", {{0.5, 0.0}, {1.0, 0.4}}}
                     res[5] = {"behemoth-spitter", {{0.9, 0.0}, {1.0, 0.3}}}
                     return res
                   end)(),
There is a function "wrapping" the res table. How can I add the new enemy type into the table, without completely rewriting the whole thing?
Some players probably have other mods doing something to such table. With a brief search on mod portal, most enemy mods are either a complete overhaul, or new spawners, or just minor stats adjustment to biters.

But I want is just adding a quite small number of new enemy to the existing spawner. How to do it? Are there existing mods that I can take reference to?

Thanks for you attention,
Schall

Re: How to add new enemy type to spawners, without overwriting?

Posted: Fri Nov 23, 2018 1:28 pm
by eradicator
The result of that rather weird bit of code is still a standard table. So you can just

Code: Select all

table.insert(data.raw["unit-spawner"]["spitter-spawner"].result_units,
  {--[[insert your new biter here]]}
  )

Re: How to add new enemy type to spawners, without overwriting?

Posted: Fri Nov 23, 2018 5:24 pm
by Schallfalke
Thank you, treating it as a simple table works. :lol:
It looks reasonable as the function just returns the table and it is assigned to result_units. At data.raw level, result_units is just a simple table...

Re: How to add new enemy type to spawners, without overwriting?

Posted: Mon Nov 26, 2018 10:22 am
by bobingabout
The function is basically just a tool so that they can have the spawner behave differently in the demo.
if you're editing it in a mod, you really don't need to use the function.

Just keep in mind that other mods might be editing the table too, so it's best to try and add to it and edit it, not just outright redefine it.

Re: How to add new enemy type to spawners, without overwriting?

Posted: Mon Nov 26, 2018 3:45 pm
by Schallfalke
Yes, thank you. :D
From eradicator's answer I have already found it out and make a new mod to spawn new enemy types.
Yes, so I did that by using table.insert(), instead of overwriting the whole thing.