mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-01-24 16:20:19 +01:00
tweak player detection (thx whosit)
This commit is contained in:
parent
dd9b3d7add
commit
822e78fd32
38
api.lua
38
api.lua
@ -14,7 +14,7 @@ local use_vh1 = minetest.get_modpath("visual_harm_1ndicators")
|
|||||||
-- Global
|
-- Global
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20240220",
|
version = "20240223",
|
||||||
translate = S,
|
translate = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||||
node_snow = minetest.registered_aliases["mapgen_snow"]
|
node_snow = minetest.registered_aliases["mapgen_snow"]
|
||||||
@ -265,14 +265,16 @@ function mob_class:collision()
|
|||||||
local x, z = 0, 0
|
local x, z = 0, 0
|
||||||
local prop = self.object:get_properties()
|
local prop = self.object:get_properties()
|
||||||
local width = -prop.collisionbox[1] + prop.collisionbox[4] + 0.5
|
local width = -prop.collisionbox[1] + prop.collisionbox[4] + 0.5
|
||||||
|
local pos2, vec, force
|
||||||
|
|
||||||
for _,object in pairs(minetest.get_objects_inside_radius(pos, width)) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
if is_player(object) then
|
pos2 = player:get_pos()
|
||||||
|
|
||||||
local pos2 = object:get_pos()
|
if pos2:distance(pos) < width then
|
||||||
local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
|
|
||||||
local force = (width + 0.5) - vector.distance(
|
vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
|
||||||
|
force = (width + 0.5) - vector.distance(
|
||||||
{x = pos.x, y = 0, z = pos.z},
|
{x = pos.x, y = 0, z = pos.z},
|
||||||
{x = pos2.x, y = 0, z = pos2.z})
|
{x = pos2.x, y = 0, z = pos2.z})
|
||||||
|
|
||||||
@ -281,6 +283,7 @@ function mob_class:collision()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return({x, z})
|
return({x, z})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2243,12 +2246,13 @@ function mob_class:do_states(dtime)
|
|||||||
|
|
||||||
local lp
|
local lp
|
||||||
local s = self.object:get_pos()
|
local s = self.object:get_pos()
|
||||||
local objs = minetest.get_objects_inside_radius(s, 3)
|
|
||||||
|
|
||||||
for n = 1, #objs do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
if is_player(objs[n]) then
|
local player_pos = player:get_pos()
|
||||||
lp = objs[n]:get_pos()
|
|
||||||
|
if player_pos:distance(s) <= 3 then
|
||||||
|
lp = player_pos
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -3334,14 +3338,10 @@ function mob_class:mob_expire(pos, dtime)
|
|||||||
if self.lifetimer <= 0 then
|
if self.lifetimer <= 0 then
|
||||||
|
|
||||||
-- only despawn away from player
|
-- only despawn away from player
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 15)
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
for n = 1, #objs do
|
|
||||||
|
|
||||||
if is_player(objs[n]) then
|
|
||||||
|
|
||||||
|
if player:get_pos():distance(pos) <= 15 then
|
||||||
self.lifetimer = 20
|
self.lifetimer = 20
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -4064,11 +4064,9 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- only spawn a set distance away from player
|
-- only spawn a set distance away from player
|
||||||
local objs = minetest.get_objects_inside_radius(pos, mob_nospawn_range)
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
for n = 1, #objs do
|
if player:get_pos():distance(pos) <= mob_nospawn_range then
|
||||||
|
|
||||||
if is_player(objs[n]) then
|
|
||||||
--print("--- player too close", name)
|
--print("--- player too close", name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
18
spawner.lua
18
spawner.lua
@ -97,7 +97,7 @@ minetest.register_abm({
|
|||||||
label = "Mob spawner node",
|
label = "Mob spawner node",
|
||||||
nodenames = {"mobs:spawner"},
|
nodenames = {"mobs:spawner"},
|
||||||
interval = 10,
|
interval = 10,
|
||||||
chance = 4,
|
chance = 1,--4,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
@ -150,24 +150,26 @@ minetest.register_abm({
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- spawn mob if player detected and in range
|
-- when player distance above 0, spawn mob if player detected and in range
|
||||||
if pla > 0 then
|
if pla > 0 then
|
||||||
|
|
||||||
local in_range = 0
|
local in_range, player
|
||||||
local objsp = minetest.get_objects_inside_radius(pos, pla)
|
local players = minetest.get_connected_players()
|
||||||
|
|
||||||
for _, oir in pairs(objsp) do
|
for i = 1, #players do
|
||||||
|
|
||||||
if is_player(oir) then
|
player = players[i]
|
||||||
|
|
||||||
in_range = 1
|
if player:get_pos():distance(pos) <= pla then
|
||||||
|
|
||||||
|
in_range = true
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- player not found
|
-- player not found
|
||||||
if in_range == 0 then
|
if not in_range then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user