forked from VoxeLibre/VoxeLibre
Sneak to dismount when in boat
This commit is contained in:
parent
a3ccb54376
commit
89ce072621
|
@ -70,26 +70,18 @@ end
|
||||||
minetest.register_on_respawnplayer(detach_player)
|
minetest.register_on_respawnplayer(detach_player)
|
||||||
|
|
||||||
function boat.on_rightclick(self, clicker)
|
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
|
return
|
||||||
end
|
end
|
||||||
local name = clicker:get_player_name()
|
local name = clicker:get_player_name()
|
||||||
if self._driver and clicker == self._driver then
|
--[[if attach and attach:get_luaentity() 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()
|
local luaentity = attach:get_luaentity()
|
||||||
if luaentity._driver then
|
if luaentity._driver then
|
||||||
luaentity._driver = nil
|
luaentity._driver = nil
|
||||||
end
|
end
|
||||||
clicker:set_detach()
|
clicker:set_detach()
|
||||||
clicker:set_properties({visual_size = {x=1, y=1}})
|
clicker:set_properties({visual_size = {x=1, y=1}})
|
||||||
end
|
end--]]
|
||||||
self._driver = clicker
|
self._driver = clicker
|
||||||
clicker:set_attach(self.object, "",
|
clicker:set_attach(self.object, "",
|
||||||
{x = 0, y = 0.42, z = -1}, {x = 0, y = 0, z = 0})
|
{x = 0, y = 0.42, z = -1}, {x = 0, y = 0, z = 0})
|
||||||
|
@ -102,7 +94,7 @@ function boat.on_rightclick(self, clicker)
|
||||||
end
|
end
|
||||||
end, name)
|
end, name)
|
||||||
clicker:set_look_horizontal(self.object:get_yaw())
|
clicker:set_look_horizontal(self.object:get_yaw())
|
||||||
end
|
mcl_tmp_message.message(clicker, S("Sneak to dismount"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,6 +154,14 @@ function boat.on_step(self, dtime)
|
||||||
|
|
||||||
if self._driver then
|
if self._driver then
|
||||||
local ctrl = self._driver:get_player_control()
|
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()
|
local yaw = self.object:get_yaw()
|
||||||
if ctrl.up then
|
if ctrl.up then
|
||||||
-- Forwards
|
-- Forwards
|
||||||
|
|
|
@ -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)
|
|
@ -6,8 +6,6 @@ local player_in_bed = 0
|
||||||
local is_sp = minetest.is_singleplayer()
|
local is_sp = minetest.is_singleplayer()
|
||||||
local weather_mod = minetest.get_modpath("mcl_weather") ~= nil
|
local weather_mod = minetest.get_modpath("mcl_weather") ~= nil
|
||||||
local explosions_mod = minetest.get_modpath("mcl_explosions") ~= nil
|
local explosions_mod = minetest.get_modpath("mcl_explosions") ~= nil
|
||||||
local huds = {}
|
|
||||||
local hud_hide_timeouts = {}
|
|
||||||
|
|
||||||
-- Helper functions
|
-- Helper functions
|
||||||
|
|
||||||
|
@ -326,8 +324,7 @@ function mcl_beds.on_rightclick(pos, player, is_top)
|
||||||
success, message = lay_down(player, ppos, other)
|
success, message = lay_down(player, ppos, other)
|
||||||
end
|
end
|
||||||
if message then
|
if message then
|
||||||
player:hud_change(huds[name], "text", message)
|
mcl_tmp_message.message(player, message)
|
||||||
hud_hide_timeouts[name] = 3
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
lay_down(player, nil, nil, false)
|
lay_down(player, nil, nil, false)
|
||||||
|
@ -355,25 +352,12 @@ minetest.register_on_joinplayer(function(player)
|
||||||
meta:set_string("mcl_beds:sleeping", "false")
|
meta:set_string("mcl_beds:sleeping", "false")
|
||||||
end
|
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, "speed", "mcl_beds:sleeping")
|
||||||
playerphysics.remove_physics_factor(player, "jump", "mcl_beds:sleeping")
|
playerphysics.remove_physics_factor(player, "jump", "mcl_beds:sleeping")
|
||||||
update_formspecs(false)
|
update_formspecs(false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
local name = player:get_player_name()
|
|
||||||
huds[name] = nil
|
|
||||||
|
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for n, player in ipairs(players) do
|
for n, player in ipairs(players) do
|
||||||
if player:get_player_name() == name then
|
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)
|
mcl_beds.kick_player(player)
|
||||||
end
|
end
|
||||||
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)
|
|
||||||
|
|
Loading…
Reference in New Issue