Respawn the player at the last bed he has slept
parent
2196208700
commit
0d2d3d203b
|
@ -16,15 +16,14 @@ http://wiki.minetest.com/wiki/Installing_Mods
|
|||
|
||||
How to use the mod:
|
||||
Craft a bed like this:
|
||||
red wool blue wool blue wool
|
||||
stick stick
|
||||
(Theres no "normal" way to get wool so you can use the commands
|
||||
"/giveme wool:red" and "/giveme wool:blue 2")
|
||||
white wool white wool white wool
|
||||
stick stick
|
||||
After placing it anywhere you can go to sleep with a leftklick with your
|
||||
hand on the bed. If it is night a chatmessage wishs you "Good night" and
|
||||
you sleep until the next morning. To go outside the bed it is recommended
|
||||
to hit the bed again with a leftklick (it also works if you just go away
|
||||
but its not so safe).
|
||||
After dying the player will respawn at the last bed he has slept.
|
||||
|
||||
License:
|
||||
Sourcecode: WTFPL (see below)
|
||||
|
|
23
init.lua
23
init.lua
|
@ -144,6 +144,13 @@ minetest.register_craft({
|
|||
}
|
||||
})
|
||||
|
||||
local player_spawns = {}
|
||||
local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "r")
|
||||
if file then
|
||||
player_spawns = minetest.deserialize(file:read("*all"))
|
||||
file:close()
|
||||
end
|
||||
|
||||
local timer = 0
|
||||
local wait = false
|
||||
minetest.register_globalstep(function(dtime)
|
||||
|
@ -163,11 +170,27 @@ minetest.register_globalstep(function(dtime)
|
|||
wait = false
|
||||
end)
|
||||
wait = true
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
player_spawns[player:get_player_name()] = player:getpos()
|
||||
end
|
||||
local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "w")
|
||||
if file then
|
||||
file:write(minetest.serialize(player_spawns))
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
if player_spawns[name] then
|
||||
player:setpos(player_spawns[name])
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"beds:bed_bottom"},
|
||||
interval = 1,
|
||||
|
|
Loading…
Reference in New Issue