1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-25 18:20:20 +01:00

added on_spawn function

This commit is contained in:
TenPlus1 2016-10-09 09:17:44 +01:00
parent d2806eccf2
commit e3e00b24a0
2 changed files with 9 additions and 4 deletions

10
api.lua
View File

@ -1,5 +1,5 @@
-- Mobs Api (8th October 2016) -- Mobs Api (9th October 2016)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
@ -2411,7 +2411,7 @@ end -- END mobs:register_mob function
-- global functions -- global functions
function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
interval, chance, aoc, min_height, max_height, day_toggle) interval, chance, aoc, min_height, max_height, day_toggle, on_spawn)
-- chance override in minetest.conf for registered mob -- chance override in minetest.conf for registered mob
local new_chance = tonumber(minetest.setting_get(name .. "_chance")) local new_chance = tonumber(minetest.setting_get(name .. "_chance"))
@ -2526,6 +2526,9 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
-- print ("[mobs] Spawned " .. name .. " at " -- print ("[mobs] Spawned " .. name .. " at "
-- .. minetest.pos_to_string(pos) .. " on " -- .. minetest.pos_to_string(pos) .. " on "
-- .. node.name .. " near " .. neighbors[1]) -- .. node.name .. " near " .. neighbors[1])
if on_spawn and not on_spawn(mob, pos) then
return
end
else else
print (S("[mobs] @1 failed to spawn at @2", print (S("[mobs] @1 failed to spawn at @2",
name, minetest.pos_to_string(pos))) name, minetest.pos_to_string(pos)))
@ -2556,9 +2559,10 @@ function mobs:spawn(def)
local min_height = def.min_height or -31000 local min_height = def.min_height or -31000
local max_height = def.max_height or 31000 local max_height = def.max_height or 31000
local day_toggle = def.day_toggle or nil local day_toggle = def.day_toggle or nil
local on_spawn = def.on_spawn
mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, interval, mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, interval,
chance, active_object_count, min_height, max_height, day_toggle) chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
end end
-- set content id's -- set content id's

View File

@ -139,7 +139,7 @@ The mob api also has some preset variables and functions that it will remember f
mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle) mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle)
mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height, day_toggle) mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
These functions register a spawn algorithm for the mob. Without this function the call the mobs won't spawn. These functions register a spawn algorithm for the mob. Without this function the call the mobs won't spawn.
@ -154,6 +154,7 @@ These functions register a spawn algorithm for the mob. Without this function th
'min_height' is the maximum height the mob can spawn 'min_height' is the maximum height the mob can spawn
'max_height' is the maximum height the mob can spawn 'max_height' is the maximum height the mob can spawn
'day_toggle' true for day spawning, false for night or nil for anytime 'day_toggle' true for day spawning, false for night or nil for anytime
'on_spawn' is a custom function which runs after mob has spawned and gives self and pos values.
... also a simpler way to handle mob spawns has been added with the mobs:spawn(def) command which uses above names to make settings clearer: ... also a simpler way to handle mob spawns has been added with the mobs:spawn(def) command which uses above names to make settings clearer: