Add join_fs: rules, disable/enable blood

This commit is contained in:
rubenwardy 2015-12-06 00:02:51 +00:00
parent 304799fde6
commit 58a785b1dd
5 changed files with 258 additions and 11 deletions

69
mods/join_fs/api.lua Normal file
View file

@ -0,0 +1,69 @@
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 not pids[def.name] and def.should_show(player) 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
mods/join_fs/depends.txt Normal file
View file

@ -0,0 +1 @@
shooter

100
mods/join_fs/init.lua Normal file
View file

@ -0,0 +1,100 @@
dofile(minetest.get_modpath("join_fs") .. "/api.lua")
-- Rules slide from agreerules
join_fs.register_slide({
name = "rules",
should_show = function(player)
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)
local slide_blood = join_fs.register_slide({
name = "blood",
should_show = function(player)
return true
end,
show = function(player)
local fs = "size[8,1.75]label[0,0;Would you like to see blood splatters when using a gun?]"
fs = fs .. " button_exit[0.5,0.5;3.5,2;yes;" ..
minetest.formspec_escape("Yes: Enable blood") .. "]"
fs = fs .. " button_exit[4,0.5;3.5,2;no;" ..
minetest.formspec_escape("No: Disable blood") .. "]"
minetest.show_formspec(player:get_player_name(), "join_fs:blood", fs)
end
})
minetest.register_on_player_receive_fields(function(player, form, fields)
if form == "join_fs:blood" then
local name = player:get_player_name()
if fields.yes then
shooter:enable_blood(name)
minetest.chat_send_player(name, "You have choosen to see blood!")
elseif fields.no then
shooter:disable_blood(name)
minetest.chat_send_player(name, "You will no longer see blood!")
else
minetest.chat_send_player(name, "You need to choose an option!")
join_fs.show_next_slide(player)
return true
end
join_fs.confirm(name, "blood")
join_fs.show_next_slide(player)
end
end)

View file

@ -23,3 +23,5 @@ end
if SHOOTER_ENABLE_TURRETS == true then if SHOOTER_ENABLE_TURRETS == true then
dofile(modpath.."/turret.lua") dofile(modpath.."/turret.lua")
end end
shooter:load_player_config()

View file

@ -5,6 +5,7 @@ shooter = {
shots = {}, shots = {},
update_time = 0, update_time = 0,
reload_time = 0, reload_time = 0,
players_enabled_blood = {}
} }
SHOOTER_ADMIN_WEAPONS = false SHOOTER_ADMIN_WEAPONS = false
@ -70,18 +71,92 @@ local function get_particle_pos(p, v, d)
return vector.add(p, vector.multiply(v, {x=d, y=d, z=d})) return vector.add(p, vector.multiply(v, {x=d, y=d, z=d}))
end end
function shooter:spawn_particles(pos, texture) function shooter:load_player_config()
if SHOOTER_ENABLE_PARTICLE_FX == true then local filepath = minetest.get_worldpath() .. "/shooter_player_config.txt"
if type(texture) ~= "string" then local file = io.open(filepath, "r")
texture = SHOOTER_EXPLOSION_TEXTURE if file then
local table = minetest.deserialize(file:read("*all"))
if type(table) == "table" then
self.players_enabled_blood = table.eblood
return
end end
local spread = {x=0.1, y=0.1, z=0.1} end
minetest.add_particlespawner(15, 0.3, end
vector.subtract(pos, spread), vector.add(pos, spread),
{x=-1, y=1, z=-1}, {x=1, y=2, z=1}, function shooter:save_player_config()
{x=-2, y=-2, z=-2}, {x=2, y=-2, z=2}, local filepath = minetest.get_worldpath() .. "/shooter_player_config.txt"
0.1, 0.75, 1, 2, false, texture local file = io.open(filepath, "w")
) if file then
file:write(minetest.serialize({
eblood = self.players_enabled_blood
}))
file:close()
else
minetest.log("warning", "Failed to save shooter player config!")
end
end
minetest.register_on_shutdown(function()
shooter:save_player_config()
end)
function shooter:enable_blood(name)
self.players_enabled_blood[name] = true
end
function shooter:disable_blood(name)
self.players_enabled_blood[name] = nil
end
function shooter:spawn_particles(pos, texture)
if not SHOOTER_ENABLE_PARTICLE_FX then
return
end
if type(texture) ~= "string" then
texture = SHOOTER_EXPLOSION_TEXTURE
end
local spread = {x=0.1, y=0.1, z=0.1}
if texture == SHOOTER_EXPLOSION_TEXTURE then
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
if shooter.players_enabled_blood[name] then
minetest.add_particlespawner({
amount = 15,
time = 0.3,
minpos = vector.subtract(pos, spread),
maxpos = vector.add(pos, spread),
minvel = {x=-1, y=1, z=-1},
maxvel = {x=1, y=2, z=1},
minacc = {x=-2, y=-2, z=-2},
maxacc = {x=2, y=-2, z=2},
minexptime = 0.1,
maxexptime = 0.75,
minsize = 1,
maxsize = 2,
collisiondetection = false,
texture = texture,
playername = name
})
end
end
else
minetest.add_particlespawner({
amount = 15,
time = 0.3,
minpos = vector.subtract(pos, spread),
maxpos = vector.add(pos, spread),
minvel = {x=-1, y=1, z=-1},
maxvel = {x=1, y=2, z=1},
minacc = {x=-2, y=-2, z=-2},
maxacc = {x=2, y=-2, z=2},
minexptime = 0.1,
maxexptime = 0.75,
minsize = 1,
maxsize = 2,
collisiondetection = false,
texture = texture
})
end end
end end