summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTenPlus1 <kinsellaja@yahoo.com>2016-10-21 14:46:50 +0100
committerTenPlus1 <kinsellaja@yahoo.com>2016-10-21 14:46:50 +0100
commit7014152bf92e1122d4f91460781c3f43db79f612 (patch)
treecda1ba4db75c33fb49c4922a7dca079c5cb4d6b9
parent3f61935a07a499b972a949ad13656ba953f9bde7 (diff)
added new spawn check for specific mob numbers
-rw-r--r--api.lua49
-rw-r--r--api.txt2
2 files changed, 40 insertions, 11 deletions
diff --git a/api.lua b/api.lua
index 88da0c2..d966526 100644
--- a/api.lua
+++ b/api.lua
@@ -1,5 +1,5 @@
--- Mobs Api (14th October 2016)
+-- Mobs Api (21st October 2016)
mobs = {}
mobs.mod = "redo"
@@ -2403,24 +2403,47 @@ minetest.register_entity(name, {
end -- END mobs:register_mob function
+-- count how many mobs of one type are inside an area
+local count_mobs = function(pos, type)
+
+ local num = 0
+ local objs = minetest.get_objects_inside_radius(pos, 16)
+
+ for n = 1, #objs do
+
+ if not objs[n]:is_player() then
+
+ obj = objs[n]:get_luaentity()
+
+ if obj and obj.name and obj.name == type then
+ num = num + 1
+ end
+ end
+ end
+
+ return num
+end
+
-- global functions
function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
interval, chance, aoc, min_height, max_height, day_toggle, on_spawn)
- -- chance override in minetest.conf for registered mob
- local new_chance = tonumber(minetest.setting_get(name .. "_chance"))
+ -- chance/spawn number override in minetest.conf for registered mob
+ local numbers = minetest.setting_get(name)
- if new_chance ~= nil then
+ if numbers then
+ numbers = numbers:split(",")
+ chance = tonumber(numbers[1]) or chance
+ aoc = tonumber(numbers[2]) or aoc
- if new_chance == 0 then
+ if chance == 0 then
print(S("[Mobs Redo] @1 has spawning disabled", name))
return
end
- chance = new_chance
-
- print (S("[Mobs Redo] Chance setting for @1 changed to @2", name, chance))
+ print (S("[Mobs Redo] Chance setting for @1 changed to @2", name, chance)
+ .. " (total: " .. aoc .. ")")
end
@@ -2435,9 +2458,15 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
action = function(pos, node, active_object_count, active_object_count_wider)
- -- do not spawn if too many active entities in area
+ -- is mob actually registered?
+ if not mobs.spawning_mobs[name] then
+--print ("--- mob doesn't exist", name)
+ return
+ end
+
+ -- do not spawn if too many of same mob in area
if active_object_count_wider >= aoc
- or not mobs.spawning_mobs[name] then
+ and count_mobs(pos, name) >= aoc then
--print ("--- too many entities", name, aoc)
return
end
diff --git a/api.txt b/api.txt
index c49a50f..028b92a 100644
--- a/api.txt
+++ b/api.txt
@@ -10,7 +10,7 @@ The mob api is a function that can be called on by other mods to add new animals
'mobs_disable_blood' if false blood effects appear when mob is hit (default is false)
'mobs_spawn_protected' if set to 1 then mobs will not spawn in protected areas (default is 0)
'remove_far_mobs' if true then mobs that are outside players visual range will be removed (default is false)
- 'mobname_chance' can change specific mob chance rates or set to 0 to disable e.g. mobs_animal:cow_chance = 1000
+ 'mobname' can change specific mob chance rate (0 to disable) and spawn number e.g. mobs_animal:cow = 1000,5
'mob_difficulty' sets difficulty level (health and hit damage multiplied by this number), defaults to 1.0.