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
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
58 local input = minetest.get_control_bits(minetest.localplayer)
59 local vel = minetest.localplayer:get_velocity().y
60 local oldvel = minetest.localplayer:get_last_velocity().y
63 if running == true and (input.up == false or input.sneak == true or input.down == true) then
66 send_server_movement_state("0")
69 --add this here so the player can sneak
70 if input.sneak == true then
74 --stop bunnyhopping on land
75 if bunny_hop == true and vel == 0 and oldvel < 0 then
79 --check if need to tell server to bunnyhop
80 if running == true and vel > 0 and input.jump == true and bunny_hop == false then
81 send_server_movement_state("2")
83 elseif bunny_hop == false then
84 if running == true then
85 send_server_movement_state("1")
87 elseif sneak == true then
88 send_server_movement_state("3")
91 send_server_movement_state("0")
99 if sneak == true and old_sneak == false then
100 send_server_movement_state("3")
101 elseif input.sneak == false and old_sneak == true then
103 send_server_movement_state("0")
106 --half second window to double tap running
107 if run_discharge_timer > 0 then
108 run_discharge_timer = run_discharge_timer - dtime
109 if run_discharge_timer <= 0 then
110 run_discharge_timer = 0
112 --initialize double tap run
113 if old_up == false and input.up == true then
114 run_discharge_timer = 0
116 --print("running toggle on")
117 send_server_movement_state("1")
120 --check if new input of walking forwards
121 if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
122 run_discharge_timer = 0.2
126 old_sneak = input.sneak