Add setspawn.

This commit is contained in:
Duane 2016-06-25 15:22:50 -05:00
parent 36af3b1d92
commit af524bf009
2 changed files with 27 additions and 6 deletions

View file

@ -18,3 +18,16 @@ minetest.register_chatcommand("armor", {
end end
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,
})

View file

@ -38,11 +38,10 @@ end
if not fun_caves.db then if not fun_caves.db then
fun_caves.db = {} fun_caves.db = {}
end end
if not fun_caves.db.teleport_data then for _, i in pairs({'teleport_data', 'hunger', 'spawn'}) do
fun_caves.db.teleport_data = {} if not fun_caves.db[i] then
end fun_caves.db[i] = {}
if not fun_caves.db.hunger then end
fun_caves.db.hunger = {}
end end
@ -116,6 +115,15 @@ end
--fun_caves.print_recipes() --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") local hunger_mod = minetest.get_modpath("hunger")
fun_caves.hunger_id = {} fun_caves.hunger_id = {}
@ -129,7 +137,7 @@ function fun_caves.hunger_change(player, change)
end end
local hp = player:get_hp() 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)) 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]) player:hud_change(fun_caves.hunger_id[name], 'number', fun_caves.db.hunger[name])
if fun_caves.db.hunger[name] == 0 then if fun_caves.db.hunger[name] == 0 then