2015-08-28 12:24:33 +02:00
|
|
|
local kill_nearest_player = function(pos)
|
|
|
|
local MAX_DISTANCE = 8 -- Use this number to set maximal distance to kill
|
2015-09-04 16:58:17 +02:00
|
|
|
|
2015-08-28 12:24:33 +02:00
|
|
|
-- Search the nearest player
|
2015-09-04 16:58:17 +02:00
|
|
|
local nearest
|
|
|
|
local min_distance = MAX_DISTANCE
|
|
|
|
for index, player in pairs(minetest.get_connected_players()) do
|
2015-08-28 12:24:33 +02:00
|
|
|
local distance = vector.distance(pos, player:getpos())
|
2015-09-04 17:58:37 +02:00
|
|
|
if distance < min_distance then
|
2015-08-28 12:24:33 +02:00
|
|
|
min_distance = distance
|
|
|
|
nearest = player
|
|
|
|
end
|
|
|
|
end
|
2015-09-04 16:58:17 +02:00
|
|
|
|
|
|
|
if not nearest then
|
|
|
|
-- no nearby player
|
|
|
|
return
|
2015-08-28 12:24:33 +02:00
|
|
|
end
|
2015-09-04 16:58:17 +02:00
|
|
|
|
|
|
|
local owner = minetest.get_meta(pos):get_string("owner")
|
|
|
|
if not owner then
|
|
|
|
-- maybe some mod placed it
|
|
|
|
return
|
|
|
|
end
|
2015-09-04 17:58:37 +02:00
|
|
|
|
|
|
|
if owner == nearest:get_player_name() then
|
|
|
|
-- don't kill the owner !
|
|
|
|
return
|
|
|
|
end
|
2015-09-04 16:58:17 +02:00
|
|
|
|
|
|
|
-- And kill him
|
|
|
|
nearest:set_hp(0)
|
2016-04-27 12:20:19 +02:00
|
|
|
minetest.log("action", "Player "..owner.." kills player "..nearest.." using a MoreMesecons Player Killer.")
|
2015-08-28 12:24:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2015-09-04 16:58:17 +02:00
|
|
|
output = "moremesecons_playerkiller:playerkiller",
|
2016-04-27 20:18:01 +02:00
|
|
|
recipe = { {"","default:mese",""},
|
2015-08-28 12:24:33 +02:00
|
|
|
{"default:apple","mesecons_detector:object_detector_off","default:apple"},
|
|
|
|
{"","default:apple",""}}
|
|
|
|
})
|
2015-09-04 16:58:17 +02:00
|
|
|
|
2015-08-28 12:24:33 +02:00
|
|
|
minetest.register_node("moremesecons_playerkiller:playerkiller", {
|
2015-09-04 16:58:17 +02:00
|
|
|
description = "Player Killer",
|
|
|
|
tiles = {"moremesecons_playerkiller_top.png", "moremesecons_playerkiller_top.png", "moremesecons_playerkiller_side.png"},
|
2015-08-28 12:24:33 +02:00
|
|
|
paramtype = "light",
|
|
|
|
walkable = true,
|
|
|
|
groups = {cracky=3},
|
|
|
|
mesecons = {effector = {
|
|
|
|
state = mesecon.state.off,
|
|
|
|
action_on = kill_nearest_player
|
|
|
|
}},
|
|
|
|
after_place_node = function(pos, placer)
|
2015-09-04 16:58:17 +02:00
|
|
|
if not placer then
|
|
|
|
return
|
2015-08-28 12:24:33 +02:00
|
|
|
end
|
2015-09-04 16:58:17 +02:00
|
|
|
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"))
|
2015-08-28 12:24:33 +02:00
|
|
|
end,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
})
|