biter spawner rate

Place to get help with not working mods / modding interface.
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

biter spawner rate

Post by Dysoch »

im adding 3 new biters, but i have a question about the spawner itself:

Code: Select all

 result_units = (function()
                     local res = {}
                     res[1] = {"small-biter", 0.3}
                     if not data.isdemo then
                       res[2] = {"medium-biter", 0.3}
                       res[3] = {"big-biter", 0.4}
                     end
                     return res
                   end)(),
    spawning_cooldown = {300, 150}, -- With zero evolution the spawn rate is 5 seconds, with max evolution it is 2.5 seconds
    spawning_radius = 10,
    spawning_spacing = 3,
    max_spawn_shift = 0.65,
    max_richness_for_spawn_shift = 100,
about the result units. it gives an 30% chance to spawn both the small and medium biter, and a 40% chance for a big one. This is weird, as small biters spawn way more. and they are together 100%, when adding 3 new ones, does it need to be 100% or can it be more then 100%?
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: biter spawner rate

Post by FreeER »

Yes it should add up to 1.0 (or 100%)
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: biter spawner rate

Post by Dysoch »

FreeER wrote:Yes it should add up to 1.0 (or 100%)
Ok, but it gave no error while loading or starting a new game (i just copied the spawn rates from the big biters for now to see if they work, dunno about the actual spawn rates ingame yet)What about the rates? 30% for a small biter is weird, as they spawn more often then big biters. So im a little stomped.

Yes i know, the small biters have a pollution attack threshold of 100 (i think of the top of my head) but that still wont explain the 30% compared to the big ones of 40%

this gave no errors:

Code: Select all

result_units = (function()
                     local res = {}
                     res[1] = {"small-biter", 0.3}
                     if not data.isdemo then
                       res[2] = {"medium-biter", 0.3}
                       res[3] = {"big-biter", 0.4}
					   res[4] = {"berserk-biter", 0.4}
					   res[5] = {"elder-biter", 0.4}
					   res[6] = {"king-biter", 0.4}
                     end
                     return res
                   end)(),
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
kovarex
Factorio Staff
Factorio Staff
Posts: 8293
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: biter spawner rate

Post by kovarex »

The spawn rates are affected by the evolution factor.
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: biter spawner rate

Post by Dysoch »

kovarex wrote:The spawn rates are affected by the evolution factor.
i assume that that is this:

Code: Select all

    maximum_count_of_owned_units = 15,
    spawning_cooldown = {300, 150}, -- With zero evolution the spawn rate is 5 seconds, with max evolution it is 2.5 seconds
    spawning_radius = 15,
    spawning_spacing = 2,
    max_spawn_shift = 0.65,
    max_richness_for_spawn_shift = 100,
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: biter spawner rate

Post by FreeER »

A comment in the code said it should be one, though looking at it now that may have been for the values not total lol.
But, looking through it to see how it works it isn't exactly a 30-30-40 ratio. The way it works is that when it's time to spawn a unit it generates a value that is equal to math.random() (basically) * maxSpawnShift (0.65 for vanilla) * math.min(entityCreationParameters.richness/maxSpawnShift) + evolutionFactor and then uses a for loop to check each result unit, if the unit's spawn ratio (that you provided) is >=GeneratedValue then it that is what is spawned, otherwise it checks the next unit in the table (and then it could still fail to place it I think lol). I'm guessing that entityCreationParameters.richness is a random value I haven't traced it yet.
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: biter spawner rate

Post by Dysoch »

ok, i need more help.

this is the spawn code

Code: Select all

    result_units = (function()
                     local res = {}
                     res[1] = {"small-biter", 0.17}
                     if not data.isdemo then
                       res[2] = {"medium-biter", 0.17}
                       res[3] = {"big-biter", 0.17}
					   res[4] = {"berserk-biter", 0.17}
					   res[5] = {"elder-biter", 0.17}
					   res[6] = {"king-biter", 0.15}
                     end
                     return res
                   end)(),
