summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README4
-rw-r--r--depends.txt0
-rw-r--r--init.lua148
3 files changed, 152 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..a5ba81e
--- /dev/null
+++ b/README
@@ -0,0 +1,4 @@
+This mod adds a form containing the rules that is shown to players without interact when they join. They are also teleported to a special spawn point designated for players without interact.
+If they press "I agree", they are teleported to the normal spawn. The /spawn command will also take them back there (or to the non-interact spawn if they don't have interact).
+If they press "I do not agree", they are allowed to play normally (but without interact), although bright red text will be placed in the middle of the screen explaining the situation.
+At any point, the /rules command will show the rules. The /set_interact_spawn and /set_no_interact_spawn commands (requiring the server priv) will set the respective spawn point to your current location.
diff --git a/depends.txt b/depends.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/depends.txt
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000..5b4cad2
--- /dev/null
+++ b/init.lua
@@ -0,0 +1,148 @@
+newplayer = {}
+
+newplayer.hudids = {}
+
+local f = io.open(minetest.get_modpath("newplayer")..DIR_DELIM.."rules.txt","r")
+if f then
+ local d = f:read("*all")
+ newplayer.rules = minetest.formspec_escape(d)
+ f:close()
+else
+ newplayer.rules = "Rules file not found!\n\nThe file should be named \"rules.txt\" and placed in the following location:\n\n"..minetest.get_modpath("newplayer")..DIR_DELIM
+end
+
+function newplayer.showrulesform(name)
+ local form_interact = "size[8,9]"..
+ "label[0,0;Server Rules]"..
+ "textarea[0.25,1;8,7;rules;;"..newplayer.rules.."]"..
+ "button_exit[3,8;2,1;quit;OK]"
+ local form_nointeract = "size[8,9]"..
+ "label[0,0;Server Rules]"..
+ "textarea[0.25,1;8,7;rules;;"..newplayer.rules.."]"..
+ "button[1,8;2,1;yes;I agree]"..
+ "button[5,8;2,1;no;I do not agree]"
+ local hasinteract = minetest.check_player_privs(name,{interact=true})
+ if hasinteract then
+ minetest.show_formspec(name,"newplayer:rules_interact",form_interact)
+ else
+ minetest.show_formspec(name,"newplayer:rules_nointeract",form_nointeract)
+ end
+end
+
+minetest.register_on_joinplayer(function(player)
+ local name = player:get_player_name()
+ if minetest.check_player_privs(name,{interact=true}) then
+ return
+ end
+ local nointeractspawn = minetest.setting_get_pos("spawnpoint_no_interact")
+ if nointeractspawn then
+ player:setpos(nointeractspawn)
+ end
+ newplayer.hudids[name] = player:hud_add({
+ hud_elem_type = "text",
+ position = {x=0.5,y=0.5},
+ scale = {x=100,y=100},
+ text = "BUILDING DISABLED\nYou must agree to\nthe rules before building!\nUse the /rules command\nto see them.",
+ number = 0xFF6666,
+ alignment = {x=0,y=0},
+ offset = {x=0,y=0}
+ })
+ minetest.after(3,newplayer.showrulesform,name)
+end)
+
+minetest.register_on_player_receive_fields(function(player,formname,fields)
+ if formname ~= "newplayer:rules_nointeract" then
+ return false
+ end
+ local name = player:get_player_name()
+ if fields.quit then
+ newplayer.showrulesform(name)
+ elseif fields.yes then
+ local privs = minetest.get_player_privs(name)
+ privs.interact = true
+ minetest.set_player_privs(name,privs)
+ if newplayer.hudids[name] then
+ minetest.get_player_by_name(name):hud_remove(newplayer.hudids[name])
+ newplayer.hudids[name] = nil
+ end
+ local spawn = minetest.setting_get_pos("spawnpoint_interact")
+ if spawn then
+ minetest.chat_send_player(name,"Teleporting to spawn...")
+ player:setpos(spawn)
+ else
+ minetest.chat_send_player(name,"ERROR: The spawn point is not set!")
+ end
+ local form = "size[5,3]"..
+ "label[1,0;Thank you for agreeing]"..
+ "label[1,0.5;to the rules!]"..
+ "label[1,1;You are now free to play normally.]"..
+ "label[1,1.5;You can also use /spawn to return here.]"..
+ "button_exit[1.5,2;2,1;quit;OK]"
+ minetest.show_formspec(name,"newplayer:agreethanks",form)
+ elseif fields.no then
+ local form = "size[5,3]"..
+ "label[1,0;You may remain on the server\,]"..
+ "label[1,0.5;but you may not dig or build]"..
+ "label[1,1;until you agree to the rules.]"..
+ "button_exit[1.5,2;2,1;quit;OK]"
+ minetest.show_formspec(name,"newplayer:disagreewarning",form)
+ end
+ return true
+end)
+
+minetest.register_chatcommand("rules",{
+ params = "",
+ description = "View the rules",
+ func = newplayer.showrulesform
+ }
+)
+
+minetest.register_chatcommand("set_no_interact_spawn",{
+ params = "",
+ description = "Set the spawn point for players without interact to your current position",
+ privs = {server=true},
+ func = function(name)
+ local pos = minetest.get_player_by_name(name):getpos()
+ minetest.setting_set("spawnpoint_no_interact",string.format("%s,%s,%s",pos.x,pos.y,pos.z))
+ minetest.setting_save()
+ minetest.chat_send_player(name,"Spawn point for players without interact set to: "..minetest.pos_to_string(pos))
+ end}
+)
+
+minetest.register_chatcommand("set_interact_spawn",{
+ params = "",
+ description = "Set the spawn point for players with interact to your current position",
+ privs = {server=true},
+ func = function(name)
+ local pos = minetest.get_player_by_name(name):getpos()
+ minetest.setting_set("spawnpoint_interact",string.format("%s,%s,%s",pos.x,pos.y,pos.z))
+ minetest.setting_save()
+ minetest.chat_send_player(name,"Spawn point for players with interact set to: "..minetest.pos_to_string(pos))
+ end}
+)
+
+minetest.register_chatcommand("spawn",{
+ params = "",
+ description = "Teleport to the spawn",
+ func = function(name)
+ local hasinteract = minetest.check_player_privs(name,{interact=true})
+ local player = minetest.get_player_by_name(name)
+ if hasinteract then
+ local pos = minetest.setting_get_pos("spawnpoint_interact")
+ if pos then
+ minetest.chat_send_player(name,"Teleporting to spawn...")
+ player:setpos(pos)
+ else
+ minetest.chat_send_player(name,"ERROR: The spawn point is not set!")
+ end
+ else
+ local pos = minetest.setting_get_pos("spawnpoint_no_interact")
+ if pos then
+ minetest.chat_send_player(name,"Teleporting to spawn...")
+ player:setpos(pos)
+ else
+ minetest.chat_send_player(name,"ERROR: The spawn point is not set!")
+ end
+ end
+ end}
+)