1
0
Fork 0
MineClone2/mods/HUD/awards/chat_commands.lua

94 lines
3.0 KiB
Lua
Raw Normal View History

2017-03-03 23:55:34 +00:00
-- AWARDS
--
-- Copyright (C) 2013-2015 rubenwardy
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as published by
-- the Free Software Foundation; either version 2.1 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Lesser General Public License for more details.
-- You should have received a copy of the GNU Lesser General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--
local S = minetest.get_translator(minetest.get_current_modname())
2017-03-03 23:55:34 +00:00
minetest.register_chatcommand("awards", {
params = S("[c|clear|disable|enable]"),
description = S("Show, clear, disable or enable your advancements."),
2017-03-03 23:55:34 +00:00
func = function(name, param)
if param == "enable" then
awards.enable(name)
minetest.chat_send_player(name, S("You have enabled your advancements."))
2022-10-31 21:53:51 +00:00
return
end
2022-10-31 15:22:28 +00:00
if awards.player(name).disabled then
minetest.chat_send_player(name, S("Awards are disabled, enable them first by using /awards enable!"))
return
end
2017-03-03 23:55:34 +00:00
if param == "clear" then
2022-10-31 15:22:28 +00:00
awards.clear_player(name)
minetest.chat_send_player(name,
S("All your awards and statistics have been cleared. You can now start again."))
2017-03-03 23:55:34 +00:00
elseif param == "disable" then
awards.disable(name)
minetest.chat_send_player(name, S("You have disabled your advancements."))
2022-10-31 21:53:51 +00:00
else
awards.show_to(name, name, nil, false)
2017-03-03 23:55:34 +00:00
end
end
})
minetest.register_privilege("advancements", {
description = S("Can give advancements to any player"),
2020-03-30 19:02:13 +00:00
give_to_singleplayer = false,
give_to_admin = false,
})
minetest.register_chatcommand("advancement", {
params = S("(grant <player> (<advancement> | all)) | list"),
privs = { advancements = true },
description = S("Give advancement to player or list all advancements"),
2020-03-30 19:02:13 +00:00
func = function(name, param)
if param == "list" then
local list = {}
for k,_ in pairs(awards.def) do
table.insert(list, k)
end
table.sort(list)
for a=1, #list do
minetest.chat_send_player(name, S("@1 (@2)", awards.def[list[a]].title, list[a]))
end
return true
end
local keyword, playername, achievement = string.match(param, "([^ ]+) (.+) (.+)")
if not keyword or not playername or not achievement then
return false, S("Invalid syntax.")
end
if keyword ~= "grant" then
return false, S("Invalid action.")
end
local player = minetest.get_player_by_name(playername)
if not player then
return false, S("Player is not online.")
end
if achievement == "all" then
for k,_ in pairs(awards.def) do
awards.unlock(playername, k)
end
return true, S("Done.")
elseif awards.exists(achievement) then
awards.unlock(playername, achievement)
return true, S("Done.")
else
return false, S("Advancement “@1” does not exist.", achievement)
2020-03-30 19:02:13 +00:00
end
end
})