MoreMesecons/moremesecons_playerkiller/init.lua

63 lines
1.7 KiB
Lua
Raw Normal View History

local kill_nearest_player = function(pos)
local MAX_DISTANCE = moremesecons.setting("playerkiller", "max_distance", 8, 1)
2015-09-04 16:58:17 +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
local distance = vector.distance(pos, player:getpos())
2015-09-04 17:58:37 +02:00
if distance < min_distance then
min_distance = distance
nearest = player
end
end
2015-09-04 16:58:17 +02:00
if not nearest then
-- no nearby player
return
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
2017-02-11 14:01:20 +01:00
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)
minetest.log("action", "Player "..owner.." kills player "..nearest.." using a MoreMesecons Player Killer.")
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",""},
{"default:apple","mesecons_detector:object_detector_off","default:apple"},
{"","default:apple",""}}
})
2015-09-04 16:58:17 +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"},
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
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"))
end,
sounds = default.node_sound_stone_defaults(),
})