How do I detect Spawner kill? - Solved

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1455
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

How do I detect Spawner kill? - Solved

Post 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.
Last edited by TheSAguy on Fri Oct 09, 2015 4:24 pm, edited 1 time in total.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15881
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: How do I detect Spawner kill?

Post 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
If you want to get ahold of me I'm almost always on Discord.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: How do I detect Spawner kill?

Post 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?
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1455
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: How do I detect Spawner kill?

Post 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
Rseding91
Factorio Staff
Factorio Staff
Posts: 15881
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: How do I detect Spawner kill?

Post 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 :)
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding help”