Add homes system
This commit is contained in:
46
mods/PLAYER/pyutest_home/init.lua
Normal file
46
mods/PLAYER/pyutest_home/init.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
local storage = minetest.get_mod_storage()
|
||||
local homes = minetest.deserialize(storage:get("player_homes")) or {}
|
||||
|
||||
minetest.register_on_joinplayer(function (player)
|
||||
local name = player:get_player_name()
|
||||
if homes[name] == nil then
|
||||
homes[name] = {}
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_chatcommand("sethome", {
|
||||
params = "<name>",
|
||||
description = "Sets the position of home <NAME>",
|
||||
func = function (name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
homes[name][param] = player:get_pos()
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("tphome", {
|
||||
params = "<name>",
|
||||
description = "Teleports to home <NAME>",
|
||||
func = function (name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
player:set_pos(homes[name][param] or player:get_pos())
|
||||
end
|
||||
})
|
||||
|
||||
local function save_data()
|
||||
storage:set_string("player_homes", minetest.serialize(homes))
|
||||
end
|
||||
|
||||
minetest.register_on_shutdown(save_data)
|
||||
|
||||
local first_run = true
|
||||
local function interval()
|
||||
if first_run then
|
||||
first_run = false
|
||||
else
|
||||
save_data()
|
||||
end
|
||||
|
||||
minetest.after(10, interval)
|
||||
end
|
||||
|
||||
interval()
|
0
mods/PLAYER/pyutest_home/mod.conf
Normal file
0
mods/PLAYER/pyutest_home/mod.conf
Normal file
Reference in New Issue
Block a user