Delete items on biters death

Place to get help with not working mods / modding interface.
kasper747
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Jul 04, 2014 4:12 pm
Contact:

Delete items on biters death

Post by kasper747 »

Hi, I have an idea for a mod and I would like to scout if it is technical possible.

What I want to do is to pay for the kill of each biter or nest. Money can be items or some virtual numbers.

Money as an item:
When a biter is killed an amount of money-items is deleted.

Money as virtual number:
When a biter is killed the virtual number will be reduced.

As money making:
Items from a factory
Virtual number increasing when factory is running

What do you think, how can it be implemented? Or maybe there are some parts from other modes to reuse. Or an other way to do this.
kasper747
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Jul 04, 2014 4:12 pm
Contact:

Re: Delete items on biters death

Post by kasper747 »

Found so far this event: onentitydied.
Cause there is only one primer cause of death for biters I think it will be enough to check if a biter was killed.

Still looking who to delete an time/items on at this event... Would be cool if someone had an example with onentitydied...
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: Delete items on biters death

Post by L0771 »

Code: Select all

game.onevent(defines.events.onentitydied, function(event)
	elseif event.entity.force.name == "enemy" then
		local cant = math.floor(event.entity.prototype.maxhealth * 0.1) -- math.floor round the number from 0 to 0.9 is 0.
		if cant > 0 then
			game.player.insert({name="money",count=cant})
		end
	end
end)
... I don't tested this, but this should work, try to use other than event.entity.prototype
kasper747
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Jul 04, 2014 4:12 pm
Contact:

Re: Delete items on biters death

Post by kasper747 »

I used this as test and it works! Thanks you

Code: Select all

game.onevent(defines.events.onentitydied, function(event)
  
   
game.onevent(defines.events.onentitydied, function(event)
  
   
   --game.showmessagedialog{text = {"msg-someone-dead"}}
   if event.entity.type == "unit" then
		game.player.insert({name="iron-ore",count=1})
		--player.character.insert ({name="iron-ore",count=1})
		game.player.print({"msg-bist-dead"})
   else
		game.player.print({"msg-someone-dead"})
   end
end)
Post Reply

Return to “Modding help”