Page 1 of 1

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

PostPosted: Tue Sep 17, 2013 16:17
by webdesigner97
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

PostPosted: Tue Sep 17, 2013 16:24
by Evergreen
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.

PostPosted: Wed Sep 18, 2013 08:17
by rubenwardy
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.

PostPosted: Wed Sep 18, 2013 09:33
by jojoa1997
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.

PostPosted: Wed Sep 18, 2013 15:56
by webdesigner97
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?

PostPosted: Thu Sep 19, 2013 08:00
by rubenwardy
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

PostPosted: Thu Sep 19, 2013 08:04
by rubenwardy
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.

PostPosted: Thu Sep 19, 2013 12:28
by webdesigner97
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...