]> git.lizzy.rs Git - Crafter.git/blob - mods/server_utilities/init.lua
Add Suffocation
[Crafter.git] / mods / server_utilities / init.lua
1 local minetest,os = minetest,os
2 local mod_storage = minetest.get_mod_storage()
3 local pool = {}
4 local home_timeout = 60
5
6 --this does not terminate data because player's can spam
7 --leave and come back in to reset the home timout
8
9
10 minetest.register_chatcommand("sethome", {
11         params = "nil",
12         description = "Use this to set your home. Can be returned to by setting /home",
13         privs = {home = true},
14         func = function(name)
15                 local time = minetest.get_us_time()/1000000
16                 local player = minetest.get_player_by_name(name)
17                 local pos = player:get_pos()
18                 if not pool[name] or pool[name] and time-pool[name] > home_timeout then
19                         mod_storage:set_string(name.."home", minetest.serialize(pos))
20                         pool[name] = time
21                         minetest.chat_send_player(name, "Home set.")
22                 elseif pool[name] then
23                         local diff = home_timeout-math.ceil(time-pool[name])+1
24                         local s = "s"
25                         if diff == 1 then
26                                 s = ""
27                         end
28                         minetest.chat_send_player(name, diff.." more second"..s.." until you can run that command.")
29                 end
30         end,
31 })
32
33
34 minetest.register_chatcommand("home", {
35         params = "nil",
36         description = "Use this to set your home. Can be returned to by setting /home",
37         privs = {home = true},
38         func = function(name)
39                 local time = minetest.get_us_time()/1000000
40                 local player = minetest.get_player_by_name(name)
41
42                 if not pool[name] or pool[name] and time-pool[name] > home_timeout then
43
44                         local newpos = minetest.deserialize(mod_storage:get_string(name.."home"))
45                         
46                         if newpos then
47                                 player:add_player_velocity(vector.multiply(player:get_player_velocity(),-1))
48                                 player:move_to(newpos)
49                                 pool[name] = time
50                         else
51                                 minetest.chat_send_player(name, "No home set.")
52                         end
53                 elseif pool[name] then
54                         local diff = home_timeout-math.ceil(time-pool[name])+1
55                         local s = "s"
56                         if diff == 1 then
57                                 s = ""
58                         end
59                         minetest.chat_send_player(name, diff.." more second"..s.." until you can run that command.")
60                 end
61         end,
62 })
63
64 minetest.register_privilege("home", {
65         description = "Player can use /home and /sethome.",
66         give_to_singleplayer = false,
67 })