mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2024-08-20 13:14:04 +02:00
change a bit code
This commit is contained in:
parent
7877d8ac92
commit
708c8b045a
@ -2,8 +2,7 @@
|
|||||||
-- Detects players in a certain radius
|
-- Detects players in a certain radius
|
||||||
-- The radius can be changes by right-click (by default 6)
|
-- The radius can be changes by right-click (by default 6)
|
||||||
|
|
||||||
local object_detector_make_formspec = function (pos)
|
local function make_formspec(meta)
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("formspec", "size[9,5]" ..
|
meta:set_string("formspec", "size[9,5]" ..
|
||||||
"field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]"..
|
"field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]"..
|
||||||
"field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]"..
|
"field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]"..
|
||||||
@ -11,26 +10,41 @@ local object_detector_make_formspec = function (pos)
|
|||||||
"button_exit[3.5,3.5;2,3;;Save]")
|
"button_exit[3.5,3.5;2,3;;Save]")
|
||||||
end
|
end
|
||||||
|
|
||||||
local object_detector_on_receive_fields = function(pos, formname, fields)
|
local function object_detector_make_formspec(pos)
|
||||||
if not fields.scanname or not fields.digiline_channel then return end;
|
make_formspec(minetest.get_meta(pos))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function object_detector_on_receive_fields(pos, formname, fields)
|
||||||
|
if not fields.scanname
|
||||||
|
or not fields.digiline_channel then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("scanname", fields.scanname)
|
meta:set_string("scanname", fields.scanname)
|
||||||
meta:set_string("digiline_channel", fields.digiline_channel)
|
meta:set_string("digiline_channel", fields.digiline_channel)
|
||||||
if tonumber(fields.radius) then meta:set_int("radius", tonumber(fields.radius)) end
|
local r = tonumber(fields.radius)
|
||||||
object_detector_make_formspec(pos)
|
if r then
|
||||||
|
meta:set_int("radius", r)
|
||||||
|
end
|
||||||
|
if not meta:get_string("formspec") then
|
||||||
|
make_formspec(meta)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns true if player was found, false if not
|
-- returns true if player was found, false if not
|
||||||
local object_detector_scan = function (pos)
|
local object_detector_scan = function (pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
local scanname = meta:get_string("scanname")
|
||||||
|
local scan_all = scanname == ""
|
||||||
local radius = meta:get_int("radius")
|
local radius = meta:get_int("radius")
|
||||||
if radius == 0 then radius = 6 end
|
if radius == 0 then
|
||||||
local objs = minetest.get_objects_inside_radius(pos, radius)
|
radius = 6
|
||||||
for k, obj in pairs(objs) do
|
end
|
||||||
|
for _,obj in pairs(minetest.get_objects_inside_radius(pos, radius)) do
|
||||||
local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil!
|
local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil!
|
||||||
local scanname = meta:get_string("scanname")
|
if isname ~= ""
|
||||||
if (isname == scanname and isname ~= "") or (isname ~= "" and scanname == "") then -- player with scanname found or not scanname specified
|
and (scan_all or isname == scanname) then -- player with scanname found or not scanname specified
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -43,9 +57,12 @@ local object_detector_digiline = {
|
|||||||
action = function (pos, node, channel, msg)
|
action = function (pos, node, channel, msg)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local active_channel = meta:get_string("digiline_channel")
|
local active_channel = meta:get_string("digiline_channel")
|
||||||
if channel == active_channel then
|
if channel ~= active_channel then
|
||||||
meta:set_string("scanname", msg)
|
return
|
||||||
object_detector_make_formspec(pos)
|
end
|
||||||
|
meta:set_string("scanname", msg)
|
||||||
|
if not meta:get_string("formspec") then
|
||||||
|
make_formspec(meta)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
@ -2,50 +2,56 @@ local kill_nearest_player = function(pos)
|
|||||||
local MAX_DISTANCE = 8 -- Use this number to set maximal distance to kill
|
local MAX_DISTANCE = 8 -- Use this number to set maximal distance to kill
|
||||||
|
|
||||||
-- Search the nearest player
|
-- Search the nearest player
|
||||||
local nearest = nil
|
local nearest
|
||||||
local min_distance = math.huge
|
local min_distance = MAX_DISTANCE
|
||||||
local players = minetest.get_connected_players()
|
for index, player in pairs(minetest.get_connected_players()) do
|
||||||
for index, player in pairs(players) do
|
|
||||||
local distance = vector.distance(pos, player:getpos())
|
local distance = vector.distance(pos, player:getpos())
|
||||||
if distance < min_distance then
|
if distance < MAX_DISTANCE
|
||||||
|
and distance < min_distance then
|
||||||
min_distance = distance
|
min_distance = distance
|
||||||
nearest = player
|
nearest = player
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- And kill him
|
if not nearest then
|
||||||
meta = minetest.get_meta(pos)
|
-- no nearby player
|
||||||
owner = meta:get_string("owner")
|
return
|
||||||
if owner then
|
|
||||||
if vector.distance(pos, nearest:getpos()) < MAX_DISTANCE and owner ~= nearest:get_player_name() then
|
|
||||||
nearest:set_hp(0)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local owner = minetest.get_meta(pos):get_string("owner")
|
||||||
|
if not owner then
|
||||||
|
-- maybe some mod placed it
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- And kill him
|
||||||
|
nearest:set_hp(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "moremesecons_playerkiller:playerkiller 1",
|
output = "moremesecons_playerkiller:playerkiller",
|
||||||
recipe = { {"","default:apple",""},
|
recipe = { {"","default:apple",""},
|
||||||
{"default:apple","mesecons_detector:object_detector_off","default:apple"},
|
{"default:apple","mesecons_detector:object_detector_off","default:apple"},
|
||||||
{"","default:apple",""}}
|
{"","default:apple",""}}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("moremesecons_playerkiller:playerkiller", {
|
minetest.register_node("moremesecons_playerkiller:playerkiller", {
|
||||||
tiles = {"moremesecons_playerkiller_top.png", "moremesecons_playerkiller_top.png", "moremesecons_playerkiller_side.png", "moremesecons_playerkiller_side.png", "moremesecons_playerkiller_side.png", "moremesecons_playerkiller_side.png"},
|
description = "Player Killer",
|
||||||
|
tiles = {"moremesecons_playerkiller_top.png", "moremesecons_playerkiller_top.png", "moremesecons_playerkiller_side.png"},
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
walkable = true,
|
walkable = true,
|
||||||
groups = {cracky=3},
|
groups = {cracky=3},
|
||||||
description="Player Killer",
|
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
state = mesecon.state.off,
|
state = mesecon.state.off,
|
||||||
action_on = kill_nearest_player
|
action_on = kill_nearest_player
|
||||||
}},
|
}},
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
meta = minetest.get_meta(pos)
|
if not placer then
|
||||||
if placer then
|
return
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name())
|
|
||||||
meta:set_string("infotext", "PlayerKiller owned by " .. meta:get_string("owner"))
|
|
||||||
end
|
end
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("owner", placer:get_player_name())
|
||||||
|
meta:set_string("infotext", "PlayerKiller owned by " .. meta:get_string("owner"))
|
||||||
end,
|
end,
|
||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user