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

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Schallfalke
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Sun Oct 28, 2018 7:57 am
Contact:

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

Post by Schallfalke » Fri Nov 23, 2018 10:08 am

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
Last edited by Schallfalke on Tue Dec 04, 2018 8:10 am, edited 1 time in total.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post by eradicator » Fri Nov 23, 2018 1:28 pm

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]]}
  )
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English

Schallfalke
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Sun Oct 28, 2018 7:57 am
Contact:

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

Post by Schallfalke » Fri Nov 23, 2018 5:24 pm

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...

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6348
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post by bobingabout » Mon Nov 26, 2018 10:22 am

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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.

Schallfalke
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Sun Oct 28, 2018 7:57 am
Contact:

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

Post by Schallfalke » Mon Nov 26, 2018 3:45 pm

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.

Post Reply

Return to “Modding discussion”

Who is online

Users browsing this forum: No registered users and 2 guests