Page 1 of 1

How do I detect Spawner kill? - Solved

Posted: Fri Oct 09, 2015 1:46 am
by TheSAguy
Hi,

I'd like to implement a 'swarm' of nearby biters when a spawner is killed.
So upon death run the code:

Code: Select all

game.player.surface.set_multi_command({type=defines.command.attack,target=game.player.character,distraction=defines.distraction.by_enemy},10)
So is the an event - on spawner death or something?
The evolution factor increases on destroying a spawner, so there must be a way to detect it.

Also, where would I implement it?
Something like this:

Code: Select all

game.on_event(defines.events.[color=#FF0000]xxx[/color], function(event)
game.player.surface.set_multi_command({type=defines.command.attack,target=game.player.character,distraction=defines.distraction.by_enemy},10)
end)
Thanks.

Re: How do I detect Spawner kill?

Posted: Fri Oct 09, 2015 5:20 am
by Rseding91
You could make the death trigger of the entity spawn the enemies.

Or if you wanted to do it through the control.lua file: https://forums.factorio.com/wiki/inde ... ntity_died

Re: How do I detect Spawner kill?

Posted: Fri Oct 09, 2015 7:41 am
by Adil
Rseding91 wrote:You could make the death trigger of the entity spawn the enemies.
Can we use commands like set_multi_command in those?

Re: How do I detect Spawner kill?

Posted: Fri Oct 09, 2015 4:24 pm
by TheSAguy
It worked great on just adding it to the On_Remove function!

Code: Select all

function On_Remove(event)

	if event.entity.type == "unit-spawner" then
		writeDebug("YOU KILLED A SPAWNER")
		game.player.surface.set_multi_command({type=defines.command.attack,target=game.player.character,distraction=defines.distraction.by_enemy},(20+math.floor(game.evolution_factor*100)))
	end
	
end

Re: How do I detect Spawner kill?

Posted: Fri Oct 09, 2015 7:01 pm
by Rseding91
TheSAguy wrote:It worked great on just adding it to the On_Remove function!

Code: Select all

function On_Remove(event)

	if event.entity.type == "unit-spawner" then
		writeDebug("YOU KILLED A SPAWNER")
		game.player.surface.set_multi_command({type=defines.command.attack,target=game.player.character,distraction=defines.distraction.by_enemy},(20+math.floor(game.evolution_factor*100)))
	end
	
end
That won't work for multiplayer. Firstly game.player can't be used In multiplayer and secondly there's no guarantee that the entity spawner that died is on the same surface as the player.

What you want to do is use the surface of the event.entity.surface and then iterate the players on that surface and send them to attack those player (if any exist).

That is, unless you don't care about multiplayer support or surfaces support :)