diff --git a/chat.lua b/chat.lua index 6fab209..6ce1a7e 100644 --- a/chat.lua +++ b/chat.lua @@ -18,3 +18,16 @@ minetest.register_chatcommand("armor", { end end, }) + + +minetest.register_chatcommand("setspawn", { + params = "", + description = "change your spawn position", + privs = {}, + func = function(name, param) + local player = minetest.get_player_by_name(name) + local pos = player:getpos() + fun_caves.db.spawn[name] = pos + minetest.chat_send_player(name, 'Your spawn position has been changed.') + end, +}) diff --git a/init.lua b/init.lua index 8dabe98..2d2131f 100644 --- a/init.lua +++ b/init.lua @@ -38,11 +38,10 @@ end if not fun_caves.db then fun_caves.db = {} end -if not fun_caves.db.teleport_data then - fun_caves.db.teleport_data = {} -end -if not fun_caves.db.hunger then - fun_caves.db.hunger = {} +for _, i in pairs({'teleport_data', 'hunger', 'spawn'}) do + if not fun_caves.db[i] then + fun_caves.db[i] = {} + end end @@ -116,6 +115,15 @@ end --fun_caves.print_recipes() +minetest.register_on_respawnplayer(function(player) + local name = player:get_player_name() + if fun_caves.db.spawn[name] then + player:setpos(fun_caves.db.spawn[name]) + return true + end +end) + + local hunger_mod = minetest.get_modpath("hunger") fun_caves.hunger_id = {} @@ -129,7 +137,7 @@ function fun_caves.hunger_change(player, change) end local hp = player:get_hp() - if change < 0 or hp >= 20 then + if change < 0 or hp >= 16 then fun_caves.db.hunger[name] = math.min(20, math.max(0, fun_caves.db.hunger[name] + change)) player:hud_change(fun_caves.hunger_id[name], 'number', fun_caves.db.hunger[name]) if fun_caves.db.hunger[name] == 0 then