Page 1 of 1

click event

Posted: Fri Mar 24, 2017 9:33 pm
by Bizobinator
Is there an event that fires whenever a player clicks? Or, even better, when a player clicks with a given item in their selection hand?

Re: click event

Posted: Fri Mar 24, 2017 9:50 pm
by SilverB1rd
if you look in the factorio documentation for the defines.events
/Factorio/doc-html/defines.html#defines.events
it does not list an event specifically for clicks.

if your trying to capture the player building something there is

defines.events.on_built_entity
defines.events.on_put_item

Re: click event

Posted: Fri Mar 24, 2017 10:46 pm
by Rseding91
Factorio doesn't generate events for clicks that do nothing as that wastes CPU time and would increase the network load in multplayer.

Only events that actually trigger some game action are processed and result in some event being fired.

Re: click event

Posted: Sat Mar 25, 2017 12:06 am
by Supercheese
Bizobinator wrote:Is there an event that fires whenever a player clicks?
Nope, there is no event for this.
Bizobinator wrote:Or, even better, when a player clicks with a given item in their selection hand?
There is, however, an event for this: http://lua-api.factorio.com/latest/even ... n_put_item

Re: click event

Posted: Sun Mar 26, 2017 6:46 pm
by Bizobinator
Supercheese wrote:
Bizobinator wrote:Is there an event that fires whenever a player clicks?
Nope, there is no event for this.
Bizobinator wrote:Or, even better, when a player clicks with a given item in their selection hand?
There is, however, an event for this: http://lua-api.factorio.com/latest/even ... n_put_item

Yeah. I've read a bit of the code in a different mod. So, with that event, is it possible to, in between the starting to place & the entity being created, to have some code that stops the entity placement (& thus keeps the item in hand)?

Re: click event

Posted: Sun Mar 26, 2017 7:08 pm
by Supercheese
Bizobinator wrote:Yeah. I've read a bit of the code in a different mod. So, with that event, is it possible to, in between the starting to place & the entity being created, to have some code that stops the entity placement (& thus keeps the item in hand)?
Yes: https://github.com/Suprcheese/Orbital-I ... #L386-L397

Re: click event

Posted: Mon Mar 27, 2017 7:14 pm
by Bizobinator
Supercheese wrote:
Bizobinator wrote:Yeah. I've read a bit of the code in a different mod. So, with that event, is it possible to, in between the starting to place & the entity being created, to have some code that stops the entity placement (& thus keeps the item in hand)?
Yes: https://github.com/Suprcheese/Orbital-I ... #L386-L397
Excellent! Yay!

Supercheese, do you mind if I use your code for playing a sound too?

Hehehehehe, you have no idea what you've just unleashed xD

Re: click event

Posted: Mon Mar 27, 2017 8:25 pm
by Supercheese
Bizobinator wrote:Excellent! Yay!

Supercheese, do you mind if I use your code for playing a sound too?

Hehehehehe, you have no idea what you've just unleashed xD
Sure, go for it! I'm always happy to see folks get inspired and launch into Factorio modding. :)