local snuma=1 for ii = 0, 9, 1 do if ii==1 then snuma=0 end minetest.register_node("portalgun:sign_numa".. ii, { description = "Sign number (" .. ii ..")", tiles = {"portalgun_snum" .. ii ..".png"}, drop="portalgun:sign_numa1", drawtype = "nodebox", groups = {mesecon=2,portalnuma=1,dig_immediate = 3, not_in_creative_inventory=snuma}, sounds = default.node_sound_wood_defaults(), is_ground_content = false, paramtype2 = "facedir", paramtype = "light", light_source = 3, node_box = { type = "fixed", fixed = { {-0.5, -0.5, 0.4375, 0, 0.5, 0.5}, } }, after_place_node = function(pos, placer, itemstack) local param2=minetest.get_node(pos).param2 local pos2=portalgun_param2(pos,param2) if minetest.get_node(pos2) and minetest.get_node(pos2).name=="air" then minetest.set_node(pos2,{name="portalgun:sign_numb1",param2=param2}) minetest.swap_node(pos, {name="portalgun:sign_numa0", param2=minetest.get_node(pos).param2}) end end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) if not minetest.is_protected(pos,clicker:get_player_name()) then local iin=ii+1 if iin==10 then iin=0 end minetest.swap_node(pos, {name="portalgun:sign_numa".. iin, param2=minetest.get_node(pos).param2}) end end, on_punch = function(pos, node, player, pointed_thing) local param2=minetest.get_node(pos).param2 local pos2=portalgun_param2(pos,param2) local node=minetest.get_node(pos2) if node and minetest.get_node_group(node.name, "portalnumb")>0 then minetest.set_node(pos2, {name = "air"}) end end, }) if snuma==0 then snuma=1 end minetest.register_node("portalgun:sign_numb".. ii, { description = "Sign number", tiles = {"portalgun_snum" .. ii ..".png"}, drop="portalgun:sign_numa1", drawtype = "nodebox", groups = {mesecon=2,portalnumb=1,dig_immediate = 3, not_in_creative_inventory=1}, sounds = default.node_sound_wood_defaults(), is_ground_content = false, paramtype2 = "facedir", paramtype = "light", light_source = 3, node_box = { type = "fixed", fixed = { {-1, -0.5, 0.4375, -0.5, 0.5, 0.5}, } }, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) if not minetest.is_protected(pos,clicker:get_player_name()) then local iin=ii+1 if iin==10 then iin=0 end minetest.swap_node(pos, {name="portalgun:sign_numb".. iin, param2=minetest.get_node(pos).param2}) end end, on_punch = function(pos, node, player, pointed_thing) local param2=minetest.get_node(pos).param2 local pos2=portalgun_param2(pos,param2,true) local node=minetest.get_node(pos2) if node and minetest.get_node_group(node.name, "portalnuma")>0 then minetest.set_node(pos2, {name = "air"}) end end, }) end minetest.register_node("portalgun:turretgun2", { description = "Sentry turret", groups = {cracky=3,not_in_creative_inventory=1}, drop="portalgun:turretgun", paramtype = "light", paramtype2 = "facedir", sunlight_propagates = true, sounds = default.node_sound_defaults(), tiles = {"portalgun_sentry_turret.png"}, drawtype = "mesh", mesh="torret2.obj", selection_box = { type = "fixed", fixed = { {-0.3, -0.5, -0.3, 0.3, 1,0.3}, } }, on_timer=function(pos, elapsed) local p=minetest.get_node(pos).param2 local pos1={x=pos.x,y=pos.y+0.5,z=pos.z} local d for i, ob in pairs(minetest.get_objects_inside_radius(pos, 10)) do if portalgun_visiable(pos1,ob) and (ob:is_player() or (ob:get_luaentity() and (ob:get_luaentity().type or ob:get_luaentity().portalgun==nil))) then local a=ob:get_pos() if a.ypos.y-1 then a={x=math.floor(a.x),y=math.floor(a.y),z=math.floor(a.z)} if p==3 and a.x>pos.x and a.z==pos.z then d={x=20,y=0,z=0} break elseif p==1 and a.xpos.z and a.x==pos.x then d={x=0,y=0,z=20} break elseif p==0 and a.zpos.y-1 then a={x=math.floor(a.x),y=math.floor(a.y),z=math.floor(a.z)} if p==3 and a.x>pos.x and a.z==pos.z then d={x=20,y=0,z=0} break elseif p==1 and a.xpos.z and a.x==pos.x then d={x=0,y=0,z=20} break elseif p==0 and a.z=pos.z then return true end if z==-1 and oz==pos.z and ox<=pos.x then return true end if z==1 and oz==pos.z and ox>=pos.x then return true end return false end minetest.register_node("portalgun:secam_off", { description = "Security cam (off)" , tiles = {"portalgun_scam.png"}, drawtype = "nodebox", walkable=false, groups = {dig_immediate = 3}, sounds = default.node_sound_glass_defaults(), is_ground_content = false, paramtype = "light", paramtype2 = "facedir", node_box = {type="fixed", fixed={ {-0.2, -0.5, -0.2, 0.2, -0.4, 0.2}, {-0.1, -0.2, -0.1, 0.1, -0.4, 0.1}} }, on_place = minetest.rotate_node, on_construct = function(pos) minetest.get_meta(pos):set_string("infotext","click to activate") end, on_rightclick = function(pos, node, player, itemstack, pointed_thing) minetest.set_node(pos, {name ="portalgun:secam", param1 = node.param1, param2 = node.param2}) minetest.get_node_timer(pos):start(1) end, }) minetest.register_node("portalgun:secam", { description = "Security cam", tiles = {"portalgun_scam.png"}, drawtype = "nodebox", walkable=false, groups = {dig_immediate = 3,stone=1,not_in_creative_inventory=1}, sounds = default.node_sound_glass_defaults(), is_ground_content = false, paramtype = "light", paramtype2 = "facedir", drop="portalgun:secam_off", node_box = {type="fixed", fixed={ {-0.2, -0.5, -0.2, 0.2, -0.4, 0.2}, {-0.1, -0.2, -0.1, 0.1, -0.4, 0.1}} }, on_timer=function(pos, elapsed) for i, ob in pairs(minetest.get_objects_inside_radius(pos, 10)) do if ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().itemstring==nil and ob:get_luaentity().portalgun==nil) then if portalgun_visiable(pos,ob) then local v=ob:get_pos() if not ob:get_luaentity() then v.y=v.y+1 end local s={x=(v.x-pos.x)*3,y=(v.y-pos.y)*3,z=(v.z-pos.z)*3} local m=minetest.add_entity(pos, "portalgun:bullet1") m:set_velocity(s) m:set_acceleration(s) minetest.sound_play("portalgun_bullet1", {pos=pos, gain = 1, max_hear_distance = 15,}) minetest.after((math.random(1,9)*0.1), function(pos,s,v) local m=minetest.add_entity(pos, "portalgun:bullet1") m:set_velocity(s) m:set_acceleration(s) minetest.sound_play("portalgun_bullet1", {pos=pos, gain = 1, max_hear_distance = 15,}) end, pos,s,v) end end end return true end, }) minetest.register_entity("portalgun:bullet1",{ hp_max = 1, --physical = true, --collisionbox={-0.01,-0.01,-0.01,0.01,0.01,0.01}, pointable=false, visual = "sprite", visual_size = {x=0.1, y=0.1}, textures = {"default_mese_block.png"}, initial_sprite_basepos = {x=0, y=0}, portalgun=2, bullet=1, on_step= function(self, dtime) self.timer=self.timer+dtime self.timer2=self.timer2+dtime local pos=self.object:get_pos() local n=minetest.registered_nodes[minetest.get_node(self.object:get_pos()).name] if self.timer>1 or (n and n.walkable) then self.object:remove() return end for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do if ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().bullet~=1) then ob:set_hp(ob:get_hp()-7) ob:punch(self.object, 1,{full_punch_interval=1.0,damage_groups={fleshy=4}}, "default:bronze_pick", nil) self.object:remove() return end end end, timer=0, timer2=0, }) minetest.register_node("portalgun:sign1", { description = "Portal sign blue", tiles = {"portalgun_testblock.png^portalgun_sign1.png"}, inventory_image = "portalgun_testblock.png^portalgun_sign1.png", drawtype = "nodebox", groups = {snappy = 3, not_in_creative_inventory=0}, sounds = default.node_sound_wood_defaults(), is_ground_content = false, paramtype2 = "facedir", paramtype = "light", node_box = { type="fixed", fixed={-0.5,-0.5,0.45,0.5,0.5,0.5}}, }) minetest.register_node("portalgun:sign2", { description = "Portal sign orange", tiles = {"portalgun_testblock.png^portalgun_sign2.png"}, inventory_image = "portalgun_testblock.png^portalgun_sign2.png", drawtype = "nodebox", groups = {snappy = 3, not_in_creative_inventory=0}, sounds = default.node_sound_wood_defaults(), is_ground_content = false, paramtype2 = "facedir", paramtype = "light", node_box = { type="fixed", fixed={-0.5,-0.5,0.45,0.5,0.5,0.5}}, })