BobBlocks/trap.lua

201 lines
5.6 KiB
Lua
Raw Normal View History

2013-03-17 15:15:49 +01:00
-- State Changes
local update_bobtrap = function (pos, node)
local nodename=""
local param2=""
--Switch Trap State
2018-09-06 20:22:59 +02:00
if
2013-03-17 15:15:49 +01:00
-- Swap Traps
node.name == 'bobblocks:trap_spike' then nodename = 'bobblocks:trap_spike_set'
elseif node.name == 'bobblocks:trap_spike_set' then nodename = 'bobblocks:trap_spike'
elseif node.name == 'bobblocks:trap_spike_major' then nodename = 'bobblocks:trap_spike_major_set'
elseif node.name == 'bobblocks:trap_spike_major_set' then nodename = 'bobblocks:trap_spike_major'
end
2014-11-30 19:05:15 +01:00
minetest.add_node(pos, {name = nodename})
2013-03-17 15:15:49 +01:00
end
2018-09-06 20:22:59 +02:00
-- Punch Traps
2013-03-17 15:15:49 +01:00
local on_bobtrap_punched = function (pos, node, puncher)
2018-09-06 20:22:59 +02:00
if
2013-03-17 15:15:49 +01:00
-- Start Traps
node.name == 'bobblocks:trap_spike' or node.name == 'bobblocks:trap_spike_set' or
2018-09-06 20:22:59 +02:00
node.name == 'bobblocks:trap_spike_major' or node.name == 'bobblocks:trap_spike_major_set'
2013-03-17 15:15:49 +01:00
then
update_bobtrap(pos, node)
end
end
minetest.register_on_punchnode(on_bobtrap_punched)
--ABM (Spring The Traps)
minetest.register_abm(
{nodenames = {"bobblocks:trap_spike_set"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
2014-11-30 19:05:15 +01:00
local objs = minetest.get_objects_inside_radius(pos, 1)
2013-03-17 15:15:49 +01:00
for k, obj in pairs(objs) do
2018-09-06 20:22:59 +02:00
2013-03-17 15:15:49 +01:00
update_bobtrap(pos, node)
end
end,
2018-09-06 20:22:59 +02:00
2013-03-17 15:15:49 +01:00
})
minetest.register_abm(
{nodenames = {"bobblocks:trap_spike_major_set"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
2014-11-30 19:05:15 +01:00
local objs = minetest.get_objects_inside_radius(pos, 1)
2013-03-17 15:15:49 +01:00
for k, obj in pairs(objs) do
2018-09-06 20:22:59 +02:00
2013-03-17 15:15:49 +01:00
update_bobtrap(pos, node)
end
end,
2018-09-06 20:22:59 +02:00
2013-03-17 15:15:49 +01:00
})
-- Nodes
minetest.register_node("bobblocks:trap_grass", {
description = "Trap Grass",
2015-10-23 19:56:04 +02:00
tiles = {"default_grass.png"},
2013-03-17 15:15:49 +01:00
paramtype2 = "facedir",
legacy_facedir_simple = true,
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
is_ground_content = false,
walkable = false,
climbable = false,
})
2018-09-06 20:22:59 +02:00
local function spikenode(name, desc, texture, drop, groups, drawtype)
minetest.register_node("bobblocks:trap_"..name, {
description = desc,
drawtype = drawtype,
tiles = {"bobblocks_"..texture..".png"},
inventory_image = ("bobblocks_"..texture..".png"),
2013-03-17 15:15:49 +01:00
paramtype = "light",
walkable = false,
sunlight_propagates = true,
2018-09-06 20:22:59 +02:00
groups = groups,
drop = drop,
2013-03-17 15:15:49 +01:00
})
2018-09-06 20:22:59 +02:00
end
2013-03-17 15:15:49 +01:00
2018-09-06 20:22:59 +02:00
local function spike1(name, desc, texture)
spikenode(name, desc, texture, "bobblocks:trap_"..name, {cracky=3,melty=3}, "plantlike")
end
2013-03-17 15:15:49 +01:00
2018-09-06 20:22:59 +02:00
local function spike2(name, desc, texture, drop)
spikenode(name, desc, texture, drop, {cracky=3,melty=3,not_in_creative_inventory=1}, "raillike")
end
spike1("spike", "Trap Spike Minor", "minorspike")
spike2("spike_set", "Trap Spike Minor Set", "trap_set", 'bobblocks:trap_spike')
spike1("spike_major", "Trap Spike Major", "majorspike")
spike2("spike_major_set", "Trap Spike Major Set", "trap_set", 'bobblocks:trap_spike_major')
2013-03-17 15:15:49 +01:00
2018-09-06 20:22:59 +02:00
minetest.register_node("bobblocks:spike_major_reverse", {
description = "Trap Spike Major Reverse",
2013-03-17 15:15:49 +01:00
drawtype = "plantlike",
visual_scale = 1,
2018-09-06 20:22:59 +02:00
tiles = {"bobblocks_majorspike_reverse.png"},
inventory_image = ("bobblocks_majorspike_reverse.png"),
2013-03-17 15:15:49 +01:00
paramtype = "light",
walkable = false,
sunlight_propagates = true,
groups = {cracky=2,melty=2},
})
-- Crafting
minetest.register_craft({
2018-09-06 20:22:59 +02:00
output = 'bobblocks:trap_spike 3',
2013-03-17 15:15:49 +01:00
recipe = {
2018-09-06 20:22:59 +02:00
{'', 'default:obsidian_shard', ''},
{'', 'default:steel_ingot', ''},
2013-03-17 15:15:49 +01:00
}
})
minetest.register_craft({
output = 'bobblocks:trap_spike_major',
recipe = {
2018-09-06 20:22:59 +02:00
{'default:obsidian_shard', 'default:obsidian_shard', 'default:obsidian_shard'},
{'', 'default:steel_ingot', ''},
2013-03-17 15:15:49 +01:00
}
})
minetest.register_craft({
output = 'bobblocks:trap_grass',
recipe = {
{'', '', ''},
{'', 'default:dirt', ''},
{'', 'default:stick', ''},
}
})
2018-09-06 20:22:59 +02:00
minetest.register_craft({
output = 'bobblocks:spike_major_reverse',
recipe = {
{'', 'default:steel_ingot', ''},
{'default:obsidian_shard', 'default:obsidian_shard', 'default:obsidian_shard'},
}
})
2013-03-17 15:15:49 +01:00
-- ABM
minetest.register_abm(
{nodenames = {"bobblocks:trap_spike"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
2014-11-30 19:05:15 +01:00
local objs = minetest.get_objects_inside_radius(pos, 1)
2013-03-17 15:15:49 +01:00
for k, obj in pairs(objs) do
2018-09-06 20:22:59 +02:00
if obj:get_hp() > 0 then --MFF (crabman 8/1/2016) dont re-kill dead player
obj:set_hp(obj:get_hp()-1)
end
2013-03-17 15:15:49 +01:00
minetest.sound_play("bobblocks_trap_fall",
{pos = pos, gain = 1.0, max_hear_distance = 3,})
end
end,
})
minetest.register_abm(
{nodenames = {"bobblocks:trap_spike_major"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
2014-11-30 19:05:15 +01:00
local objs = minetest.get_objects_inside_radius(pos, 1)
2013-03-17 15:15:49 +01:00
for k, obj in pairs(objs) do
2018-09-06 20:22:59 +02:00
if obj:get_hp() > 0 then --MFF (crabman 8/1/2016) dont re-kill dead player
obj:set_hp(obj:get_hp()-100)
end
2013-03-17 15:15:49 +01:00
minetest.sound_play("bobblocks_trap_fall",
2018-09-06 20:22:59 +02:00
{pos = pos, gain = 1.0, max_hear_distance = 3,})
2013-03-17 15:15:49 +01:00
end
end,
})
2018-09-06 20:22:59 +02:00
minetest.register_abm(
{nodenames = {"bobblocks:spike_major_reverse"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
pos.y = pos.y-1.2
local objs = minetest.get_objects_inside_radius(pos, 1)
for k, obj in pairs(objs) do
if obj:get_hp() > 0 then --MFF (crabman 8/1/2016) dont re-kill dead player
obj:set_hp(obj:get_hp()-100)
end
minetest.sound_play("bobblocks_trap_fall",
{pos = pos, gain = 1.0, max_hear_distance = 3,})
end
end,
})