mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
better fix to issue https://github.com/MinetestForFun/server-minetestforfun/issues/161
remove old fix(itemdrop timer,now useless)
This commit is contained in:
parent
5b926f753c
commit
c54bdbef03
@ -181,13 +181,27 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
beds.read_spawns()
|
beds.read_spawns()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- respawn player at bed if enabled and valid position is found
|
|
||||||
minetest.register_on_respawnplayer(function(player)
|
|
||||||
--MFF DEBUT crabman(8/01/2016 ) respawn player in special area(event) if a spawn is set.
|
|
||||||
if ((minetest.get_modpath("areas") ~= nil) and (areas:onRespawn(player))) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
|
local dead_players = {}
|
||||||
|
local have_areas_mod = false
|
||||||
|
if (minetest.get_modpath("areas") ~= nil) and areas.getSpawn then
|
||||||
|
have_areas_mod = true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function teleport_player(player, clear)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if not name or name == "" then return false end
|
||||||
|
if have_areas_mod and dead_players[name] ~= nil then
|
||||||
|
local pos = areas:getSpawn(dead_players[name])
|
||||||
|
if clear then
|
||||||
|
dead_players[name] = nil
|
||||||
|
end
|
||||||
|
if pos then
|
||||||
|
player:setpos(pos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
if not enable_respawn then
|
if not enable_respawn then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -197,8 +211,31 @@ minetest.register_on_respawnplayer(function(player)
|
|||||||
player:setpos(pos)
|
player:setpos(pos)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
--if not areas or bed spawnpoint, tp to the spawn
|
||||||
|
local spawn = minetest.string_to_pos(minetest.setting_get("static_spawnpoint") or "0,0,0")
|
||||||
|
player:setpos(spawn)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_on_dieplayer(function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if not name or name == "" then return end
|
||||||
|
if have_areas_mod then
|
||||||
|
local pos = player:getpos()
|
||||||
|
if pos then
|
||||||
|
dead_players[name] = pos
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.after(0.20, teleport_player, player) -- tp after all others on_dieplayer callback otherwise their pos is wrong
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- respawn player at bed if enabled and valid position is found
|
||||||
|
minetest.register_on_respawnplayer(function(player)
|
||||||
|
return teleport_player(player, true)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
lay_down(player, nil, nil, false, true)
|
lay_down(player, nil, nil, false, true)
|
||||||
|
@ -162,32 +162,13 @@ function areas:canMakeArea(pos1, pos2, name) --MFF crabman(25/02/2016) fix areas
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--MFF DEBUT crabman(17/09/2015 ) respawn player in special area(event) if a spawn is set.
|
--MFF crabman(5/03/2016 ) return special area pos if a spawn is set.
|
||||||
--1 party (2 party in beds mod)
|
--1 party (2 party in beds mod)
|
||||||
local dead_players = {}
|
function areas:getSpawn(pos)
|
||||||
minetest.register_on_dieplayer(function(player)
|
for _, area in pairs(areas:getAreasAtPos(pos)) do
|
||||||
local player_name = player:get_player_name()
|
if area.spawn and area.spawn.x then
|
||||||
if not player_name then return end
|
return area.spawn
|
||||||
local pos = player:getpos()
|
|
||||||
if pos then
|
|
||||||
dead_players[player_name] = pos
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
function areas:onRespawn(player)
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
if not player_name or not dead_players[player_name] then return false end
|
|
||||||
local pos = dead_players[player_name]
|
|
||||||
dead_players[player_name] = nil
|
|
||||||
if pos then
|
|
||||||
for _, area in pairs(areas:getAreasAtPos(pos)) do
|
|
||||||
if area.spawn then
|
|
||||||
player:setpos(area.spawn)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return nil
|
||||||
end
|
end
|
||||||
--FIN
|
|
||||||
|
@ -4,36 +4,6 @@ local creative_mode = minetest.setting_getbool("creative_mode")
|
|||||||
local TICK_UPDATE = 0.1
|
local TICK_UPDATE = 0.1
|
||||||
|
|
||||||
|
|
||||||
local die_timeout = 20
|
|
||||||
local die_time = {}
|
|
||||||
local die_respawned = {}
|
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
die_time[player_name] = 0
|
|
||||||
die_respawned[player_name] = false
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
die_time[player_name] = nil
|
|
||||||
die_respawned[player_name] = nil
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_on_dieplayer(function(player)
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
if not player_name then return end
|
|
||||||
die_respawned[player_name] = false
|
|
||||||
die_time[player_name] = die_timeout
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_on_respawnplayer(function(player)
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
if not player_name then return end
|
|
||||||
die_respawned[player_name] = true
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
-- Following edits by gravgun
|
-- Following edits by gravgun
|
||||||
|
|
||||||
item_drop.drop_callbacks = {}
|
item_drop.drop_callbacks = {}
|
||||||
@ -67,83 +37,76 @@ local pickup_inv_duration = 1/pickup_duration*0.7
|
|||||||
local function tick()
|
local function tick()
|
||||||
local tstamp = minetest.get_us_time()
|
local tstamp = minetest.get_us_time()
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
local player_name = player:get_player_name()
|
if player:get_hp() > 0 or not enable_damage then
|
||||||
if die_time[player_name] and die_time[player_name] < 1 then
|
local pos = player:getpos()
|
||||||
if player:get_hp() > 0 or not enable_damage then
|
pos.y = pos.y + player_half_height
|
||||||
local pos = player:getpos()
|
local inv = player:get_inventory()
|
||||||
pos.y = pos.y + player_half_height
|
|
||||||
local inv = player:get_inventory()
|
|
||||||
|
|
||||||
if inv then
|
if inv then
|
||||||
for _,object in ipairs(minetest.get_objects_inside_radius(pos, scan_range)) do
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, scan_range)) do
|
||||||
local luaEnt = object:get_luaentity()
|
local luaEnt = object:get_luaentity()
|
||||||
if luaEnt and luaEnt.name == "__builtin:item" then
|
if luaEnt and luaEnt.name == "__builtin:item" then
|
||||||
local ticky = luaEnt.item_drop_min_tstamp
|
local ticky = luaEnt.item_drop_min_tstamp
|
||||||
if ticky then
|
if ticky then
|
||||||
if tstamp >= ticky then
|
if tstamp >= ticky then
|
||||||
luaEnt.item_drop_min_tstamp = nil
|
luaEnt.item_drop_min_tstamp = nil
|
||||||
end
|
end
|
||||||
elseif not luaEnt.item_drop_nopickup then
|
elseif not luaEnt.item_drop_nopickup then
|
||||||
-- Point-line distance computation, heavily simplified since the wanted line,
|
-- Point-line distance computation, heavily simplified since the wanted line,
|
||||||
-- being the player, is completely upright (no variation on X or Z)
|
-- being the player, is completely upright (no variation on X or Z)
|
||||||
local pos2 = object:getpos()
|
local pos2 = object:getpos()
|
||||||
-- No sqrt, avoid useless computation
|
-- No sqrt, avoid useless computation
|
||||||
-- (just take the radius, compare it to the square of what you want)
|
-- (just take the radius, compare it to the square of what you want)
|
||||||
-- Pos order doesn't really matter, we're squaring the result
|
-- Pos order doesn't really matter, we're squaring the result
|
||||||
-- (but don't change it, we use the cached values afterwards)
|
-- (but don't change it, we use the cached values afterwards)
|
||||||
local dX = pos.x-pos2.x
|
local dX = pos.x-pos2.x
|
||||||
local dZ = pos.z-pos2.z
|
local dZ = pos.z-pos2.z
|
||||||
local playerDistance = dX*dX+dZ*dZ
|
local playerDistance = dX*dX+dZ*dZ
|
||||||
if playerDistance <= pickup_range_squared then
|
if playerDistance <= pickup_range_squared then
|
||||||
local itemStack = ItemStack(luaEnt.itemstring)
|
local itemStack = ItemStack(luaEnt.itemstring)
|
||||||
if inv:room_for_item("main", itemStack) then
|
if inv:room_for_item("main", itemStack) then
|
||||||
local vec = {x=dX, y=pos.y-pos2.y, z=dZ}
|
local vec = {x=dX, y=pos.y-pos2.y, z=dZ}
|
||||||
vec.x = vec.x*pickup_inv_duration
|
vec.x = vec.x*pickup_inv_duration
|
||||||
vec.y = vec.y*pickup_inv_duration
|
vec.y = vec.y*pickup_inv_duration
|
||||||
vec.z = vec.z*pickup_inv_duration
|
vec.z = vec.z*pickup_inv_duration
|
||||||
object:setvelocity(vec)
|
object:setvelocity(vec)
|
||||||
luaEnt.physical_state = false
|
luaEnt.physical_state = false
|
||||||
luaEnt.object:set_properties({
|
luaEnt.object:set_properties({
|
||||||
physical = false
|
physical = false
|
||||||
})
|
})
|
||||||
-- Mark the object as already picking up
|
-- Mark the object as already picking up
|
||||||
luaEnt.item_drop_nopickup = true
|
luaEnt.item_drop_nopickup = true
|
||||||
|
|
||||||
minetest.after(pickup_duration, function()
|
minetest.after(pickup_duration, function()
|
||||||
local lua = luaEnt
|
local lua = luaEnt
|
||||||
if object == nil or lua == nil or lua.itemstring == nil then
|
if object == nil or lua == nil or lua.itemstring == nil then
|
||||||
return
|
return
|
||||||
|
end
|
||||||
|
if inv:room_for_item("main", itemStack) then
|
||||||
|
inv:add_item("main", itemStack)
|
||||||
|
if luaEnt.itemstring ~= "" then
|
||||||
|
minetest.sound_play("item_drop_pickup", {pos = pos, gain = 0.3, max_hear_distance = 8})
|
||||||
end
|
end
|
||||||
if inv:room_for_item("main", itemStack) then
|
luaEnt.itemstring = ""
|
||||||
inv:add_item("main", itemStack)
|
object:remove()
|
||||||
if luaEnt.itemstring ~= "" then
|
for i, cb in ipairs(item_drop.pickup_callbacks) do
|
||||||
minetest.sound_play("item_drop_pickup", {pos = pos, gain = 0.3, max_hear_distance = 8})
|
cb(player, itemstack)
|
||||||
end
|
|
||||||
luaEnt.itemstring = ""
|
|
||||||
object:remove()
|
|
||||||
for i, cb in ipairs(item_drop.pickup_callbacks) do
|
|
||||||
cb(player, itemstack)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
object:setvelocity({x = 0,y = 0,z = 0})
|
|
||||||
luaEnt.physical_state = true
|
|
||||||
luaEnt.object:set_properties({
|
|
||||||
physical = true
|
|
||||||
})
|
|
||||||
luaEnt.item_drop_nopickup = nil
|
|
||||||
end
|
end
|
||||||
end)
|
else
|
||||||
end
|
object:setvelocity({x = 0,y = 0,z = 0})
|
||||||
|
luaEnt.physical_state = true
|
||||||
|
luaEnt.object:set_properties({
|
||||||
|
physical = true
|
||||||
|
})
|
||||||
|
luaEnt.item_drop_nopickup = nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
if die_respawned[player_name] then
|
|
||||||
die_time[player_name] = (die_time[player_name] or die_timeout) - TICK_UPDATE
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.after(TICK_UPDATE, tick)
|
minetest.after(TICK_UPDATE, tick)
|
||||||
|
Loading…
Reference in New Issue
Block a user