From a3cbc982982679d821c3c0cc40721cb505315db5 Mon Sep 17 00:00:00 2001 From: kaadmy Date: Sun, 7 Feb 2016 16:57:45 -0800 Subject: [PATCH] added welcome mod --- minetest.conf | 3 ++ mods/welcome/README.txt | 7 ++++ mods/welcome/depends.txt | 2 + mods/welcome/init.lua | 87 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 mods/welcome/README.txt create mode 100644 mods/welcome/depends.txt create mode 100644 mods/welcome/init.lua diff --git a/minetest.conf b/minetest.conf index 5bf43d7..c30dfe5 100644 --- a/minetest.conf +++ b/minetest.conf @@ -21,6 +21,9 @@ movement_gravity = 9.8 # privs default_privs = interact, shout, spawn, fast, player_skin +# if the welcome formspec is shown on join +welcome_enable = true + # if you're given the inital stuff; a stone pick and 10 torches give_initial_stuff = false diff --git a/mods/welcome/README.txt b/mods/welcome/README.txt new file mode 100644 index 0000000..0b81f35 --- /dev/null +++ b/mods/welcome/README.txt @@ -0,0 +1,7 @@ +Welcome mod +=========== +By Kaadmy, for Pixture + +Prompts users to accept the rules when joining + +Source license: LGPLv2.1 diff --git a/mods/welcome/depends.txt b/mods/welcome/depends.txt new file mode 100644 index 0000000..3a7daa1 --- /dev/null +++ b/mods/welcome/depends.txt @@ -0,0 +1,2 @@ +default + diff --git a/mods/welcome/init.lua b/mods/welcome/init.lua new file mode 100644 index 0000000..a85ecd4 --- /dev/null +++ b/mods/welcome/init.lua @@ -0,0 +1,87 @@ +-- +-- Welcome mod +-- By Kaadmy, for Pixture +-- + +welcome = {} + +welcome.rules = { + "Welcome!", + "", + "Rules:", + "1. No swearing.", + "2. No griefing.", + "3. No spamming." +} + +function welcome.get_formspec(name) + if not minetest.setting_getbool("welcome_enable") then + minetest.chat_send_player(name, "Welcoming is disabled") + return "" + end + + local form = default.ui.get_page("core_notabs") + + local rules = "" + + for _, t in ipairs(welcome.rules) do + if rules ~= "" then rules = rules .. "," end + + rules = rules .. minetest.formspec_escape(t) + end + + form = form .. "textlist[0.25,0.75;7.75,6.75;rules;" .. rules .. "]" + + if not minetest.check_player_privs(name, {interact = true}) then + form = form .. default.ui.button_exit(1.25, 7.75, 3, 1, "decline_rules", "Nope") + form = form .. default.ui.button_exit(4.25, 7.75, 3, 1, "accept_rules", "Okay") + else + form = form .. default.ui.button_exit(2.9, 7.75, 3, 1, "", "Okay") + end + + return form +end + +function welcome.show_rules(name) + local f = welcome.get_formspec(name) + + if f ~= "" then + minetest.show_formspec(name, "welcome:welcome", f) + end +end + +minetest.register_on_player_receive_fields( + function(player, form_name, fields) + local name = player:get_player_name() + + if minetest.check_player_privs(name, {interact = true}) or fields.rules then + return true + end + + if fields.accept_rules then + minetest.set_player_privs(name, {interact = true}) + minetest.chat_send_player(name, "You now have interact, follow the rules and have fun!") + else + minetest.chat_send_player(name, "If you want to interact, please read and accept the rules. Type /welcome to show rules.") + end + end) + +minetest.register_chatcommand( + "welcome", + { + description = "Show rules", + func = function(name, param) + welcome.show_rules(name) + end + }) + +minetest.register_on_joinplayer( + function(player) + local name = player:get_player_name() + + if not minetest.check_player_privs(name, {interact = true}) and minetest.setting_getbool("welcome_enable") then + welcome.show_rules(name) + end + end) + +default.log("mod:welcome", "loaded") \ No newline at end of file