Add setspawn.
This commit is contained in:
parent
36af3b1d92
commit
af524bf009
2 changed files with 27 additions and 6 deletions
13
chat.lua
13
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,
|
||||
})
|
||||
|
|
18
init.lua
18
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 = {}
|
||||
for _, i in pairs({'teleport_data', 'hunger', 'spawn'}) do
|
||||
if not fun_caves.db[i] then
|
||||
fun_caves.db[i] = {}
|
||||
end
|
||||
if not fun_caves.db.hunger then
|
||||
fun_caves.db.hunger = {}
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue