Page 1 of 1
biter spawner rate
Posted: Fri Nov 15, 2013 11:14 am
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%?
Re: biter spawner rate
Posted: Fri Nov 15, 2013 11:45 am
by FreeER
Yes it should add up to 1.0 (or 100%)
Re: biter spawner rate
Posted: Fri Nov 15, 2013 11:48 am
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)(),
Re: biter spawner rate
Posted: Fri Nov 15, 2013 12:09 pm
by kovarex
The spawn rates are affected by the evolution factor.
Re: biter spawner rate
Posted: Fri Nov 15, 2013 12:11 pm
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,
Re: biter spawner rate
Posted: Fri Nov 15, 2013 12:14 pm
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.
Re: biter spawner rate
Posted: Thu Nov 21, 2013 9:58 pm
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:

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]
Re: biter spawner rate
Posted: Fri Nov 22, 2013 10:29 am
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?
Re: biter spawner rate
Posted: Wed Nov 27, 2013 4:34 pm
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})
Re: biter spawner rate
Posted: Wed Nov 27, 2013 5:15 pm
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
Re: biter spawner rate
Posted: Wed Nov 27, 2013 6:37 pm
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

))
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
},
}
)
Re: biter spawner rate
Posted: Wed Nov 27, 2013 9:08 pm
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
Re: biter spawner rate
Posted: Thu Nov 28, 2013 8:23 am
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}
Re: biter spawner rate
Posted: Thu Nov 28, 2013 9:07 am
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.)
Re: biter spawner rate
Posted: Thu Nov 28, 2013 2:57 pm
by ficolas
Dammned phpbb with android.
Re: biter spawner rate
Posted: Mon Dec 02, 2013 11:11 am
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
Re: biter spawner rate
Posted: Mon Dec 02, 2013 1:24 pm
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
Re: biter spawner rate
Posted: Mon Dec 02, 2013 4:04 pm
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).