aboutsummaryrefslogtreecommitdiff
path: root/clientmods/commands/init.lua
blob: 6e2ea4ed67b1f6cf5898a512df49ffa71f210d09 (plain)
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
core.register_chatcommand("place", {
	params = "<X>,<Y>,<Z>",
	description = "Place wielded item",
	func = function(param)
		local success, pos = core.parse_pos(param)
		if success then
			core.place_node(pos)
			return true, "Node placed at " .. core.pos_to_string(pos)
		end
		return false, pos
	end,
})

core.register_chatcommand("dig", {
	params = "<X>,<Y>,<Z>",
	description = "Dig node",
	func = function(param)
		local success, pos = core.parse_pos(param)
		if success then
			core.dig_node(pos)
			return true, "Node at " .. core.pos_to_string(pos) .. " dug"
		end
		return false, pos
	end,
})

core.register_chatcommand("kill", {
	description = "Kill yourself",
	func = function(param)
		core.send_damage(core.localplayer:get_hp())
	end,
})

core.register_chatcommand("scan", {
	description = "Scan for one or multible nodes in a radius around you",
	param = "<radius> node1[,node2...]",
	func = function(param)
		local radius = tonumber(param:split(" ")[1])
		local nodes = param:split(" ")[2]:split(",")
		local pos = core.localplayer:get_pos()
		local fpos = core.find_node_near(pos, radius, nodes, true)
		if fpos then
			return true, "Found " .. table.concat(nodes, " or ") .. " at " .. core.pos_to_string(fpos)
		end
		return false, "None of " .. table.concat(nodes, " or ") .. " found in a radius of " .. tostring(radius)
	end,
})

local function teleport(param)
	local success, pos = core.parse_pos(param)
	if success then
		core.localplayer:set_pos(pos)
		return true, "Teleporting to " .. core.pos_to_string(pos)
	end
	return false, pos
end

core.register_chatcommand("teleport", {
	params = "<X>,<Y>,<Z>",
	description = "Teleport to position",
	func = function(param)
		return teleport(param)
	end,
})

core.register_chatcommand("tpoff", {
	params = "<X>,<Y>,<Z>",
	description = "Teleport to position and log out immediately",
	func = function(param)
		teleport(param)
		minetest.disconnect()
	end,
})

minetest.register_chatcommand("wielded", {
	description = "Print itemstring of wieleded item",
	func = function()
		return true, minetest.get_wielded_item():get_name()
	end
})