Sneak to dismount when in boat

This commit is contained in:
Elias Fleckenstein 2021-01-28 17:44:55 +01:00
parent a3ccb54376
commit 89ce072621
3 changed files with 74 additions and 62 deletions

View File

@ -70,39 +70,31 @@ end
minetest.register_on_respawnplayer(detach_player)
function boat.on_rightclick(self, clicker)
if not clicker or not clicker:is_player() then
if self._driver or not clicker or not clicker:is_player() or clicker:get_attach() then
return
end
local name = clicker:get_player_name()
if self._driver and clicker == self._driver then
self._driver = nil
detach_player(clicker)
local pos = clicker:get_pos()
pos = {x = pos.x, y = pos.y + 0.2, z = pos.z}
clicker:set_pos(pos)
elseif not self._driver then
local attach = clicker:get_attach()
if attach and attach:get_luaentity() then
local luaentity = attach:get_luaentity()
if luaentity._driver then
luaentity._driver = nil
end
clicker:set_detach()
clicker:set_properties({visual_size = {x=1, y=1}})
--[[if attach and attach:get_luaentity() then
local luaentity = attach:get_luaentity()
if luaentity._driver then
luaentity._driver = nil
end
self._driver = clicker
clicker:set_attach(self.object, "",
{x = 0, y = 0.42, z = -1}, {x = 0, y = 0, z = 0})
clicker:set_properties({ visual_size = driver_visual_size })
mcl_player.player_attached[name] = true
minetest.after(0.2, function(name)
local player = minetest.get_player_by_name(name)
if player then
mcl_player.player_set_animation(player, "sit" , 30)
end
end, name)
clicker:set_look_horizontal(self.object:get_yaw())
end
clicker:set_detach()
clicker:set_properties({visual_size = {x=1, y=1}})
end--]]
self._driver = clicker
clicker:set_attach(self.object, "",
{x = 0, y = 0.42, z = -1}, {x = 0, y = 0, z = 0})
clicker:set_properties({ visual_size = driver_visual_size })
mcl_player.player_attached[name] = true
minetest.after(0.2, function(name)
local player = minetest.get_player_by_name(name)
if player then
mcl_player.player_set_animation(player, "sit" , 30)
end
end, name)
clicker:set_look_horizontal(self.object:get_yaw())
mcl_tmp_message.message(clicker, S("Sneak to dismount"))
end
@ -162,6 +154,14 @@ function boat.on_step(self, dtime)
if self._driver then
local ctrl = self._driver:get_player_control()
if ctrl.sneak then
detach_player(self._driver)
local pos = self._driver:get_pos()
pos = {x = pos.x, y = pos.y + 0.2, z = pos.z}
self._driver:set_pos(pos)
self._driver = nil
return
end
local yaw = self.object:get_yaw()
if ctrl.up then
-- Forwards

View File

@ -0,0 +1,44 @@
mcl_tmp_message = {}
local huds = {}
local hud_hide_timeouts = {}
function mcl_tmp_message.message(player, message)
local name = player:get_player_name()
player:hud_change(huds[name], "text", message)
hud_hide_timeouts[name] = 3
end
minetest.register_on_joinplayer(function(player)
huds[player:get_player_name()] = player:hud_add({
hud_elem_type = "text",
position = {x=0.5, y=1},
offset = {x = 0, y = -210},
alignment = {x=0, y=0},
number = 0xFFFFFF ,
text = "",
z_index = 100,
})
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
huds[name] = nil
hud_hide_timeouts[name] = nil
end)
minetest.register_globalstep(function(dtime)
local new_timeouts = {}
for name, timeout in pairs(hud_hide_timeouts) do
timeout = timeout - dtime
if timeout <= 0 then
local player = minetest.get_player_by_name(name)
if player then
player:hud_change(huds[name], "text", "")
end
else
new_timeouts[name] = timeout
end
end
hud_hide_timeouts = new_timeouts
end)

View File

@ -6,8 +6,6 @@ local player_in_bed = 0
local is_sp = minetest.is_singleplayer()
local weather_mod = minetest.get_modpath("mcl_weather") ~= nil
local explosions_mod = minetest.get_modpath("mcl_explosions") ~= nil
local huds = {}
local hud_hide_timeouts = {}
-- Helper functions
@ -326,8 +324,7 @@ function mcl_beds.on_rightclick(pos, player, is_top)
success, message = lay_down(player, ppos, other)
end
if message then
player:hud_change(huds[name], "text", message)
hud_hide_timeouts[name] = 3
mcl_tmp_message.message(player, message)
end
else
lay_down(player, nil, nil, false)
@ -355,25 +352,12 @@ minetest.register_on_joinplayer(function(player)
meta:set_string("mcl_beds:sleeping", "false")
end
huds[player:get_player_name()] = player:hud_add({
hud_elem_type = "text",
position = {x=0.5, y=1},
offset = {x = 0, y = -210},
alignment = {x=0, y=0},
number = 0xFFFFFF ,
text = "",
z_index = 100,
})
playerphysics.remove_physics_factor(player, "speed", "mcl_beds:sleeping")
playerphysics.remove_physics_factor(player, "jump", "mcl_beds:sleeping")
update_formspecs(false)
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
huds[name] = nil
local players = minetest.get_connected_players()
for n, player in ipairs(players) do
if player:get_player_name() == name then
@ -412,19 +396,3 @@ minetest.register_on_player_hpchange(function(player, hp_change)
mcl_beds.kick_player(player)
end
end)
minetest.register_globalstep(function(dtime)
local new_timeouts = {}
for name, timeout in pairs(hud_hide_timeouts) do
timeout = timeout - dtime
if timeout <= 0 then
local player = minetest.get_player_by_name(name)
if player then
player:hud_change(huds[name], "text", "")
end
else
new_timeouts[name] = timeout
end
end
hud_hide_timeouts = new_timeouts
end)