master
DS-Minetest 2019-08-14 15:49:43 +02:00
commit c704ac4460
2 changed files with 53 additions and 0 deletions

52
init.lua Normal file
View File

@ -0,0 +1,52 @@
-- nil: player is not on ground and did already jump
-- 1: player is on ground
-- 2: currently normal jump; dj on next button press
-- 3: player can on next jump press
local can_player_dj = {}
local function try_doublejump(player, is_on_ground)
if is_on_ground and (can_player_dj[player] == nil or can_player_dj[player] == 3) then
can_player_dj[player] = 1
end
if not player:get_player_control().jump then
if can_player_dj[player] == 2 then
-- normal jump button press stops
can_player_dj[player] = 3
end
return
elseif can_player_dj[player] == 1 then
-- normal jump starts
can_player_dj[player] = 2
end
if can_player_dj[player] ~= 3 then
return
end
local vel_y = player:get_player_velocity().y
vel_y = math.min(vel_y, 0)
player:add_player_velocity({x = 0, y = 6.5 - vel_y, z = 0})
can_player_dj[player] = nil
end
minetest.register_globalstep(function(_)
local players = minetest.get_connected_players()
for _, player in pairs(players) do
-- check if player is on ground
local is_on_ground = false
if player:get_player_velocity().y == 0 then
local pos = player:get_pos()
pos.y = math.ceil(pos.y - 0.5)
local nodedef = minetest.registered_nodes[minetest.get_node(pos).name]
if nodedef and nodedef.walkable then
is_on_ground = true
end
end
try_doublejump(player, is_on_ground)
--~ minetest.chat_send_all(can_player_dj[player] or 0)
end
end)

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name=doublejump