mirror of
https://notabug.org/TenPlus1/protector.git
synced 2025-01-10 09:07:30 +01:00
code tidy and tweak (thanks Krock)
This commit is contained in:
parent
dacab4f038
commit
edb6f448de
43
init.lua
43
init.lua
@ -1,14 +1,15 @@
|
|||||||
|
|
||||||
-- get minetest.conf settings
|
|
||||||
protector = {}
|
protector = {}
|
||||||
protector.mod = "redo"
|
protector.mod = "redo"
|
||||||
|
protector.max_share_count = 12
|
||||||
|
|
||||||
|
-- get minetest.conf settings
|
||||||
protector.radius = tonumber(minetest.settings:get("protector_radius")) or 5
|
protector.radius = tonumber(minetest.settings:get("protector_radius")) or 5
|
||||||
protector.flip = minetest.settings:get_bool("protector_flip") or false
|
protector.flip = minetest.settings:get_bool("protector_flip") or false
|
||||||
protector.hurt = tonumber(minetest.settings:get("protector_hurt")) or 0
|
protector.hurt = tonumber(minetest.settings:get("protector_hurt")) or 0
|
||||||
protector.spawn = tonumber(minetest.settings:get("protector_spawn")
|
protector.spawn = tonumber(minetest.settings:get("protector_spawn")
|
||||||
or minetest.settings:get("protector_pvp_spawn")) or 0
|
or minetest.settings:get("protector_pvp_spawn")) or 0
|
||||||
|
|
||||||
|
|
||||||
-- get static spawn position
|
-- get static spawn position
|
||||||
local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint"))
|
local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint"))
|
||||||
or {x = 0, y = 2, z = 0}
|
or {x = 0, y = 2, z = 0}
|
||||||
@ -67,6 +68,11 @@ end
|
|||||||
-- add player name to table as member
|
-- add player name to table as member
|
||||||
local add_member = function(meta, name)
|
local add_member = function(meta, name)
|
||||||
|
|
||||||
|
-- Constant (20) defined by player.h
|
||||||
|
if name:len() > 25 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- does name already exist?
|
-- does name already exist?
|
||||||
if is_owner(meta, name)
|
if is_owner(meta, name)
|
||||||
or is_member(meta, name) then
|
or is_member(meta, name) then
|
||||||
@ -75,6 +81,10 @@ local add_member = function(meta, name)
|
|||||||
|
|
||||||
local list = get_member_list(meta)
|
local list = get_member_list(meta)
|
||||||
|
|
||||||
|
if #list >= protector.max_share_count then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(list, name)
|
table.insert(list, name)
|
||||||
|
|
||||||
set_member_list(meta, list)
|
set_member_list(meta, list)
|
||||||
@ -111,7 +121,7 @@ local protector_formspec = function(meta)
|
|||||||
.. "button_exit[2.5,6.2;3,0.5;close_me;" .. S("Close") .. "]"
|
.. "button_exit[2.5,6.2;3,0.5;close_me;" .. S("Close") .. "]"
|
||||||
|
|
||||||
local members = get_member_list(meta)
|
local members = get_member_list(meta)
|
||||||
local npp = 12 -- max users added to protector list
|
local npp = protector.max_share_count -- max users added to protector list
|
||||||
local i = 0
|
local i = 0
|
||||||
|
|
||||||
for n = 1, #members do
|
for n = 1, #members do
|
||||||
@ -282,20 +292,18 @@ function minetest.is_protected(pos, digger)
|
|||||||
|
|
||||||
-- flip player when protection violated
|
-- flip player when protection violated
|
||||||
if protector.flip then
|
if protector.flip then
|
||||||
|
|
||||||
-- yaw + 180°
|
-- yaw + 180°
|
||||||
local yaw = player:get_look_horizontal() + math.pi
|
local yaw = player:get_look_horizontal() + math.pi
|
||||||
--local yaw = player:get_look_yaw() + math.pi
|
|
||||||
|
|
||||||
if yaw > 2 * math.pi then
|
if yaw > 2 * math.pi then
|
||||||
yaw = yaw - 2 * math.pi
|
yaw = yaw - 2 * math.pi
|
||||||
end
|
end
|
||||||
|
|
||||||
--player:set_look_horizontal(yaw)
|
player:set_look_horizontal(yaw)
|
||||||
player:set_look_yaw(yaw)
|
|
||||||
|
|
||||||
-- invert pitch
|
-- invert pitch
|
||||||
player:set_look_vertical(-player:get_look_vertical())
|
player:set_look_vertical(-player:get_look_vertical())
|
||||||
--player:set_look_pitch(-player:get_look_pitch())
|
|
||||||
|
|
||||||
-- if digging below player, move up to avoid falling through hole
|
-- if digging below player, move up to avoid falling through hole
|
||||||
local pla_pos = player:get_pos()
|
local pla_pos = player:get_pos()
|
||||||
@ -530,13 +538,20 @@ minetest.register_craft({
|
|||||||
-- check formspec buttons or when name entered
|
-- check formspec buttons or when name entered
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
|
||||||
if formname == "protector:node" then
|
if formname ~= "protector:node" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local pos = player_pos[name]
|
local pos = player_pos[name]
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
|
|
||||||
if not name or not pos or not meta then
|
if not name or not pos then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- reset formspec until close button pressed
|
||||||
|
if fields.close_me or fields.quit then
|
||||||
|
player_pos[name] = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -553,6 +568,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
-- add member [+]
|
-- add member [+]
|
||||||
if fields.protector_add_member then
|
if fields.protector_add_member then
|
||||||
|
|
||||||
@ -572,13 +589,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset formspec until close button pressed
|
|
||||||
if not fields.close_me and not fields.quit then
|
|
||||||
minetest.show_formspec(name, formname, protector_formspec(meta))
|
minetest.show_formspec(name, formname, protector_formspec(meta))
|
||||||
else
|
|
||||||
player_pos[name] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user