Adding custom keystrokes through LUA

Post Reply
User avatar
Kenney
Member
Posts: 131
Joined: Fri Jan 02, 2015 12:12
In-game: Kenney

Adding custom keystrokes through LUA

by Kenney » Post

To add advanced functionality to mods adding custom keystrokes would be great. Bundling that together with pointing at nodes it could be used to give nodes more than 1 action (knocking on a door, opening/closing a door and locking/unlocking a door).

LUA example:

Code: Select all

minetest.register_key({
	key = 'C',
	function = do_c()
})
Games:
Voxus | UFO Race

TriBlade9
Member
Posts: 89
Joined: Fri Sep 05, 2014 09:35

Re: Adding custom keystrokes through LUA

by TriBlade9 » Post

I love the idea (and have wanted it for ages), but the problem is quite simply that everything runs on the server. A packet would have to be sent for every keypress, which is just nope.

*ahem*someone hurry up and write a system for client-side scripts*ahem*

TG-MyinaWD
Member
Posts: 356
Joined: Thu May 08, 2014 21:22
GitHub: Maddie-Myina
IRC: Maddie-Myina
In-game: .
Location: Far Eden

Re: Adding custom keystrokes through LUA

by TG-MyinaWD » Post

Yeah how about an Bind? like A mod allow players make binds, and it all can be saved in the player file or.. A %playername%_binds. But knocking on a door does sound interesting on Minetest. Specially for My Real Life subgame building one byte after another.

But anyway about the binding it maybe can be (well it will say in help) "/bind <key> <action/do>" and "/unbind <key>" to unbind it. that if all this is possible.

But I think we be cool see your Ideas Kenney come possible.
But be cool if we can add to an animation for knocking. and un/locking and open/close door. But how Sam Mine Swing his arm kinda looks like he is knocking.

But we do need more things to interact with the players and so on.

But all I know I think the knocking would be nice see.
I'm a Transgender no shame about it.
I prefer to be considered as a "Girl/Lady/Miss/Madam/Female" for now on.

Zeno
Member
Posts: 140
Joined: Sun Jun 29, 2014 03:36
GitHub: Zeno-
Location: Australia

Re: Adding custom keystrokes through LUA

by Zeno » Post

TriBlade9 wrote:I love the idea (and have wanted it for ages), but the problem is quite simply that everything runs on the server. A packet would have to be sent for every keypress, which is just nope.

*ahem*someone hurry up and write a system for client-side scripts*ahem*
I'm not positive that a packet would have to be sent for *every* keypress. I.e. the client could be told upon connection what a key is bound to and just send a packet if that key is pressed.

TriBlade9
Member
Posts: 89
Joined: Fri Sep 05, 2014 09:35

Re: Adding custom keystrokes through LUA

by TriBlade9 » Post

Hmm, that would be possible. However, what about keyup/keydown handlers?

thetoon
Member
Posts: 106
Joined: Tue Dec 11, 2012 12:55

Re: Adding custom keystrokes through LUA

by thetoon » Post

Zeno wrote:I'm not positive that a packet would have to be sent for *every* keypress. I.e. the client could be told upon connection what a key is bound to and just send a packet if that key is pressed.
It has to send on every keypress, as long as scripts are server-side only (IIRC, keypresses are sent no matter what, and server decides what to do with them).

User avatar
Calinou
Moderator
Posts: 3169
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

Re: Adding custom keystrokes through LUA

by Calinou » Post

Kenney wrote:LUA example:

Code: Select all

minetest.register_key({
	key = 'C',
	function = do_c()
})
This has two problems:
  • How do you handle keyboard layouts other than QWERTY?
  • How do you let the client change that key, especially if they already use that key for something like movement?
I would rather have more “special” keys (special2, special3, special4 would be a good start), which the client can configure.

thetoon
Member
Posts: 106
Joined: Tue Dec 11, 2012 12:55

Re: Adding custom keystrokes through LUA

by thetoon » Post

Calinou wrote: This has two problems:
  • How do you handle keyboard layouts other than QWERTY?
  • How do you let the client change that key, especially if they already use that key for something like movement?
I would rather have more “special” keys (special2, special3, special4 would be a good start), which the client can configure.
This is already a problem, isn't it? And every other game (not to mention engines) already looked into it : picking ideas from competitors could be helpful here.

IMHO, client code should only send "actions" ("left", "right", "jump", "blahblah") and let the server decide what to do with it. The key/action mapping should be completely client side (it is already, I guess).

User avatar
Kalabasa
Member
Posts: 37
Joined: Tue Jan 06, 2015 17:36
GitHub: Kalabasa
IRC: Kalabasa
In-game: Kalabasa

Re: Adding custom keystrokes through LUA

by Kalabasa » Post

Well then,

Code: Select all

minetest.register_action("mymod:myaction", function(player)
  -- Example callback
  --   player = player who sent the action
  kill_player(player)
end)

-- This binding is sent to the client
minetest.register_keybind("mymod:myaction", {
  default_key = "X",
  description = "Suicide"
})
On connect, the server sends all custom keybindings to the client (all registered keybinds). The client then adds those to the "Change Keys" screen.

I don't know how keys currently work though, so this may be a trivial or a huge change.
insert signature here

Zeno
Member
Posts: 140
Joined: Sun Jun 29, 2014 03:36
GitHub: Zeno-
Location: Australia

Re: Adding custom keystrokes through LUA

by Zeno » Post

thetoon wrote:
Zeno wrote:I'm not positive that a packet would have to be sent for *every* keypress. I.e. the client could be told upon connection what a key is bound to and just send a packet if that key is pressed.
It has to send on every keypress, as long as scripts are server-side only (IIRC, keypresses are sent no matter what, and server decides what to do with them).
I wasn't talking about scripts (not really anyway). I was suggesting that if a server-side script created a custom key binding then that binding be sent to the client as part of the connection negotiation. This has several roadblocks, but it does not mean that every key press would need to be sent to the server.
(IIRC, keypresses are sent no matter what, and server decides what to do with them).
Currently key presses are not sent to the server at all (the key press in the client is converted into a directive if it's relevant). Why would the server need to know about key presses in the client?

spillz
Member
Posts: 138
Joined: Thu Feb 13, 2014 05:11

Re: Adding custom keystrokes through LUA

by spillz » Post

I dabbled with making keyboard shortcuts for chat commands here:

https://github.com/minetest/minetest/pull/1217

If it ever got accepted I was going to come up with a system for letting mods send default shortcuts to clients.
Last edited by spillz on Mon Jan 19, 2015 12:36, edited 1 time in total.

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Adding custom keystrokes through LUA

by rubenwardy » Post

Please rebase it to the current master - without including all the upstream commits. I reckon it would be commited.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Gearhart
Member
Posts: 15
Joined: Wed May 23, 2018 13:40
IRC: Souleater
In-game: Souleater

Re: Adding custom keystrokes through LUA

by Gearhart » Post

so im lost how do i get a a key press to mess with the player physics

it keeps saying "attempt to call field 'register_action' (a nil value)"

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: Adding custom keystrokes through LUA

by Pyrollo » Post

Gearhart wrote:so im lost how do i get a a key press to mess with the player physics

it keeps saying "attempt to call field 'register_action' (a nil value)"
It seems that this "register_action" method had not been implemented finaly.

Please refer to lua_api.txt for implemented methods.
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests