Add simple rules mod
This commit is contained in:
parent
d945c5002b
commit
277ada0bdc
4 changed files with 96 additions and 134 deletions
|
@ -1,69 +0,0 @@
|
|||
join_fs = {
|
||||
slides = {},
|
||||
players = {}
|
||||
}
|
||||
|
||||
function join_fs.load()
|
||||
local filepath = minetest.get_worldpath() .. "/join_fs.txt"
|
||||
local file = io.open(filepath, "r")
|
||||
if file then
|
||||
local table = minetest.deserialize(file:read("*all"))
|
||||
if type(table) == "table" then
|
||||
join_fs.players = table.players
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function join_fs.save()
|
||||
local filepath = minetest.get_worldpath() .. "/join_fs.txt"
|
||||
local file = io.open(filepath, "w")
|
||||
if file then
|
||||
file:write(minetest.serialize({
|
||||
players = join_fs.players
|
||||
}))
|
||||
file:close()
|
||||
else
|
||||
minetest.log("warning", "Failed to save join_fs player config!")
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
join_fs.save()
|
||||
end)
|
||||
|
||||
function join_fs.confirm(name, sname)
|
||||
local player = join_fs.players[name]
|
||||
if not player then
|
||||
player = {}
|
||||
join_fs.players[name] = player
|
||||
end
|
||||
player[sname] = true
|
||||
join_fs.save()
|
||||
end
|
||||
|
||||
function join_fs.register_slide(def)
|
||||
table.insert(join_fs.slides, def)
|
||||
return def.name
|
||||
end
|
||||
|
||||
function join_fs.show_next_slide(player)
|
||||
for _, def in pairs(join_fs.slides) do
|
||||
local pids = join_fs.players[player:get_player_name()] or {}
|
||||
if def.should_show(player, pids[def.name]) then
|
||||
def.show(player)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
join_fs.load()
|
||||
minetest.register_on_joinplayer(function (player)
|
||||
local name = player:get_player_name()
|
||||
minetest.after(0.5, function()
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
join_fs.show_next_slide(player)
|
||||
end
|
||||
end)
|
||||
end)
|
|
@ -1 +0,0 @@
|
|||
shooter
|
|
@ -1,64 +0,0 @@
|
|||
dofile(minetest.get_modpath("join_fs") .. "/api.lua")
|
||||
|
||||
-- Rules slide from agreerules
|
||||
|
||||
join_fs.register_slide({
|
||||
name = "rules",
|
||||
should_show = function(player, has_been_shown_before)
|
||||
return not minetest.check_player_privs(player:get_player_name(), {interact=true})
|
||||
end,
|
||||
show = function(player)
|
||||
local msgs = {
|
||||
"Welcome to Capture the Flag!",
|
||||
"Developed, hosted, and moderated by rubenwardy.",
|
||||
" tip: use /vote_next to skip to the next round",
|
||||
",By playing on this server you agree to these rules:",
|
||||
"1. Be nice. eg: No (excessive or bad) swearing",
|
||||
"2. No dating",
|
||||
"3. Don't be a cheater",
|
||||
" (No hacked clients or griefing/sabotage of team)",
|
||||
"4. Don't impersonate other community members",
|
||||
"Failure to follow these rules may result in a kick or ban",
|
||||
" (temp or permanent) depending on severity."}
|
||||
|
||||
local fs = ""
|
||||
for _, line in pairs(msgs) do
|
||||
if fs ~= "" then
|
||||
fs = fs .. ","
|
||||
end
|
||||
fs = fs .. minetest.formspec_escape(line)
|
||||
end
|
||||
|
||||
fs = "size[8,9] textlist[0.1,0.1;7.8,7;rules;" .. fs .. "]"
|
||||
fs = fs .. " button_exit[0.5,7;3.5,2;yes;" ..
|
||||
minetest.formspec_escape("Yes, let me play!") .. "]"
|
||||
fs = fs .. " button[4,7;3.5,2;no;" ..
|
||||
minetest.formspec_escape("No, get me out of here!") .. "]"
|
||||
minetest.show_formspec(player:get_player_name(), "join_fs:rules", fs)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, form, fields)
|
||||
if form == "join_fs:rules" then
|
||||
local name = player:get_player_name()
|
||||
|
||||
if fields.rules then
|
||||
return true
|
||||
elseif not fields.yes or fields.no then
|
||||
minetest.kick_player(name,
|
||||
"You need to agree to the rules to play on this server. " ..
|
||||
"Please rejoin and confirm another time.")
|
||||
return true
|
||||
end
|
||||
|
||||
local privs = minetest.get_player_privs(name)
|
||||
privs.shout = true
|
||||
privs.interact = true
|
||||
|
||||
minetest.set_player_privs(name, privs)
|
||||
minetest.chat_send_player(name, "Welcome "..name.."! You have now permission to play!")
|
||||
|
||||
join_fs.confirm(name, "rules")
|
||||
join_fs.show_next_slide(player)
|
||||
end
|
||||
end)
|
96
mods/rules/init.lua
Normal file
96
mods/rules/init.lua
Normal file
|
@ -0,0 +1,96 @@
|
|||
-- Rules slide from agreerules
|
||||
|
||||
rules = {}
|
||||
function rules.show(player)
|
||||
local msgs = {
|
||||
"Welcome to Capture the Flag!",
|
||||
"Developed and hosted by rubenwardy.",
|
||||
"Moderators: Kpenguin, Thomas-S, Dragonop,",
|
||||
" stormchaser3000, Calinou.",
|
||||
" tip: use /vote to skip to the next round",
|
||||
",By playing on this server you agree to these rules:",
|
||||
"1. Be nice. eg: No (excessive or bad) swearing",
|
||||
"2. No dating.",
|
||||
"3. Don't be a cheater. No hacked clients.",
|
||||
"4. Don't be a traitor. Don't:",
|
||||
" a. Dig blocks in your base to make it less secure or",
|
||||
" to trap team mates on purpuse.",
|
||||
" b. Help the other team.",
|
||||
"5. Don't impersonate other community members",
|
||||
"Failure to follow these rules may result in a kick or ban",
|
||||
" (temp or permanent) depending on severity."}
|
||||
|
||||
local fs = ""
|
||||
for _, line in pairs(msgs) do
|
||||
if fs ~= "" then
|
||||
fs = fs .. ","
|
||||
end
|
||||
fs = fs .. minetest.formspec_escape(line)
|
||||
end
|
||||
|
||||
|
||||
fs = "size[8,8]textlist[0.1,0.1;7.8,6;msg;" .. fs .. "]"
|
||||
if minetest.check_player_privs(player:get_player_name(), { interact = true }) then
|
||||
fs = fs .. "button_exit[0.5,6;7,2;yes;Okay]"
|
||||
else
|
||||
local yes = minetest.formspec_escape("Yes, let me play!")
|
||||
local no = minetest.formspec_escape("No, get me out of here!")
|
||||
|
||||
fs = fs .. "button_exit[0.5,6;3.5,2;no;" .. no .. "]"
|
||||
fs = fs .. "button_exit[4,6;3.5,2;yes;" .. yes .. "]"
|
||||
end
|
||||
|
||||
minetest.show_formspec(player:get_player_name(), "rules:rules", fs)
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("rules", {
|
||||
func = function(name, param)
|
||||
if param ~= "" and
|
||||
minetest.check_player_privs(name, { kick = true }) then
|
||||
name = param
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
rules.show(player)
|
||||
return true, "Rules shown."
|
||||
else
|
||||
return false, "Player " .. name .. " does not exist or is not online"
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
if not minetest.check_player_privs(player:get_player_name(), { interact = true }) then
|
||||
rules.show(player)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, form, fields)
|
||||
if form ~= "rules:rules" then
|
||||
return
|
||||
end
|
||||
|
||||
local name = player:get_player_name()
|
||||
if minetest.check_player_privs(name, { interact = true }) then
|
||||
return true
|
||||
end
|
||||
|
||||
if fields.msg then
|
||||
return true
|
||||
elseif not fields.yes or fields.no then
|
||||
minetest.kick_player(name,
|
||||
"You need to agree to the rules to play on this server. " ..
|
||||
"Please rejoin and confirm another time.")
|
||||
return true
|
||||
end
|
||||
|
||||
local privs = minetest.get_player_privs(name)
|
||||
privs.shout = true
|
||||
privs.interact = true
|
||||
minetest.set_player_privs(name, privs)
|
||||
|
||||
minetest.chat_send_player(name, "Welcome "..name.."! You have now permission to play!")
|
||||
|
||||
return true
|
||||
end)
|
Loading…
Reference in a new issue