mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2025-01-01 18:27:35 +01:00
Change the code a bit
This commit is contained in:
parent
708c8b045a
commit
419fa62656
@ -6,8 +6,7 @@ local kill_nearest_player = function(pos)
|
|||||||
local min_distance = MAX_DISTANCE
|
local min_distance = MAX_DISTANCE
|
||||||
for index, player in pairs(minetest.get_connected_players()) do
|
for index, player in pairs(minetest.get_connected_players()) do
|
||||||
local distance = vector.distance(pos, player:getpos())
|
local distance = vector.distance(pos, player:getpos())
|
||||||
if distance < MAX_DISTANCE
|
if distance < min_distance then
|
||||||
and distance < min_distance then
|
|
||||||
min_distance = distance
|
min_distance = distance
|
||||||
nearest = player
|
nearest = player
|
||||||
end
|
end
|
||||||
@ -24,6 +23,11 @@ local kill_nearest_player = function(pos)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if owner == nearest:get_player_name() then
|
||||||
|
-- don't kill the owner !
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- And kill him
|
-- And kill him
|
||||||
nearest:set_hp(0)
|
nearest:set_hp(0)
|
||||||
end
|
end
|
||||||
|
@ -11,11 +11,12 @@ local register = function(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local teleport_nearest = function(pos)
|
local teleport_nearest = function(pos)
|
||||||
local MAX_DISTANCE = 50
|
local MAX_TELEPORTATION_DISTANCE = 50
|
||||||
|
local MAX_PLAYER_DISTANCE = 25
|
||||||
|
|
||||||
-- Search the nearest player
|
-- Search the nearest player
|
||||||
local nearest = nil
|
local nearest = nil
|
||||||
local min_distance = math.huge
|
local min_distance = MAX_PLAYER_DISTANCE
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for index, player in pairs(players) do
|
for index, player in pairs(players) do
|
||||||
local distance = vector.distance(pos, player:getpos())
|
local distance = vector.distance(pos, player:getpos())
|
||||||
@ -25,6 +26,11 @@ local teleport_nearest = function(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not nearest then
|
||||||
|
-- If there is no nearest player (maybe too far...)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Search other teleporter and teleport
|
-- Search other teleporter and teleport
|
||||||
if not minetest.registered_nodes["moremesecons_teleporter:teleporter"] then return end
|
if not minetest.registered_nodes["moremesecons_teleporter:teleporter"] then return end
|
||||||
|
|
||||||
@ -41,7 +47,10 @@ local teleport_nearest = function(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if newpos.x then
|
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
|
end
|
||||||
if not newpos.x then
|
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.
|
newpos = {x=pos.x, y=pos.y+1, z=pos.z} -- If newpos doesn't exist, teleport on the actual teleporter.
|
||||||
|
Loading…
Reference in New Issue
Block a user