This repository has been archived on 2024-03-05. You can view files and clone it, but cannot push or open issues or pull requests.
mcl_cozy/init.lua

101 lines
3.8 KiB
Lua
Raw Normal View History

local S = minetest.get_translator(minetest.get_current_modname())
local mcl_cozy_print_actions = minetest.settings:get_bool("mcl_cozy_print_actions") ~= false
-- functions
local function print_action_sit(name)
if mcl_cozy_print_actions then
minetest.chat_send_all("* "..name..S(" sits"))
end
end
local function print_action_lay(name)
if mcl_cozy_print_actions then
minetest.chat_send_all("* "..name..S(" lies"))
end
end
local function print_action_stand(name)
if mcl_cozy_print_actions then
minetest.chat_send_all("* "..name..S(" stands up"))
end
end
-- to support both Mineclonia and MineClone 2/5
local function actionbar_show_status(player)
if minetest.get_modpath("mcl_title") then
mcl_title.set(player, "actionbar", {text=S("Move to stand up"), color="white", stay=60})
elseif minetest.get_modpath("mcl_tmp_message") then
mcl_tmp_message.message(player, S("Move to stand up"))
else
minetest.log("warning", "[mcl_cozy] Didn't found any mod to set titles in actionbar (mcl_title or mcl_tmp_message)!")
end
end
2022-02-24 01:24:56 +01:00
minetest.register_globalstep(function(dtime)
local players = minetest.get_connected_players()
for i=1, #players do
local name = players[i]:get_player_name()
if mcl_player.player_attached[name] and not players[i]:get_attach() and
(players[i]:get_player_control().up == true or
players[i]:get_player_control().down == true or
players[i]:get_player_control().left == true or
players[i]:get_player_control().right == true or
players[i]:get_player_control().jump == true or
players[i]:get_player_control().sneak == true) then
players[i]:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
players[i]:set_physics_override({speed=1, jump=1, gravity=1})
mcl_player.player_attached[name] = false
mcl_player.player_set_animation(players[i], "stand", 30)
end
-- check the node below player (and if it's air, just unmount)
if minetest.get_node(vector.offset(players[i]:get_pos(),0,-1,0)).name == "air" then
2022-02-24 01:24:56 +01:00
players[i]:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
players[i]:set_physics_override({speed=1, jump=1, gravity=1})
2022-02-24 01:24:56 +01:00
mcl_player.player_attached[name] = false
end
end
end)
minetest.register_chatcommand("sit", {
description = S("Sit down"),
2022-02-24 01:24:56 +01:00
func = function(name)
local player = minetest.get_player_by_name(name)
-- check the node below player (and if it's air, just don't sit)
if minetest.get_node(vector.offset(player:get_pos(),0,-1,0)).name == "air" then return end
2022-02-24 01:24:56 +01:00
if mcl_player.player_attached[name] then
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
player:set_physics_override({speed=1, jump=1, gravity=1})
2022-02-24 01:24:56 +01:00
mcl_player.player_attached[name] = false
mcl_player.player_set_animation(player, "stand", 30)
print_action_stand(name)
2022-02-24 01:24:56 +01:00
else
player:set_eye_offset({x=0, y=-7, z=2}, {x=0, y=0, z=0})
player:set_physics_override({speed=0, jump=0, gravity=0})
2022-02-24 01:24:56 +01:00
mcl_player.player_attached[name] = true
mcl_player.player_set_animation(player, "sit", 30)
print_action_sit(name)
actionbar_show_status(player)
2022-02-24 01:24:56 +01:00
end
end
})
minetest.register_chatcommand("lay", {
description = S("Lay down"),
2022-02-24 01:24:56 +01:00
func = function(name)
local player = minetest.get_player_by_name(name)
if minetest.get_node(vector.offset(player:get_pos(),0,-1,0)).name == "air" then return end
2022-02-24 01:24:56 +01:00
if mcl_player.player_attached[name] then
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
player:set_physics_override({speed=1, jump=1, gravity=1})
2022-02-24 01:24:56 +01:00
mcl_player.player_attached[name] = false
mcl_player.player_set_animation(player, "stand", 30)
print_action_stand(name)
2022-02-24 01:24:56 +01:00
else
player:set_eye_offset({x=0, y=-13, z=0}, {x=0, y=0, z=0})
player:set_physics_override({speed=0, jump=0, gravity=0})
2022-02-24 01:24:56 +01:00
mcl_player.player_attached[name] = true
mcl_player.player_set_animation(player, "lay", 0)
print_action_lay(name)
actionbar_show_status(player)
2022-02-24 01:24:56 +01:00
end
end
})