Page 1 of 1

Delete items on biters death

Posted: Mon Dec 29, 2014 11:51 am
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.

Re: Delete items on biters death

Posted: Mon Dec 29, 2014 12:23 pm
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...

Re: Delete items on biters death

Posted: Mon Dec 29, 2014 6:58 pm
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

Re: Delete items on biters death

Posted: Thu Jan 01, 2015 11:41 am
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)