File: register_command.lua

package info (click to toggle)
minetest-mod-skyblock 0.2.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 384 kB
  • sloc: makefile: 14
file content (48 lines) | stat: -rw-r--r-- 1,434 bytes parent folder | download | duplicates (2)
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
--[[

Skyblock for Minetest

Copyright (c) 2015 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-skyblock
License: GPLv3

]]--


-- register register_privilege
minetest.register_privilege('level', 'Can use /level')

-- level
minetest.register_chatcommand('level', {
	description = 'Get or change a players current level.',
	privs = {level = true},
	params = "<player_name> <level>",
	func = function(name, param)
		local found, _, player_name, level = param:find("^([^%s]+)%s+(.+)$")
		if not player_name then
			player_name = name
		end
		level = tonumber(level)
		if not level then
			minetest.chat_send_player(name, player_name..' is on level '..skyblock.feats.get_level(player_name))
			return
		end
		if skyblock.feats.set_level(player_name, level) then
			minetest.chat_send_player(name, player_name..' has been set to level '..level)
		else
			minetest.chat_send_player(name, 'cannot change '..player_name..' to level '..level)
		end
	end,
})

-- who
minetest.register_chatcommand('who', {
	description = 'Display list of online players and their current level.',
	func = function(name)
		minetest.chat_send_player(name, 'Current Players:')
		for _,player in ipairs(minetest.get_connected_players()) do
			local player_name = player:get_player_name()
			minetest.chat_send_player(name, ' - '..player_name..' - level '..skyblock.feats.get_level(player_name))
		end
	end,
})