remove unecessary globals
This commit is contained in:
parent
fa12398332
commit
a7ee92feff
4 changed files with 40 additions and 35 deletions
|
|
@ -111,6 +111,8 @@ minetest.register_abm({
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- get protection radius
|
||||||
|
local r = tonumber(minetest.settings:get("protector_radius")) or 5
|
||||||
|
|
||||||
-- show protection areas of nearby protectors owned by you (thanks agaran)
|
-- show protection areas of nearby protectors owned by you (thanks agaran)
|
||||||
minetest.register_chatcommand("protector_show", {
|
minetest.register_chatcommand("protector_show", {
|
||||||
|
|
@ -121,7 +123,6 @@ minetest.register_chatcommand("protector_show", {
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local r = protector.radius
|
|
||||||
|
|
||||||
-- find the protector nodes
|
-- find the protector nodes
|
||||||
local pos = minetest.find_nodes_in_area(
|
local pos = minetest.find_nodes_in_area(
|
||||||
|
|
|
||||||
40
init.lua
40
init.lua
|
|
@ -8,14 +8,14 @@ local F = minetest.formspec_escape
|
||||||
protector = {}
|
protector = {}
|
||||||
protector.mod = "redo"
|
protector.mod = "redo"
|
||||||
protector.modpath = MP
|
protector.modpath = MP
|
||||||
protector.max_share_count = 12
|
|
||||||
protector.intllib = S
|
protector.intllib = S
|
||||||
|
|
||||||
|
local protector_max_share_count = 12
|
||||||
-- get minetest.conf settings
|
-- get minetest.conf settings
|
||||||
protector.radius = tonumber(minetest.settings:get("protector_radius")) or 5
|
local protector_radius = tonumber(minetest.settings:get("protector_radius")) or 5
|
||||||
protector.flip = minetest.settings:get_bool("protector_flip") or false
|
local protector_flip = minetest.settings:get_bool("protector_flip") or false
|
||||||
protector.hurt = tonumber(minetest.settings:get("protector_hurt")) or 0
|
local protector_hurt = tonumber(minetest.settings:get("protector_hurt")) or 0
|
||||||
protector.spawn = tonumber(minetest.settings:get("protector_spawn")
|
local 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
|
||||||
|
|
@ -74,7 +74,7 @@ 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
|
if #list >= protector_max_share_count then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -115,7 +115,7 @@ local protector_formspec = function(meta)
|
||||||
.. "field_close_on_enter[protector_add_member;false]"
|
.. "field_close_on_enter[protector_add_member;false]"
|
||||||
|
|
||||||
local members = get_member_list(meta)
|
local members = get_member_list(meta)
|
||||||
local npp = protector.max_share_count -- 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
|
||||||
|
|
@ -156,7 +156,7 @@ end
|
||||||
-- check if pos is inside a protected spawn area
|
-- check if pos is inside a protected spawn area
|
||||||
local inside_spawn = function(pos, radius)
|
local inside_spawn = function(pos, radius)
|
||||||
|
|
||||||
if protector.spawn <= 0 then
|
if protector_spawn <= 0 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -196,11 +196,11 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
||||||
if infolevel == 3 then infolevel = 1 end
|
if infolevel == 3 then infolevel = 1 end
|
||||||
|
|
||||||
-- is spawn area protected ?
|
-- is spawn area protected ?
|
||||||
if inside_spawn(pos, protector.spawn) then
|
if inside_spawn(pos, protector_spawn) then
|
||||||
|
|
||||||
minetest.chat_send_player(digger,
|
minetest.chat_send_player(digger,
|
||||||
S("Spawn @1 has been protected up to a @2 block radius.",
|
S("Spawn @1 has been protected up to a @2 block radius.",
|
||||||
minetest.pos_to_string(statspawn), protector.spawn))
|
minetest.pos_to_string(statspawn), protector_spawn))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
@ -274,19 +274,19 @@ function minetest.is_protected(pos, digger)
|
||||||
digger = digger or "" -- nil check
|
digger = digger or "" -- nil check
|
||||||
|
|
||||||
-- is area protected against digger?
|
-- is area protected against digger?
|
||||||
if not protector.can_dig(protector.radius, pos, digger, false, 1) then
|
if not protector.can_dig(protector_radius, pos, digger, false, 1) then
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(digger)
|
local player = minetest.get_player_by_name(digger)
|
||||||
|
|
||||||
if player and player:is_player() then
|
if player and player:is_player() then
|
||||||
|
|
||||||
-- hurt player if protection violated
|
-- hurt player if protection violated
|
||||||
if protector.hurt > 0 and player:get_hp() > 0 then
|
if protector_hurt > 0 and player:get_hp() > 0 then
|
||||||
player:set_hp(player:get_hp() - protector.hurt)
|
player:set_hp(player:get_hp() - protector_hurt)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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
|
||||||
|
|
@ -333,17 +333,17 @@ local check_overlap = function(itemstack, placer, pointed_thing)
|
||||||
local name = placer:get_player_name()
|
local name = placer:get_player_name()
|
||||||
|
|
||||||
-- make sure protector doesn't overlap onto protected spawn area
|
-- make sure protector doesn't overlap onto protected spawn area
|
||||||
if inside_spawn(pos, protector.spawn + protector.radius) then
|
if inside_spawn(pos, protector_spawn + protector_radius) then
|
||||||
|
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
S("Spawn @1 has been protected up to a @2 block radius.",
|
S("Spawn @1 has been protected up to a @2 block radius.",
|
||||||
minetest.pos_to_string(statspawn), protector.spawn))
|
minetest.pos_to_string(statspawn), protector_spawn))
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
-- make sure protector doesn't overlap any other player's area
|
-- make sure protector doesn't overlap any other player's area
|
||||||
if not protector.can_dig(protector.radius * 2, pos, name, true, 3) then
|
if not protector.can_dig(protector_radius * 2, pos, name, true, 3) then
|
||||||
|
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
S("Overlaps into above players protected area"))
|
S("Overlaps into above players protected area"))
|
||||||
|
|
@ -398,7 +398,7 @@ minetest.register_node("protector:protect", {
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
protector.can_dig(protector.radius, pointed_thing.under, user:get_player_name(), false, 2)
|
protector.can_dig(protector_radius, pointed_thing.under, user:get_player_name(), false, 2)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack)
|
on_rightclick = function(pos, node, clicker, itemstack)
|
||||||
|
|
@ -482,7 +482,7 @@ minetest.register_node("protector:protect2", {
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
protector.can_dig(protector.radius, pointed_thing.under, user:get_player_name(), false, 2)
|
protector.can_dig(protector_radius, pointed_thing.under, user:get_player_name(), false, 2)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack)
|
on_rightclick = function(pos, node, clicker, itemstack)
|
||||||
|
|
@ -621,7 +621,7 @@ minetest.register_entity("protector:display", {
|
||||||
-- Display-zone node, Do NOT place the display as a node,
|
-- Display-zone node, Do NOT place the display as a node,
|
||||||
-- it is made to be used as an entity (see above)
|
-- it is made to be used as an entity (see above)
|
||||||
|
|
||||||
local x = protector.radius
|
local x = protector_radius
|
||||||
minetest.register_node("protector:display_node", {
|
minetest.register_node("protector:display_node", {
|
||||||
tiles = {"protector_display.png"},
|
tiles = {"protector_display.png"},
|
||||||
use_texture_alpha = true,
|
use_texture_alpha = true,
|
||||||
|
|
|
||||||
24
pvp.lua
24
pvp.lua
|
|
@ -5,14 +5,16 @@ local S = protector.intllib
|
||||||
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}
|
||||||
|
|
||||||
-- is pvp protection enabled
|
-- is spawn protected
|
||||||
protector.pvp = minetest.settings:get_bool("protector_pvp")
|
local protector_spawn = tonumber(minetest.settings:get("protector_spawn")
|
||||||
|
or minetest.settings:get("protector_pvp_spawn")) or 0
|
||||||
|
|
||||||
-- is night-only pvp enabled
|
-- is night-only pvp enabled
|
||||||
protector.night_pvp = minetest.settings:get_bool("protector_night_pvp")
|
local protector_night_pvp = minetest.settings:get_bool("protector_night_pvp")
|
||||||
|
|
||||||
-- disables PVP in your own protected areas
|
-- disables PVP in your own protected areas
|
||||||
if minetest.settings:get_bool("enable_pvp") and protector.pvp then
|
if minetest.settings:get_bool("enable_pvp")
|
||||||
|
and minetest.settings:get_bool("protector_pvp") then
|
||||||
|
|
||||||
if minetest.register_on_punchplayer then
|
if minetest.register_on_punchplayer then
|
||||||
|
|
||||||
|
|
@ -31,17 +33,17 @@ if minetest.settings:get_bool("enable_pvp") and protector.pvp then
|
||||||
-- no pvp at spawn area
|
-- no pvp at spawn area
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
|
||||||
if pos.x < statspawn.x + protector.spawn
|
if pos.x < statspawn.x + protector_spawn
|
||||||
and pos.x > statspawn.x - protector.spawn
|
and pos.x > statspawn.x - protector_spawn
|
||||||
and pos.y < statspawn.y + protector.spawn
|
and pos.y < statspawn.y + protector_spawn
|
||||||
and pos.y > statspawn.y - protector.spawn
|
and pos.y > statspawn.y - protector_spawn
|
||||||
and pos.z < statspawn.z + protector.spawn
|
and pos.z < statspawn.z + protector_spawn
|
||||||
and pos.z > statspawn.z - protector.spawn then
|
and pos.z > statspawn.z - protector_spawn then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- do we enable pvp at night time only ?
|
-- do we enable pvp at night time only ?
|
||||||
if protector.night_pvp then
|
if protector_night_pvp then
|
||||||
|
|
||||||
-- get time of day
|
-- get time of day
|
||||||
local tod = minetest.get_timeofday() or 0
|
local tod = minetest.get_timeofday() or 0
|
||||||
|
|
|
||||||
8
tool.lua
8
tool.lua
|
|
@ -1,6 +1,9 @@
|
||||||
|
|
||||||
-- protector placement tool (thanks to Shara for code and idea)
|
-- protector placement tool (thanks to Shara for code and idea)
|
||||||
|
|
||||||
|
-- get protection radius
|
||||||
|
local r = tonumber(minetest.settings:get("protector_radius")) or 5
|
||||||
|
|
||||||
minetest.register_craftitem("protector:tool", {
|
minetest.register_craftitem("protector:tool", {
|
||||||
description = "Protector Placer Tool (stand near protector, face direction and use)",
|
description = "Protector Placer Tool (stand near protector, face direction and use)",
|
||||||
inventory_image = "protector_display.png^protector_logo.png",
|
inventory_image = "protector_display.png^protector_logo.png",
|
||||||
|
|
@ -27,7 +30,7 @@ minetest.register_craftitem("protector:tool", {
|
||||||
-- get direction player is facing
|
-- get direction player is facing
|
||||||
local dir = minetest.dir_to_facedir( user:get_look_dir() )
|
local dir = minetest.dir_to_facedir( user:get_look_dir() )
|
||||||
local vec = {x = 0, y = 0, z = 0}
|
local vec = {x = 0, y = 0, z = 0}
|
||||||
local gap = (protector.radius * 2) + 1
|
local gap = (r * 2) + 1
|
||||||
local pit = user:get_look_pitch()
|
local pit = user:get_look_pitch()
|
||||||
|
|
||||||
-- set placement coords
|
-- set placement coords
|
||||||
|
|
@ -51,8 +54,7 @@ minetest.register_craftitem("protector:tool", {
|
||||||
pos.z = pos.z + vec.z
|
pos.z = pos.z + vec.z
|
||||||
|
|
||||||
-- does placing a protector overlap existing area
|
-- does placing a protector overlap existing area
|
||||||
if not protector.can_dig(protector.radius * 2, pos,
|
if not protector.can_dig(r * 2, pos, user:get_player_name(), true, 3) then
|
||||||
user:get_player_name(), true, 3) then
|
|
||||||
|
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
"Overlaps into above players protected area")
|
"Overlaps into above players protected area")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue