forked from mff/interact
Add a quiz screen!
This commit is contained in:
parent
b3eb6379a1
commit
3fcb5c86b0
|
@ -1,12 +1,12 @@
|
|||
##Interact: A mod for minetest.
|
||||
##Interact: A mod for Minetest.
|
||||
|
||||
This mod is designed to automatically grant new players on a server interact. A formspec will be show when the player joins, and there is a command to bring the formspec up later in the game.
|
||||
There are 3 screens that they go through. The first one is a check if they like griefing (One for really stupid griefers!), the next checks if the player just wants to look round the server, and the final one shows the rules, and asks the player to accept them.
|
||||
There are 3 screens that they go through. The first one is a check if they like griefing (One for really stupid griefers!), the next checks if the player just wants to look round the server, and the final one shows the rules, and asks the player to accept them. Finally, there is a screen which offers the player a quiz, which s/he has to complete successfully to get interact.
|
||||
|
||||
Almost everything in the mod can be configured to how you want it.
|
||||
|
||||
####Configuring the mod:
|
||||
You will probably want to replace the default rules with your own in rules.lua.
|
||||
You will probably want to replace the default rules with your own in rules.lua. Also, the quiz should be adapted to your rules, thus the quiz questions are found in rules.lua also.
|
||||
|
||||
Everything else that you need to configure the mod can be found in config.lua. If you want to, have a look over it before running the mod, to see if everything seems to be as you want it!
|
||||
|
||||
|
|
47
config.lua
47
config.lua
|
@ -1,5 +1,10 @@
|
|||
interact = {}
|
||||
|
||||
--Which screens to show.
|
||||
interact.screen1 = true --The welcome a first question screen.
|
||||
interact.screen2 = true --The visit or interact screen.
|
||||
interact.screen4 = true --The quiz screen.
|
||||
|
||||
--The first screen--
|
||||
--The text at the top.
|
||||
interact.s1_header = "Hello, welcome to this server!"
|
||||
|
@ -24,8 +29,8 @@ interact.s2_l2 = "the server?"
|
|||
interact.s2_b1 = "Yes, I want interact!"
|
||||
interact.s2_b2 = "I just want to look round."
|
||||
|
||||
--The message the player is sent if s/he is just visting.
|
||||
interact.vist_msg = "Have a nice time looking round! If you want interact just type /rules, and you can go through the process again!"
|
||||
--The message the player is sent if s/he is just visiting.
|
||||
interact.visit_msg = "Have a nice time looking round! If you want interact just type /rules, and you can go through the process again!"
|
||||
|
||||
--The third screen--
|
||||
--The header for the rules box, this can have 60 characters, max.
|
||||
|
@ -35,12 +40,46 @@ interact.s3_header = "Here are the rules:"
|
|||
interact.s3_b1 = "I agree"
|
||||
interact.s3_b2 = "I disagree"
|
||||
|
||||
--The message to send players who disagree when they are kicked.
|
||||
--The message to send players who disagree when they are kicked for disagring with the rules.
|
||||
interact.disagree_msg = "Bye then! You have to agree to the rules to play on the server."
|
||||
|
||||
--Kick or ban players who disagree. False will just kick.
|
||||
--Kick or ban players who disagree with the rules. False will just kick.
|
||||
interact.disagree_ban = false
|
||||
|
||||
--The fouth screen--
|
||||
--Should there be a back to rules button?
|
||||
interact.s4_to_rules_button = true
|
||||
--The back to rules button. 13 characters, max.
|
||||
interact.s4_to_rules = "Back to rules"
|
||||
|
||||
--The header for screen 4. 60 characters max, although this is a bit of a squash. I recomend 55 as a max.
|
||||
interact.s4_header = "Time for a quiz on the rules!"
|
||||
|
||||
--Since the questions are intrinsically connected with the rules, they are to be found in rules.lua
|
||||
--The trues are limited to 24 characters. The falses can have 36 characters.
|
||||
interact.s4_question1_true = "Yes."
|
||||
interact.s4_question1_false = "No."
|
||||
interact.s4_question2_true = "Yes."
|
||||
interact.s4_question2_false = "No."
|
||||
interact.s4_question3_true = "Yes."
|
||||
interact.s4_question3_false = "No."
|
||||
interact.s4_question4_true = "Yes."
|
||||
interact.s4_question4_false = "No."
|
||||
|
||||
interact.s4_submit = "Submit!"
|
||||
|
||||
--What to do on a wrong quiz.
|
||||
--Options are "kick" "ban" "reshow" "rules" and "nothing"
|
||||
interact.on_wrong_quiz = "nothing"
|
||||
--The message to send the player if reshow is the on_wrong_quiz option.
|
||||
interact.quiz_try_again_msg = "Have another go."
|
||||
--The message sent to the player if rules is the on_wrong_quiz option.
|
||||
interact.quiz_rules_msg = "Have another look at the rules:"
|
||||
--The kick reason if kick is the on_wrong_quiz option.
|
||||
interact.wrong_quiz_kick_msg = "Pay more attention next time!"
|
||||
--The message sent to the player if nothing is the on_wrong_quiz option.
|
||||
interact.quiz_fail_msg = "You got that wrong."
|
||||
|
||||
--The messages send to the player after interact is granted.
|
||||
interact.interact_msg1 = "Thanks for accepting the rules, you now are able to interact with things."
|
||||
interact.interact_msg2 = "Happy building!"
|
||||
|
|
180
init.lua
180
init.lua
|
@ -1,6 +1,12 @@
|
|||
dofile(minetest.get_modpath("interact") .. "/config.lua")
|
||||
dofile(minetest.get_modpath("interact") .. "/rules.lua") --I put the rules in their own file so that they don't get lost/overlooked!
|
||||
|
||||
local rule1 = 0
|
||||
local rule2 = 0
|
||||
local rule3 = 0
|
||||
local rule4 = 0
|
||||
local multi = 0
|
||||
|
||||
local function make_formspec(player)
|
||||
local name = player:get_player_name()
|
||||
local size = { "size[10,4]" }
|
||||
|
@ -30,36 +36,69 @@ local function make_formspec3(player)
|
|||
return table.concat(size)
|
||||
end
|
||||
|
||||
local function make_formspec4(player)
|
||||
local name = player:get_player_name()
|
||||
local size = { "size[10,9]" }
|
||||
if interact.s4_to_rules_button == true then
|
||||
table.insert(size, "button_exit[7.75,0.25;2.1,0.1;rules;" ..interact.s4_to_rules.. "]")
|
||||
end
|
||||
table.insert(size, "label[0.25,0;" ..interact.s4_header.."]")
|
||||
table.insert(size, "label[0.5,0.5;" ..interact.s4_question1.."]")
|
||||
table.insert(size, "checkbox[0.25,1;rule1_true;" ..interact.s4_question1_true.."]")
|
||||
table.insert(size, "checkbox[4,1;rule1_false;" ..interact.s4_question1_false.. "]")
|
||||
table.insert(size, "label[0.5,2;" ..interact.s4_question2.. "]")
|
||||
table.insert(size, "checkbox[0.25,2.5;rule2_true;" ..interact.s4_question2_true.. "]")
|
||||
table.insert(size, "checkbox[4,2.5;rule2_false;" ..interact.s4_question2_false.. "]")
|
||||
table.insert(size, "label[0.5,3.5;" ..interact.s4_question3.. "]")
|
||||
table.insert(size, "checkbox[0.25,4;rule3_true;" ..interact.s4_question3_true.. "]")
|
||||
table.insert(size, "checkbox[4,4;rule3_false;" ..interact.s4_question3_false.. "]")
|
||||
table.insert(size, "label[0.5,5;" ..interact.s4_question4.. "]")
|
||||
table.insert(size, "checkbox[0.25,5.5;rule4_true;" ..interact.s4_question4_true.. "]")
|
||||
table.insert(size, "checkbox[4,5.5;rule4_false;" ..interact.s4_question4_false.."]")
|
||||
table.insert(size, "label[0.5,6.5;" ..interact.s4_multi_question.. "]")
|
||||
table.insert(size, "checkbox[4.75,6.25;multi_choice1;" ..interact.s4_multi1.. "]")
|
||||
table.insert(size, "checkbox[0.25,7;multi_choice2;" ..interact.s4_multi2.. "]")
|
||||
table.insert(size, "checkbox[4.75,7;multi_choice3;" ..interact.s4_multi3.."]")
|
||||
table.insert(size, "button_exit[3,8.4;3.5,0.5;submit;" ..interact.s4_submit.."]")
|
||||
return table.concat(size)
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "welcome" then return end
|
||||
local name = player:get_player_name()
|
||||
if fields.no then
|
||||
local name = player:get_player_name()
|
||||
if fields.no then
|
||||
if interact.screen2 == false then
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "rules", make_formspec3(player))
|
||||
end)
|
||||
else
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "visit", make_formspec2(player))
|
||||
end)
|
||||
return
|
||||
elseif fields.yes then
|
||||
if interact.grief_ban ~= true then
|
||||
minetest.kick_player(name, interact.msg_grief)
|
||||
else
|
||||
minetest.ban_player(name)
|
||||
end
|
||||
end
|
||||
return
|
||||
elseif fields.yes then
|
||||
if interact.grief_ban ~= true then
|
||||
minetest.kick_player(name, interact.msg_grief)
|
||||
else
|
||||
minetest.ban_player(name)
|
||||
end
|
||||
return
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "visit" then return end
|
||||
local name = player:get_player_name()
|
||||
if fields.interact then
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "rules", make_formspec3(player))
|
||||
end)
|
||||
return
|
||||
elseif fields.visit then
|
||||
minetest.chat_send_player(name, interact.vist_msg)
|
||||
minetest.log("action", name.. " is just visiting.")
|
||||
local name = player:get_player_name()
|
||||
if fields.interact then
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "rules", make_formspec3(player))
|
||||
end)
|
||||
return
|
||||
elseif fields.visit then
|
||||
minetest.chat_send_player(name, interact.visit_msg)
|
||||
minetest.log("action", name.. " is just visiting.")
|
||||
return
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -67,7 +106,8 @@ end)
|
|||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "rules" then return end
|
||||
local name = player:get_player_name()
|
||||
if fields.accept then
|
||||
if fields.accept then
|
||||
if interact.screen4 == false then
|
||||
if minetest.check_player_privs(name, interact.priv) then
|
||||
minetest.chat_send_player(name, interact.interact_msg1)
|
||||
minetest.chat_send_player(name, interact.interact_msg2)
|
||||
|
@ -76,15 +116,81 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
minetest.set_player_privs(name, privs)
|
||||
minetest.log("action", "Granted " ..name.. " interact.")
|
||||
end
|
||||
else
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "quiz", make_formspec4(player))
|
||||
end)
|
||||
end
|
||||
return
|
||||
elseif fields.decline then
|
||||
if interact.disagree_ban ~= true then
|
||||
minetest.kick_player(name, interact.disagree_msg)
|
||||
else
|
||||
minetest.ban_player(name)
|
||||
end
|
||||
elseif fields.decline then
|
||||
if interact.disagree_ban ~= true then
|
||||
minetest.kick_player(name, interact.disagree_msg)
|
||||
else
|
||||
minetest.ban_player(name)
|
||||
end
|
||||
return
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "quiz" then return end
|
||||
local name = player:get_player_name()
|
||||
if fields.rules then
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "rules", make_formspec3(player))
|
||||
end)
|
||||
return
|
||||
end
|
||||
if fields.rule1_true then rule1 = true
|
||||
elseif fields.rule1_false then rule1 = false
|
||||
elseif fields.rule2_true then rule2 = true
|
||||
elseif fields.rule2_false then rule2 = false
|
||||
elseif fields.rule3_true then rule3 = true
|
||||
elseif fields.rule3_false then rule3 = false
|
||||
elseif fields.rule4_true then rule4 = true
|
||||
elseif fields.rule4_false then rule4 = false
|
||||
elseif fields.multi_choice1 then multi = 1
|
||||
elseif fields.multi_choice2 then multi = 2
|
||||
elseif fields.multi_choice3 then multi = 3 end
|
||||
if fields.submit and rule1 == interact.quiz1 and rule2 == interact.quiz2 and
|
||||
rule3 == interact.quiz3 and rule4 == interact.quiz4 and multi == interact.quiz_multi then
|
||||
rule1 = 0
|
||||
rule2 = 0
|
||||
rule3 = 0
|
||||
rule4 = 0
|
||||
multi = 0
|
||||
if minetest.check_player_privs(name, interact.priv) then
|
||||
minetest.chat_send_player(name, interact.interact_msg1)
|
||||
minetest.chat_send_player(name, interact.interact_msg2)
|
||||
local privs = minetest.get_player_privs(name)
|
||||
privs.interact = true
|
||||
minetest.set_player_privs(name, privs)
|
||||
minetest.log("action", "Granted " ..name.. " interact.")
|
||||
end
|
||||
elseif fields.submit then
|
||||
rule1 = 0
|
||||
rule2 = 0
|
||||
rule3 = 0
|
||||
rule4 = 0
|
||||
multi = 0
|
||||
if interact.on_wrong_quiz == "kick" then
|
||||
minetest.kick_player(name, interact.wrong_quiz_kick_msg)
|
||||
elseif interact.on_wrong_quiz == "ban" then
|
||||
minetest.ban_player(name)
|
||||
elseif interact.on_wrong_quiz == "reshow" then
|
||||
minetest.chat_send_player(name, interact.quiz_try_again_msg)
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "quiz", make_formspec4(player))
|
||||
end)
|
||||
elseif interact.on_wrong_quiz == "rules" then
|
||||
minetest.chat_send_player(name, interact.quiz_rules_msg)
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "rules", make_formspec3(player))
|
||||
end)
|
||||
else
|
||||
minetest.chat_send_player(name, interact.quiz_fail_msg)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_chatcommand("rules",{
|
||||
|
@ -93,16 +199,32 @@ minetest.register_chatcommand("rules",{
|
|||
privs = interact.priv,
|
||||
func = function (name,params)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "welcome", make_formspec(player))
|
||||
end)
|
||||
if interact.screen1 ~= false then
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "welcome", make_formspec(player))
|
||||
end)
|
||||
elseif interact.screen2 ~= false then
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "visit", make_formspec2(player))
|
||||
end)
|
||||
else
|
||||
minetest.after(1, function()
|
||||
minetest.show_formspec(name, "rules", make_formspec3(player))
|
||||
end)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
if not minetest.get_player_privs(name).interact then
|
||||
minetest.show_formspec(name, "welcome", make_formspec(player))
|
||||
if interact.screen1 ~= false then
|
||||
minetest.show_formspec(name, "welcome", make_formspec(player))
|
||||
elseif interact.screen2 ~= false then
|
||||
minetest.show_formspec(name, "visit", make_formspec2(player))
|
||||
else
|
||||
minetest.show_formspec(name, "rules", make_formspec3(player))
|
||||
end
|
||||
else
|
||||
end
|
||||
end
|
||||
|
|
25
rules.lua
25
rules.lua
|
@ -10,3 +10,28 @@ Rules:
|
|||
6. Do not ask for more privs, or to be an admin. Also do not ask for items.
|
||||
7. PVP is not allowed.
|
||||
]]
|
||||
|
||||
--The questions on the rules, if the quiz is used.
|
||||
--The checkboxes for the first 4 questions are in config.lua
|
||||
interact.s4_question1 = "Is PVP is allowed?"
|
||||
interact.s4_question2 = "Is family roleplay allowed?"
|
||||
interact.s4_question3 = "Should you be nice to all players?"
|
||||
interact.s4_question4 = "Should you ask for all the privs you can?"
|
||||
interact.s4_multi_question = "Which of these is a rule?"
|
||||
|
||||
--The answers to the multiple choice questions. Only one of these should be true.
|
||||
interact.s4_multi1 = "No griefing!"
|
||||
interact.s4_multi2 = "PVP is allowed."
|
||||
interact.s4_multi3 = "Be rude to other players."
|
||||
|
||||
--Which answer is needed for the quiz questions. interact.quiz1-4 takes true or false.
|
||||
--True is left, false is right.
|
||||
--Please, please spell true and false right!!! If you spell it wrong it won't work!
|
||||
--interact.quiz can be 1, 2 or 3.
|
||||
--1 is the top one by the question, 2 is the bottom left one, 3 is the bottom right one.
|
||||
--Make sure these agree with your answers!
|
||||
interact.quiz1 = false
|
||||
interact.quiz2 = false
|
||||
interact.quiz3 = true
|
||||
interact.quiz4 = false
|
||||
interact.quiz_multi = 1
|
||||
|
|
Loading…
Reference in New Issue
Block a user