Adding custom keystrokes through LUA

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

Adding custom keystrokes through LUA

by Kenney » Thu Jan 15, 2015 01:44

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:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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 » Thu Jan 15, 2015 04:10

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*
 

User avatar
TG-MyinaWD
Member
 
Posts: 355
Joined: Thu May 08, 2014 21:22
GitHub: Maddie-Myina
IRC: Maddie-Myina
In-game: .

Re: Adding custom keystrokes through LUA

by TG-MyinaWD » Thu Jan 15, 2015 04:36

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-

Re: Adding custom keystrokes through LUA

by Zeno » Thu Jan 15, 2015 05:52

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 » Thu Jan 15, 2015 14:47

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 » Thu Jan 15, 2015 15:07

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
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

Re: Adding custom keystrokes through LUA

by Calinou » Thu Jan 15, 2015 16:05

Kenney wrote:LUA example:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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 » Thu Jan 15, 2015 16:08

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: 34
Joined: Tue Jan 06, 2015 17:36
GitHub: Kalabasa
IRC: Kalabasa
In-game: Kalabasa

Re: Adding custom keystrokes through LUA

by Kalabasa » Sat Jan 17, 2015 08:10

Well then,
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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-

Re: Adding custom keystrokes through LUA

by Zeno » Sat Jan 17, 2015 13:00

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 » Mon Jan 19, 2015 02:53

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
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Adding custom keystrokes through LUA

by rubenwardy » Mon Jan 19, 2015 07:49

Please rebase it to the current master - without including all the upstream commits. I reckon it would be commited.
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 5 guests

cron