1 local minetest,name = minetest,minetest.localplayer:get_name()
2 local player_movement_state = minetest.mod_channel_join(name..":player_movement_state")
5 --set up our initial values
9 local run_discharge_timer = 0
12 local old_sneak = false
13 local bunny_hop = false
14 local old_bunny_hop = false
18 --attempt to tell the server to allow us to run
19 local send_server_movement_state = function(state)
20 player_movement_state:send_all(state)
24 --receive the server states
25 minetest.register_on_modchannel_message(function(channel_name, sender, message)
26 if sender == "" and channel_name == name..":player_movement_state" then
27 local message_table = minetest.deserialize(message)
29 if message.stop_running then
32 run_discharge_timer = 0
38 --check player's input on the "up" key
39 minetest.register_globalstep(function(dtime)
41 if not minetest.localplayer then
45 local input = minetest.localplayer:get_control()
46 local vel = minetest.localplayer:get_velocity()
47 local oldvel = minetest.localplayer:get_last_velocity()
49 --cancel running if the player bumps into something
50 if running == true and ((vel.x == 0 and oldvel.x ~= 0) or (vel.z == 0 and oldvel.z ~= 0)) then
53 run_discharge_timer = 0
58 if running == true and (input.up == false or input.sneak == true or input.down == true) then
65 --check if need to tell server to bunnyhop
66 if running == true and vel.y > 0 and input.jump == true and bunny_hop == false then
72 if bunny_hop == true and input.jump == false and running == true and vel.y == 0 then
78 --half second window to double tap running
79 if run_discharge_timer > 0 then
80 run_discharge_timer = run_discharge_timer - dtime
81 if run_discharge_timer <= 0 then
82 run_discharge_timer = 0
84 --initialize double tap run
85 if old_up == false and input.up == true and vel.x ~= 0 and vel.z ~= 0 then
86 run_discharge_timer = 0
93 --check if new input of walking forwards
94 if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
95 run_discharge_timer = 0.2
98 --add this here so the player can sneak
99 if input.sneak == true then
100 run_discharge_timer = 0
107 --set the sneak state
108 if sneak == true and old_sneak == false then
110 elseif input.sneak == false and old_sneak == true then
115 --only send if state has changed
116 if state ~= old_state then
117 send_server_movement_state(tostring(state))
122 old_sneak = input.sneak
123 old_bunny_hop = bunny_hop