12 --make the data from get_key_pressed usable
13 --Thanks Thou shalt use my mods!
14 function minetest.get_control_bits(player)
15 local input = player:get_key_pressed()
16 local input_table = {}
17 --iterate through the table using the highest value first
18 local keys = {"rightclick","leftclick","sneak","aux","jump","right","left","down","up"}
19 for index,data in pairs(keys) do
20 local modifier = math.pow(2, 9-index)
21 if input >= modifier then
22 input_table[data] = true
23 input = input - modifier
25 input_table[data] = false
33 --set up our initial values
35 local run_discharge_timer = 0
38 local old_sneak = false
39 local bunny_hop = false
41 --attempt to tell the server to allow us to run
42 local send_server_movement_state = function(state)
43 player_movement_state:send_all(state)
46 --receive the server states
47 minetest.register_on_modchannel_message(function(channel_name, sender, message)
48 if channel_name == "player.player_movement_state" then
53 --check player's input on the "up" key
54 minetest.register_globalstep(function(dtime)
55 if not minetest.localplayer then
59 local input = minetest.get_control_bits(minetest.localplayer)
60 local vel = minetest.localplayer:get_velocity().y
61 local oldvel = minetest.localplayer:get_last_velocity().y
64 if running == true and (input.up == false or input.sneak == true or input.down == true) then
67 send_server_movement_state("0")
70 --add this here so the player can sneak
71 if input.sneak == true then
75 --stop bunnyhopping on land
76 if bunny_hop == true and vel == 0 and oldvel < 0 then
80 --check if need to tell server to bunnyhop
81 if running == true and vel > 0 and input.jump == true and bunny_hop == false then
82 send_server_movement_state("2")
84 elseif bunny_hop == false then
85 if running == true then
86 send_server_movement_state("1")
88 elseif sneak == true then
89 send_server_movement_state("3")
92 send_server_movement_state("0")
100 if sneak == true and old_sneak == false then
101 send_server_movement_state("3")
102 elseif input.sneak == false and old_sneak == true then
104 send_server_movement_state("0")
107 --half second window to double tap running
108 if run_discharge_timer > 0 then
109 run_discharge_timer = run_discharge_timer - dtime
110 if run_discharge_timer <= 0 then
111 run_discharge_timer = 0
113 --initialize double tap run
114 if old_up == false and input.up == true then
115 run_discharge_timer = 0
117 --print("running toggle on")
118 send_server_movement_state("1")
121 --check if new input of walking forwards
122 if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
123 run_discharge_timer = 0.2
127 old_sneak = input.sneak