require "util" require "defines" require ("config") --------------------------------------------- function Load_Me() if game.forces['vampire'] == nil then game.create_force('vampire') writeDebug("Vampire force created") --game.forces['vampire'].set_cease_fire('enemy', false) --game.forces['vampire'].set_cease_fire('player', false) end end --------------------------------------------- script.on_event({defines.events.on_entity_died,},function(event) On_Remove(event) end) --------------------------------------------- function On_Remove(event) -- When a small biter gets killed. if event.entity.name == "small-biter" then --writeDebug("a small-biter died") local surface = game.get_surface(0) local radius = 1 local pos = event.entity.position local area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}} -- find nearby Vampire biters local V_Biters = surface.find_entities_filtered{area=area, name="small-vampire"} --local V_Biters = surface.find_enemy_units(pos, radius, vampire) -- Alternative possibility? --local V_Biter = surface.find_entities_filtered{area=area, force="vampire"} -- Alternative possibility? if V_Biters then player.surface.create_entity{name="small-vampire", position={pos}, force=game.forces.vampire} -- player.surface.create_entity{name="small-vampire", position={PosX,PosY}, force=game.forces.vampire} -- Alternative possibility? --SpawnVampire(event.entity) end end end function SpawnVampire(enemy) local SpawnPosition = enemy.surface.find_non_colliding_position(enemy, enemy.position, 2, 0.5) if SpawnPosition then --writeDebug("Valid position found") enemy.surface.create_entity({name = "small-vampire", position = SpawnPosition, force = game.forces.enemy}) end end --------------------------------------------- script.on_init(Load_Me) script.on_configuration_changed(Load_Me) --------------------------------------------- --- DeBug Messages QCCode = true function writeDebug(message) if QCCode then for i, player in ipairs(game.players) do player.print(tostring(message)) end end end