-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
81 lines (72 loc) · 1.92 KB
/
init.lua
File metadata and controls
81 lines (72 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
local players = {}
local function vdistance(a, b)
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
return x*x + y*y + z*z
end
local function set_checkpoint(player, pos)
local name = player:get_player_name()
local ppos = player:getpos()
if vdistance(pos, ppos) <= 10 then
players[name] = ppos
minetest.chat_send_player(name, "Checkpoint set.")
else
minetest.chat_send_player(name, "Out of range!")
end
end
minetest.register_node("d53_checkpoint:checkpoint_button", {
description = "Checkpoint button.",
tiles = {"checkpointbtn.png"},
drawtype = "mesh",
light_source = 6,
paramtype = "light",
mesh = "checkpointbtn.obj",
collision_box = {
type = "fixed",
fixed = {0.2, 0.55, 0.2, -0.2, -1, -0.2},
},
selection_box = {
type = "fixed",
fixed = {0.2, 0.55, 0.2, -0.2, -1, -0.2},
},
on_rightclick = function(pos, _, clicker)
set_checkpoint(clicker, pos)
end,
on_punch = function(pos, _, puncher)
set_checkpoint(puncher, pos)
end
})
minetest.register_chatcommand("checkpoint", {
description = "Restore saved checkpoint.",
func = function(name, param)
local pos = players[name]
if pos then
local player = minetest.get_player_by_name(name)
player:setpos(pos)
else
minetest.chat_send_player(name, "No checkpoint saved.")
end
end
})
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
players[name] = nil
end)
minetest.register_privilege("checkpoint_control", {
description = "Using checkpoint mod.",
})
minetest.register_chatcommand("r_checkpoint", {
description = "Reset checkpoints.",
privs = {checkpoint_control = true},
func = function(name)
players[name] = nil
minetest.chat_send_player(name, "Checkpoint removed.")
end
})
minetest.register_chatcommand("r_checkpoints", {
description = "Resets all checkpoints",
privs = {checkpoint_control = true},
func = function(name)
players = {}
minetest.chat_send_player(name, "All checkpoints removed.")
end
})