Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
use_mesecons = false
function npc_spawner(pos)
local MAX_NPC = 5
local found = table.getn(minetest.env:get_objects_inside_radius(pos, 20))
if found == nil then
found = 0
if found <= MAX_NPC then
offsetx = math.random(-3,3)
offsety = math.random(2,4)
offsetz = math.random(-3,3)
minetest.env:add_entity({ x=pos.x+offsetx, y=pos.y+offsety, z=pos.z+offsetz }, ("peaceful_npc:npc"))
end
end
end
if use_mesecons == true then
minetest.register_node("peaceful_npc:npc_spawner", {
description = "NPC Portal",
drawtype = "glasslike",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
sounds = default.node_sound_glass_defaults(),
tiles = {"peaceful_npc_spawner.png"},
sunlight_propagates = true,
paramtype = "light",
mesecons = {effector = {
action_on = npc_spawner
}}
})
end
if use_mesecons == false then
minetest.register_node("peaceful_npc:npc_spawner", {
description = "NPC Portal",
drawtype = "glasslike",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
sounds = default.node_sound_glass_defaults(),
tiles = {"peaceful_npc_spawner.png"},
sunlight_propagates = true,
paramtype = "light",
})
minetest.register_abm({
nodenames = {"peaceful_npc:npc_spawner"},
interval = 10.0,
chance = 1,
action = function(pos)
npc_spawner(pos)
end,
})
end