nssm-server/mob_inhibitor.lua

105 lines
3.6 KiB
Lua
Raw Permalink Normal View History

2019-01-02 13:45:27 -08:00
--[[
2019-01-03 09:55:08 -08:00
Obliterate NSSM monsters that approach Mob Inhibitor nodes
2019-01-02 13:45:27 -08:00
2019-01-03 09:55:08 -08:00
By default, an admin-only inhibitor node is provided.
Optionally, other nodes can benefit from the inhibition effect.
2019-01-02 13:45:27 -08:00
--]]
nssm_server = {}
2019-01-06 09:05:40 -08:00
local inhibition_radius = tonumber(minetest.settings:get("nssm_server.inhibition_radius")) or 8
2019-01-02 14:04:36 -08:00
2019-01-03 09:55:08 -08:00
-- Recommended ---> protector:protect,protector:protect2,cityblock:cityblock
2019-01-06 09:05:40 -08:00
local inhibition_nodes = minetest.settings:get("nssm_server.inhibition_nodes") or ""
2019-01-03 09:55:08 -08:00
inhibition_nodes = inhibition_nodes:split(",")
-- Always include the inhibitor node
inhibition_nodes[#inhibition_nodes+1] = "nssm:mob_inhibitor"
2019-01-02 13:45:27 -08:00
minetest.register_privilege("mob_inhibitor", {description="Allows placing mob inhibitor blocks"})
minetest.register_node("nssm_server:mob_inhibitor", {
description = "NSSM Monster Ward",
tiles = {
"default_obsidian.png^proud_soul_fragment.png", -- top
"default_obsidian.png^greedy_soul_fragment.png", --under
"default_obsidian.png^phoenix_fire_bomb.png", -- back
"default_obsidian.png^phoenix_fire_bomb.png", -- side
"default_obsidian.png^phoenix_fire_bomb.png", --side
"default_obsidian.png^phoenix_fire_bomb.png", --front
},
groups = {cracky = 1, level = 4, not_in_creative_inventory = 1},
sounds = default.node_sound_stone_defaults(),
drop = "",
2019-01-05 10:36:19 -08:00
on_blast = function() end,
2019-01-02 13:45:27 -08:00
on_place = function(itemstack, placer, pointed_thing)
local playername = placer:get_player_name()
local privs = minetest.get_player_privs(playername)
if privs.mob_inhibitor then
return minetest.item_place(itemstack, placer, pointed_thing)
else
minetest.log("action", playername.." prevented from using nssm_server:mob_inhibitor")
return
end
end
})
-- Remove from main NSSM
minetest.register_alias("nssm:mob_inhibitor", "nssm_server:mob_inhibitor")
function nssm_server:inhibit_effect(pos,radius)
radius = radius or 1
minetest.add_particlespawner({
amount = 80,
time = 1,
minpos = {x=pos.x-radius/2, y=pos.y-radius/2, z=pos.z-radius/2},
maxpos = {x=pos.x+radius/2, y=pos.y+radius/2, z=pos.z+radius/2},
minlevel = {x=-0, y=-0, z=-0},
maxlevel = {x=1, y=1, z=1},
minacc = {x=-0.5,y=5,z=-0.5},
maxacc = {x=0.5,y=5,z=0.5},
minexptime = 0.1,
maxexptime = 1,
minsieze = 3,
maxsieze = 4,
collisiondetection = false,
texture = "morparticle.png^[colorize:yellow:200^[colorize:white:100"
})
minetest.sound_play("nssm_inhibit", {
pos = pos,
2019-01-02 14:04:36 -08:00
max_hear_distance = inhibition_radius*2,
2019-01-02 13:45:27 -08:00
})
end
-- Inhibition block - place in spawn buildings on servers
minetest.register_abm({
label = "Monster Inhibition Block",
2019-01-03 09:55:08 -08:00
nodenames = inhibition_nodes,
2019-01-02 13:45:27 -08:00
interval = 1,
chance = 1,
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
local obj, istring, lua_entity
2019-01-02 14:04:36 -08:00
for _,obj in pairs(minetest.get_objects_inside_radius(pos , inhibition_radius)) do
2019-01-02 13:45:27 -08:00
if not obj:is_player() and obj:get_luaentity() then
lua_entity = obj:get_luaentity()
istring = lua_entity["name"]
2019-01-03 09:55:08 -08:00
-- We got a name, it's nssm and it is monster mob
if istring and istring:sub(1,5) == "nssm:" and lua_entity.type == "monster" then
2019-01-02 13:45:27 -08:00
nssm_server:inhibit_effect(obj:get_pos())
obj:remove()
end
end
end
end,
})