1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-19 16:50:31 +01:00

fix bobber and worms removed when on_place

fix wrong condition cause remove bobber and worms when on_place if several player connected
This commit is contained in:
crabman77 2015-03-10 02:53:53 +01:00
parent c5ad8e22a1
commit 2cb1438e99
3 changed files with 21 additions and 23 deletions

View File

@ -242,19 +242,23 @@ local FISHING_BOBBER_ENTITY={
if math.random(1, 4) == 1 then if math.random(1, 4) == 1 then
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/2880*math.pi)) self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/2880*math.pi))
end end
local remove_entity = true
for _,player in pairs(minetest.get_connected_players()) do for _,player in pairs(minetest.get_connected_players()) do
local s = self.object:getpos() local s = self.object:getpos()
local p = player:getpos() local p = player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range then if dist < self.view_range then
-- make sound and remove bobber remove_entity = false
minetest.sound_play("fishing_bobber1", { break
pos = self.object:getpos(),
gain = 0.5,
})
self.object:remove()
end end
end end
if remove_entity then
-- make sound and remove bobber
minetest.sound_play("fishing_bobber1", {pos = self.object:getpos(),gain = 0.5,})
self.object:remove()
end
if self.object:get_hp() > 310 then if self.object:get_hp() > 310 then
local find_fish = minetest.get_objects_inside_radius({x=pos.x,y=pos.y+0.5,z=pos.z}, 1) local find_fish = minetest.get_objects_inside_radius({x=pos.x,y=pos.y+0.5,z=pos.z}, 1)

View File

@ -172,18 +172,21 @@ local FISHING_BOBBER_ENTITY_SHARK={
if math.random(1, 4) == 1 then if math.random(1, 4) == 1 then
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/2880*math.pi)) self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/2880*math.pi))
end end
local remove_entity = true
for _,player in pairs(minetest.get_connected_players()) do for _,player in pairs(minetest.get_connected_players()) do
local s = self.object:getpos() local s = self.object:getpos()
local p = player:getpos() local p = player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range then if dist < self.view_range then
minetest.sound_play("fishing_bobber1", { remove_entity = false
pos = self.object:getpos(), break
gain = 0.5,
})
self.object:remove()
end end
end end
if remove_entity then
-- make sound and remove bobber
minetest.sound_play("fishing_bobber1", {pos = self.object:getpos(),gain = 0.5,})
self.object:remove()
end
local do_env_damage = function(self) local do_env_damage = function(self)
self.object:set_hp(self.object:get_hp()-self.water_damage) self.object:set_hp(self.object:get_hp()-self.water_damage)
if self.object:get_hp() == 600 then if self.object:get_hp() == 600 then

View File

@ -63,15 +63,6 @@ minetest.register_entity("fishing:bait_worm_entity", {
on_step = function(self, dtime) on_step = function(self, dtime)
local pos = self.object:getpos() local pos = self.object:getpos()
local n = minetest.env:get_node({x=pos.x,y=pos.y-0.3,z=pos.z}) local n = minetest.env:get_node({x=pos.x,y=pos.y-0.3,z=pos.z})
-- despawn when no player in range
for _,player in pairs(minetest.get_connected_players()) do
local s = self.object:getpos()
local p = player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range then
self.object:remove()
end
end
-- move in world -- move in world
local look_whats_up = function(self) local look_whats_up = function(self)
self.object:set_hp(self.object:get_hp()-self.damage_over_time) -- creature is getting older self.object:set_hp(self.object:get_hp()-self.damage_over_time) -- creature is getting older