How to determine if the player has been killed?

Place to get help with not working mods / modding interface.
FatApe
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Dec 15, 2014 9:33 am
Contact:

How to determine if the player has been killed?

Post by FatApe »

I am trying to make my mod do something when the player dies. I tried using the onentitydied event but that is called every time any entity dies. How do I check if just the player has died. Thanks.
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: How to determine if the player has been killed?

Post by L0771 »

is with onentitydied, but you can't know who player has die.
I use a code like this, if a entity die, asks what player is dead, on this save a var with the dead player

Code: Select all

game.onevent(defines.events.onentitydied, function(event)
	if event.entity.type == "player" then
		local player
		for _,vplayer in ipairs(game.players) do
			if v.character == nil and glob.dead[vplayer.name] == nil then
				player = v
			end
		end
		if player ~= nil then
			glob.dead[player.name] = true
				-- code
		end
	end
end)
Is an example je
With this can know what player is dead, for multiplayer, and if have a mod who adds entities type player NPC.

onplayerdied doesn't exist.
FatApe
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Dec 15, 2014 9:33 am
Contact:

Re: How to determine if the player has been killed?

Post by FatApe »

Thank you very much!
Post Reply

Return to “Modding help”