But the problem is here:
Image
Each number matches the res[1] number. The location is where i found them (used god mode scenario for testing, at max everything (enemies wise)
(to calculate it to normal settings, double the distance between each spawn point twice. found that out after testing)(for each richness setting the spawn distance at start doubles or halves, depending on whether you make it richer or poorer)

I kept going on after the picture was taken, but res[5] and res[6] dont show up anywhere.

Can somebody figure out a good balance for me?
this is what i want:

Code: Select all

res[1] --Want this to spawn from the start, but so that at later stages they dissapear
res[2] -- Want this to spawn relative quickly after you find your first base.
res[3] -- want this about 3 minutes walking away from res[2]
res[4] -- this follows res[3] relatively quickly, only 1 minute away.
res[5] -- this follows res[4] relatively quickly, only 1,5 minute away.
res[6] -- this is a tricky one. its extremely strong, so i dont want it to spawn to soon, or to many. about 5 minutes walk after res[5]
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: biter spawner rate

Post by Dysoch »

Ok got it to work, somewhat.

Put res 1-4 at 0.15 and res 5 and 6 at 0.20 (this is the base spawn rates, only halved)
Res 5 shows up, but res 6 doesnt

Why is that?
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: biter spawner rate

Post by Dysoch »

ok. the spawn rates are good.

But now i got another problem.
i added an egg, that when placed, spawns a biter spawner. They only problem is it wont turn to enemies. Its force is still player.
i tried adding this to control.lua, but no avail:

Code: Select all

	--[[Biter spawner build]]--
	elseif event.createdentity.name == "biter-spawner" then
		if not glob.spawner then
			glob.spawner = {}
		end
		table.insert(glob.spawner, {entity=event.createdentity, tick=event.tick, force=game.forces.enemy})
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
kovarex
Factorio Staff
Factorio Staff
Posts: 8293
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: biter spawner rate

Post by kovarex »

Dysoch wrote:ok. the spawn rates are good.

But now i got another problem.
i added an egg, that when placed, spawns a biter spawner. They only problem is it wont turn to enemies. Its force is still player.
i tried adding this to control.lua, but no avail:

Code: Select all

	--[[Biter spawner build]]--
	elseif event.createdentity.name == "biter-spawner" then
		if not glob.spawner then
			glob.spawner = {}
		end
		table.insert(glob.spawner, {entity=event.createdentity, tick=event.tick, force=game.forces.enemy})
The code I see just adds the created spawner into some table, but I can't see the code that creates the spawner.
You can either specify the force when creating the entity: https://forums.factorio.com/wiki/inde ... eateentity
Or you can change the force of existing entity (after creation): https://forums.factorio.com/wiki/inde ... tity#force
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: biter spawner rate

Post by Dysoch »

ok, im using these events:

this is to change the spawners from spawner-1 to spawner: (spawner-1 is not autoplaced in the world)

Code: Select all

	if glob.spawning~=nil and game.tick%60==1 then
		for i, spawning in pairs(glob.spawning) do
			if spawning.valid then
				game.getplayer().print("killed and switched") --used these to check if it works
				spawning.die()
				game.createentity{name = "biter-spawner", position=!NOTE!, force=game.forces.enemy, time=2}
			break
			elseif not spawning.valid then
		game.getplayer().print("not vaild")
        table.remove(glob.spawning, i)
			break
			end
		end
	end
at !NOTE! i want the position of the placed spawner, how do i find that?

this is the table insert event:

Code: Select all

	--[[Biter spawner build]]--
	elseif event.createdentity.name == "biter-spawner-1" then
		if not glob.spawning then 
			glob.spawning = {}
		end
		table.insert(glob.spawning, event.createdentity)
as a side note:
i specified different types of spawn rates in the biter-spawner data file. But when i place down the egg (eg create a spawner) the spawn rates go berserk and spawn everything wildly. they no longer follow evolution.
(tested at start of game: At start checked what is being spawned (small biters) and then placed spawner through egg, after that, all 6 the biters start to spawn (even Mega Biter :P ))

code for the egg:

Code: Select all

data:extend(
{
  {
    type = "item",
    name = "biter-queen-egg",
    icon = "__DyTech__/graphics/icons/queen-egg.png",
    flags = {"goes-to-quickbar"},
    group = "combat",
    order = "b-q-e",
    place_result = "biter-spawner-1",
    stack_size = 64
  },
}
)
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: biter spawner rate

Post by ficolas »

Game.createentity returns the entity that is created, so you could:
position=game.createentity(arguments here).position
And if you also need to use other things from the entity you could just do:
entity=game.createentity(arguments here)
And then access entity as you would with any entity.
entity.destroy() / entity.position.x / whatever
kovarex
Factorio Staff
Factorio Staff
Posts: 8293
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: biter spawner rate

Post by kovarex »

Dysoch wrote:at !NOTE! i want the position of the placed spawner, how do i find that?

Code: Select all

            spawning.die()
            local spawningposition = spawning.position
            game.createentity{name = "biter-spawner", position=spawningposition, force=game.forces.enemy, time=2}
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: biter spawner rate

Post by Dysoch »

kovarex wrote:
Dysoch wrote:at !NOTE! i want the position of the placed spawner, how do i find that?

Code: Select all

            spawning.die()
            local spawningposition = spawning.position
            game.createentity{name = "biter-spawner", position=spawningposition, force=game.forces.enemy, time=2}
Great, thx

But why is it, that when you dont place the spawner, the evolution is normal. But when you place the spawner, the evolution goes berserk? (Eg, spawns the. Mega biter right at the start of a game.)
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: biter spawner rate

Post by ficolas »

Dammned phpbb with android.
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: biter spawner rate

Post by Dysoch »

ok i added the code by kovarex, but i get an api error. it says value of 0?

this is the code now:

Code: Select all

if glob.spawning~=nil and game.tick%60==1 then
		for i, spawning in pairs(glob.spawning) do
			if spawning.valid then
				game.getplayer().print("killed and switched")
				spawning.die()
				local spawningposition = spawning.position (ERROR POINTS TO THIS LINE)
				game.createentity{name = "biter-spawner", position=spawningposition, force=game.forces.enemy, time=2}
			break
			elseif not spawning.valid then
		game.getplayer().print("not vaild")
        table.remove(glob.spawning, i)
			break
			end
		end
	end
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: biter spawner rate

Post by rk84 »

Dysoch wrote:ok i added the code by kovarex, but i get an api error. it says value of 0?

this is the code now:

Code: Select all

if glob.spawning~=nil and game.tick%60==1 then
		for i, spawning in pairs(glob.spawning) do
			if spawning.valid then
				game.getplayer().print("killed and switched")
				spawning.die()
				local spawningposition = spawning.position (ERROR POINTS TO THIS LINE)
				game.createentity{name = "biter-spawner", position=spawningposition, force=game.forces.enemy, time=2}
			break
			elseif not spawning.valid then
		game.getplayer().print("not vaild")
        table.remove(glob.spawning, i)
			break
			end
		end
	end
Entity is not valid after it is killed with die() (you could use destroy() too since goal is to switch it unnoticeably?)
Move "local spawningposition = spawning.position" over/before "spawning.die()"

To be honest, I too, though that you can get position of it after remove. Did something change or can you access it only in "onentitydied" -event?

Another notes:
  • Not really maters but where does the "time=2" comes from?
  • you dont really need loop if you are breaking it anyway.
    If you plan to keep for-loop, ipairs() is better match then pairs(). Since table.remove accepts only numbers as iterators.
  • "elseif not spawning.valid then" could be just "else" because
    not nil --> true
    not false --> true
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
kovarex
Factorio Staff
Factorio Staff
Posts: 8293
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: biter spawner rate

Post by kovarex »

Yes, as rk84 wrote, first get the position, once you call the die, you can't access it. (spawning.valid would be false).
Post Reply

Return to “Modding help”