Add option to require nearby players for spawn
This commit is contained in:
parent
b0f464e7ac
commit
1aff8fee5b
1
TODO.txt
1
TODO.txt
@ -1,4 +1,3 @@
|
||||
|
||||
TODO:
|
||||
- check for nearbly players before spawning
|
||||
- add lifetime limit
|
||||
|
12
settings.lua
12
settings.lua
@ -3,6 +3,18 @@
|
||||
|
||||
local time_min = 60
|
||||
|
||||
--- Determines whether or not a player must be close for spawn to occur.
|
||||
--
|
||||
-- @setting sneeker.spawn_require_player_nearby
|
||||
sneeker.spawn_require_player_nearby = core.settings:get_bool("sneeker.spawn_require_player_nearby", true)
|
||||
|
||||
--- Distance in nodes a player must be for spawn to occur.
|
||||
--
|
||||
-- Only used if `sneeker.spawn_require_player_nearby` enabled.
|
||||
--
|
||||
-- @setting sneeker.spawn_player_radius
|
||||
sneeker.spawn_player_radius = tonumber(core.settings:get("sneeker.spawn_player_radius") or 100)
|
||||
|
||||
--- Sets possibility for spawn.
|
||||
--
|
||||
-- Inverted value (e.g. 10000 = 1/10000).
|
||||
|
@ -2,6 +2,14 @@
|
||||
# Extra debugging messages.
|
||||
enable_debug_mods (Mod debugging) bool false
|
||||
|
||||
# Determines whether or not a player must be close for spawn to occur.
|
||||
sneeker.spawn_require_player_nearby (Require player nearby) bool true
|
||||
|
||||
# Distance in nodes a player must be for spawn to occur.
|
||||
#
|
||||
# Only used if `sneeker.spawn_require_player_nearby` enabled.
|
||||
sneeker.spawn_player_radius (Player detect radius) int 100
|
||||
|
||||
# Sets possibility for spawn.
|
||||
#
|
||||
# Rate is the inverted value (e.g. 1/value).
|
||||
|
26
spawn.lua
26
spawn.lua
@ -28,6 +28,22 @@ core.register_abm({
|
||||
-- check above target node
|
||||
pos.y = pos.y+1
|
||||
|
||||
local pos_string = tostring(math.floor(pos.x))
|
||||
.. "," .. tostring(math.floor(pos.y))
|
||||
.. "," .. tostring(math.floor(pos.z))
|
||||
|
||||
if sneeker.spawn_require_player_nearby then
|
||||
local player_nearby = false
|
||||
for _, entity in ipairs(core.get_objects_inside_radius(pos, sneeker.spawn_player_radius)) do
|
||||
if entity:is_player() then
|
||||
player_nearby = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not player_nearby then return end
|
||||
end
|
||||
|
||||
if pos.y > sneeker.spawn_maxheight or pos.y < sneeker.spawn_minheight then
|
||||
return
|
||||
end
|
||||
@ -46,15 +62,9 @@ core.register_abm({
|
||||
|
||||
local spawned = core.add_entity(pos, "sneeker:sneeker")
|
||||
if not spawned then
|
||||
sneeker.log("warning", "Failed to spawn at: "
|
||||
.. tostring(math.floor(pos.x))
|
||||
.. "," .. tostring(math.floor(pos.y))
|
||||
.. "," .. tostring(math.floor(pos.z)))
|
||||
sneeker.log("warning", "Failed to spawn at: " .. pos_string)
|
||||
else
|
||||
sneeker.log("debug", "Spawned at: "
|
||||
.. tostring(math.floor(pos.x))
|
||||
.. "," .. tostring(math.floor(pos.y))
|
||||
.. "," .. tostring(math.floor(pos.z)))
|
||||
sneeker.log("debug", "Spawned at: " .. pos_string)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user