Change the code a bit

This commit is contained in:
paly2 2015-09-04 17:58:37 +02:00
parent 708c8b045a
commit 419fa62656
2 changed files with 18 additions and 5 deletions

@ -6,8 +6,7 @@ local kill_nearest_player = function(pos)
local min_distance = MAX_DISTANCE
for index, player in pairs(minetest.get_connected_players()) do
local distance = vector.distance(pos, player:getpos())
if distance < MAX_DISTANCE
and distance < min_distance then
if distance < min_distance then
min_distance = distance
nearest = player
end
@ -23,6 +22,11 @@ local kill_nearest_player = function(pos)
-- maybe some mod placed it
return
end
if owner == nearest:get_player_name() then
-- don't kill the owner !
return
end
-- And kill him
nearest:set_hp(0)

@ -11,11 +11,12 @@ local register = function(pos)
end
local teleport_nearest = function(pos)
local MAX_DISTANCE = 50
local MAX_TELEPORTATION_DISTANCE = 50
local MAX_PLAYER_DISTANCE = 25
-- Search the nearest player
local nearest = nil
local min_distance = math.huge
local min_distance = MAX_PLAYER_DISTANCE
local players = minetest.get_connected_players()
for index, player in pairs(players) do
local distance = vector.distance(pos, player:getpos())
@ -25,6 +26,11 @@ local teleport_nearest = function(pos)
end
end
if not nearest then
-- If there is no nearest player (maybe too far...)
return
end
-- Search other teleporter and teleport
if not minetest.registered_nodes["moremesecons_teleporter:teleporter"] then return end
@ -41,7 +47,10 @@ local teleport_nearest = function(pos)
end
end
if newpos.x then
if vector.distance(newpos, nearest:getpos()) > MAX_DISTANCE then newpos = {} end -- If the is another teleporter BUT too far, delete newpos.
-- If there is another teleporter BUT too far, delete newpos.
if vector.distance(newpos, pos) > MAX_TELEPORTATION_DISTANCE then
newpos = {}
end
end
if not newpos.x then
newpos = {x=pos.x, y=pos.y+1, z=pos.z} -- If newpos doesn't exist, teleport on the actual teleporter.