LuaPlayer:current_inputs [R]
Posted: Mon Nov 18, 2019 1:33 am
Something I have been thinking about is a way to detect when a player quits dragging something. For example, in Even Distribution, the mod just waits a certain amount of time after the last entity was highlighted to execute the distribution. It would be much more intuitive and nice if it distributed when you stopped holding down the mouse.
So, here's my suggestion: Since straight-up drag support has been rejected in the past, I propose that a current_inputs class be added to LuaPlayer. This would simply be an array of all of the inputs that are currently being used by that player during that tick. They would use the same syntax as one would use when defining a custom input. For example, it might return {'mouse-button-2', 'CONTROL', 'A', 'W'}.
In the case of even distribution, the usecase would be this: The mod detects when someone starts an even distribution, then registers a conditional on_tick event to read the current_inputs table. When the on_tick no longer sees that CONTROL and mouse-button-2 are being held down, it knows that the player has stopped dragging and distributes the items, then deregisters itself.
This is merely one usecase, I'm sure modders out there could find many uses for something like this. Thanks!
So, here's my suggestion: Since straight-up drag support has been rejected in the past, I propose that a current_inputs class be added to LuaPlayer. This would simply be an array of all of the inputs that are currently being used by that player during that tick. They would use the same syntax as one would use when defining a custom input. For example, it might return {'mouse-button-2', 'CONTROL', 'A', 'W'}.
In the case of even distribution, the usecase would be this: The mod detects when someone starts an even distribution, then registers a conditional on_tick event to read the current_inputs table. When the on_tick no longer sees that CONTROL and mouse-button-2 are being held down, it knows that the player has stopped dragging and distributes the items, then deregisters itself.
This is merely one usecase, I'm sure modders out there could find many uses for something like this. Thanks!