Custom keys for mods: minetest.register_on_keydown(player,key)

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

Custom keys for mods: minetest.register_on_keydown(player,key)

by webdesigner97 » Tue Sep 17, 2013 16:17

What about allowing mods to check wheter keys are pressed which aren't included to get_player_controls? This would allow e.g. a car mod to change gears or something like this. How it could look like

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_on_keydown(player,key)
  if key == "esc" then
    minetest.chat_send_player(player:get_player_name(),"You pressed ESC!");
  end
end

or
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
local ctrl = player:get_player_controls()
if ctrl.esc then
  minetest.chat_send_player(player:get_player_name(),"You pressed ESC!");
end
 

User avatar
Evergreen
Member
 
Posts: 2131
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

by Evergreen » Tue Sep 17, 2013 16:24

webdesigner97 wrote:What about allowing mods to check wheter keys are pressed which aren't included to get_player_controls? This would allow e.g. a car mod to change gears or something like this. How it could look like

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_on_keydown(player,key)
  if key == "esc" then
    minetest.chat_send_player(player:get_player_name(),"You pressed ESC!");
  end
end

or
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
local ctrl = player:get_player_controls()
if ctrl.esc then
  minetest.chat_send_player(player:get_player_name(),"You pressed ESC!");
end
That would be so useful.
"Help! I searched for a mod but I couldn't find it!"
http://krock-works.16mb.com/MTstuff/modSearch.php
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

by rubenwardy » Wed Sep 18, 2013 08:17

This would introduce lag, and so would be better if it ran on the client. Current key presses work this way, with the client controlling the player's movement.

This could be added as a quick way, but I recommend that it works more llike this:

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_on_keydown("e",function(player)

end)


So the player only sends the keydown when it needs too.
"e" can be a list, and function can contain key with the key id.
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11

by jojoa1997 » Wed Sep 18, 2013 09:33

rubenwardy wrote:This would introduce lag, and so would be better if it ran on the client. Current key presses work this way, with the client controlling the player's movement.

This could be added as a quick way, but I recommend that it works more llike this:

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_on_keydown("e",function(player)

end)


So the player only sends the keydown when it needs too.
"e" can be a list, and function can contain key with the key id.
Yes but if everything is client then you cant mod with any cool features. Just like the fov.
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Wed Sep 18, 2013 15:56

rubenwardy wrote:This would introduce lag, and so would be better if it ran on the client. Current key presses work this way, with the client controlling the player's movement.

This could be added as a quick way, but I recommend that it works more llike this:

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_on_keydown("e",function(player)

end)


So the player only sends the keydown when it needs too.
"e" can be a list, and function can contain key with the key id.

Ah, es. Thi way seems to be better. But why would it cause lag?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

by rubenwardy » Thu Sep 19, 2013 08:00

jojoa1997 wrote:
rubenwardy wrote:This would introduce lag, and so would be better if it ran on the client. Current key presses work this way, with the client controlling the player's movement.

This could be added as a quick way, but I recommend that it works more llike this:

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_on_keydown("e",function(player)

end)


So the player only sends the keydown when it needs too.
"e" can be a list, and function can contain key with the key id.
Yes but if everything is client then you cant mod with any cool features. Just like the fov.


Client API
Last edited by rubenwardy on Thu Sep 19, 2013 08:00, 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

by rubenwardy » Thu Sep 19, 2013 08:04

webdesigner97 wrote:Ah, es. This way seems to be better. But why would it cause lag?


There is time between when the player presses the key, and when the server receives the player press.

With the other method, all key presses would be sent which is a lot of key presses.
Last edited by rubenwardy on Thu Sep 19, 2013 08:05, edited 1 time in total.
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Thu Sep 19, 2013 12:28

rubenwardy wrote:
webdesigner97 wrote:Ah, es. This way seems to be better. But why would it cause lag?


There is time between when the player presses the key, and when the server receives the player press.

With the other method, all key presses would be sent which is a lot of key presses.

AH, this is what you mean! So this really needs client-side code execution...
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 16 guests

cron