Page 1 of 1

Event Requests

Posted: Tue Sep 09, 2014 7:02 am
by Chronicles
Would like to have some event calls :

onmineditem - called when a mining drill or pumpjack mines something. returns item/entity
oncrafteditem - called when a assembly machine / furnace creates an entity. returns item/entity
onuseditem - similar to onputitem, but called by an assembly machine / furnace instead of player.

Re: Event Requests

Posted: Fri Jan 09, 2015 7:57 pm
by Adil
It's been a while since tread has begun, but I guess the suggestion is still worth a thought.
And I guess I'll just put suggestion for another couple of events here as well:
onvehicleentered
onvehicleexit
these should rise when player enters/exits vehicle. Because

Code: Select all

game.onevent(defines.events.ontick, function(event)
  if game.player.character and game.player.character.vehicle and game.player.character.vehicle.name == "bomber"...
doesn't feel right.

Re: Event Requests

Posted: Wed Jan 28, 2015 8:44 am
by Choumiko
Adil wrote:Because

Code: Select all

game.onevent(defines.events.ontick, function(event)
  if game.player.character and game.player.character.vehicle and game.player.character.vehicle.name == "bomber"...
doesn't feel right.
That's right :D Neither does

Code: Select all

for pi, player in ipairs(game.players) do
      if player.opened ~= nil and player.opened.valid then
        if player.opened.type == "locomotive" and player.opened.train ~= nil then
           ....
        elseif player.opened.type == "train-stop"
          ....
       end
     end
end
so i would propose
onguiopened()
onguiclosed()
returning playerindex and the entity whose gui was opened/closed

Re: Event Requests

Posted: Wed Jan 28, 2015 11:04 am
by ThaPear
I'd like to request onentitydamaged. It would be passed the entity in question, the damage dealt and the instigator.
It could even be allowed to return whether or not to actually apply the damage.

Example usage:

Code: Select all

function onentitydamaged(target, damage, instigator)
	if instigator == game.player then
		if target.force == game.player.force then
			return false -- Do not apply damage.
		end
	end
	return true
end
It might even allow us to return the amount of damage to apply, allowing us to mitigate the damage:

Code: Select all

function onentitydamaged(target, damage, instigator)
	if instigator == game.player then
		if target.force == game.player.force then
			return damage/10 -- Only apply 10% damage.
		end
	end
	return damage
end

Re: Event Requests

Posted: Sun Feb 08, 2015 8:38 am
by morphman
Chronicles wrote:oncrafteditem - called when a assembly machine / furnace creates an entity. returns item/entity
For that you could call the Entity.getoutputinventory on the furnace/assembly to check for updates. If an item appears in the output inventory without one having been taken, then it has crafted one item.
Chronicles wrote:onuseditem - similar to onputitem, but called by an assembly machine / furnace instead of player.
Similar, but instead check the Entity.getinventory and instead of checking if something is added without being taken away, just check if something has been taken away without new things being added.

There are probably better ways to handle both, but you get an inventory as result from both to play around with and do pretty much whatever you want with.

Check the Wikipage for Lua/Entity for more info.