split it into separate files

This commit is contained in:
Bruno Rybársky 2022-07-12 10:20:50 +02:00
parent f580dcd720
commit 3ebdae5ea1
38 changed files with 3107 additions and 2468 deletions

@ -1,160 +0,0 @@
portalgun_power={}
portalgun_power_tmp_power=0
function portalgun_gravity(itemstack, user, pointed_thing)
local ob=pointed_thing.ref
local at = ob:get_attach()
if at and at:get_luaentity() and at:get_luaentity().portalgun_power then
ob:set_detach()
local target = at:get_luaentity().target
if target and target:get_luaentity() and (target:get_luaentity().itemstring or target:get_luaentity().wsc) then
target:set_velocity({x=0, y=-1, z=0})
target:set_acceleration({x=0, y=-8, z=0})
end
return itemstack
end
if not ob:get_attach() and (ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().powerball~=1)) then
--if 4 blocks or closer to player
if vector.distance(ob:get_pos(),user:get_pos())<4 then
portalgun_power.user=user
portalgun_power.target=ob
if ob:is_player() then portalgun_power.player=1 end
local m=minetest.add_entity(ob:get_pos(), "portalgun:power")
ob:set_attach(m, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
return itemstack
end
end
return itemstack
end
minetest.register_entity("portalgun:power",{
hp_max = 100,
physical = false,
weight = 0,
collisionbox = {-0.2,-0.2,-0.2, 0.2,0.2,0.2},
visual = "sprite",
visual_size = {x=1, y=1},
textures = {"portalgun_gravity.png"},
spritediv = {x=1, y=1},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = 0,
timer=0,
time=0.1,
portalgun_power=1,
portalgun=1,
lifelime=100,
on_activate=function(self, staticdata)
if portalgun_power.user then
self.user=portalgun_power.user
self.target=portalgun_power.target
self.player=portalgun_power.player
portalgun_power={}
else
self.object:remove()
end
end,
on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if self.target and self.target:get_attach() then
self.target:set_detach()
self.target:set_hp(0)
end
end,
on_step= function(self, dtime)
self.timer=self.timer+dtime
if self.timer<self.time then return self end
self.timer=0
if self.target==nil or (not self.target:get_attach()) then
self.object:set_hp(0)
if self.sound then minetest.sound_stop(self.sound) end
end
if self.player then
self.lifelime=self.lifelime-1
if self.lifelime<0 then
self.target:set_detach()
return self
end
end
local pos = self.user:get_pos()
if pos==nil then return self end
pos.y=pos.y+1.6
local dir = self.user:get_look_dir()
local npos={x=pos.x+(dir.x*2), y=pos.y+(dir.y*2), z=pos.z+(dir.z*2)}
if minetest.registered_nodes[minetest.get_node(npos).name].walkable then
return self
end
self.object:move_to(npos)
return self
end,
})
minetest.register_entity("portalgun:power2",{
hp_max = 100,
physical = true,
weight = 10,
collisionbox = {-0.35,0,-0.35, 0.35,1,0.35},
visual = "sprite",
visual_size = {x=1, y=1},
textures = {"portalgun_gravity.png"},
spritediv = {x=1, y=1},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = 0,
timer=0,
time=0.025,
portalgun_power=1,
portalgun=1,
lifelime=1000,
v=0.3,
ltime=0,
on_activate=function(self, staticdata)
if portalgun_power.user then
self.user=portalgun_power.user
self.target=portalgun_power.target
self.ltime=portalgun_power_tmp_power
portalgun_power={}
else
self.object:remove()
end
end,
on_step= function(self, dtime)
local pos=self.object:get_pos()
local v=self.object:get_velocity()
local v2={x=v.x-self.v,y=(v.y-self.v)*0.99,z=v.z-self.v}
if v2.x<0.5 and v2.x>-0.5 then v2.x=0 end
if v2.y<0.5 and v2.y>-0.5 then v2.y=0 end
if v2.z<0.5 and v2.z>-0.5 then v2.z=0 end
self.object:set_velocity(v2)
self.ltime=self.ltime-self.v
if self.ltime<self.v or (v2.x+v2.y+v2.z==0) then
self.lifelime=-1
end
local nexpos={x=pos.x+(v.x*0.05),y=pos.y+(v.y*0.05)+1,z=pos.z+(v.z*0.05)}
if minetest.registered_nodes[minetest.get_node(nexpos).name].walkable then
self.lifelime=-1
end
self.lifelime=self.lifelime-1
if self.lifelime<0 then
self.target:set_detach()
end
if self.target==nil or (not self.target:get_attach()) then
self.object:set_hp(0)
return self
end
return self
end,
})

592
init.lua

@ -1,556 +1,38 @@
disable_portal_stuff=false
proportal_group_only = false
--do scripts in folder scripts
portalgun={new=0,checkpoints={}}
dofile(minetest.get_modpath("portalgun") .. "/gravityuse.lua") -- the gravity part of portalgun
dofile(minetest.get_modpath("portalgun") .. "/stuff.lua") -- security cam
if disable_portal_stuff==false and minetest.get_modpath("mesecons")~=nil then
dofile(minetest.get_modpath("portalgun") .. "/weightedstoragecube.lua") -- weighted storage cube
dofile(minetest.get_modpath("portalgun") .. "/powerball.lua") -- the poweball
dofile(minetest.get_modpath("portalgun") .. "/other.lua")
end
portalgun_portal={}
portalgun_portal_tmp_user_abort=0
portalgun_portal_tmp_user=""
local portalgun_timer=1.2
local portalgun_time=0
portalgun_lifelime=1200 --deletes portals that not used after a while
portalgun_max_rage=100
portalgun_max_use_per_secund_time=4 --destroys the portal if excessive used
portalgun_max_use_per_secund=25 --4 & 25 is default = teleported (teleported 25 times in 4 sec)
function portalgun_param2(pos,param2,r)
local pos2={x=pos.x,y=pos.y,z=pos.z}
if r then
if param2==0 then
pos2.x=pos2.x-1
elseif param2==1 then pos2.z=pos2.z+1
elseif param2==2 then pos2.x=pos2.x+1
elseif param2==3 then pos2.z=pos2.z-1
end
else
if param2==0 then
pos2.x=pos2.x+1
elseif param2==1 then pos2.z=pos2.z-1
elseif param2==2 then pos2.x=pos2.x-1
elseif param2==3 then pos2.z=pos2.z+1
end
end
return pos2
end
local function portalgun_getLength(a)-- get length of an array / table
local count = 0
for _ in pairs(a) do count = count + 1 end
return count
end
function portal_delete(name,n) -- using set_hp & :punch instand of :remove ... no risk for crash if something attach it
if portalgun_portal[name]==nil then return end
if (n==1 or n==0) and portalgun_portal[name].portal1~=nil then
if n==0 then
local pos=portalgun_portal[name].portal1:get_pos()
if pos~=nil then minetest.sound_play("portalgun_closeportals", {pos=pos,max_hear_distance = 20, gain = 1}) end
end
portalgun_portal[name].portal1_active=false
portalgun_portal[name].portal1:set_hp(0)
end
if (n==2 or n==0) and portalgun_portal[name].portal2~=nil then
if n==0 then
local pos=portalgun_portal[name].portal2:get_pos()
if pos~=nil then minetest.sound_play("portalgun_closeportals", {pos=pos,max_hear_distance = 20, gain = 1}) end
end
portalgun_portal[name].portal2_active=false
portalgun_portal[name].portal2:set_hp(0)
end
if n==0 then portalgun_portal[name]=nil end
end
minetest.register_on_leaveplayer(function(player)-- deletes user the profile (saveing memory)
local name=player:get_player_name()
portal_delete(name,0)
portalgun_portal[name]=nil
end)
minetest.register_on_dieplayer(function(player)
local name=player:get_player_name()
portal_delete(name,0)
portalgun_portal[name]=nil
end)
portalgun_on_step=function(self, dtime)
local name=self.user
if portalgun_portal[self.user]==nil then
self.object:remove()
return self
end
if (self.project==1 and self.use~=portalgun_portal[self.user].portal1_use)
or (self.project==2 and self.use~=portalgun_portal[self.user].portal2_use) then
self.object:remove()
return self
end
if portalgun_portal[name].lifelime<0 then
portal_delete(name,0)
return self
end
if portalgun_portal[name].portal1_active and portalgun_portal[name].portal2_active then -- makes lifetime equal when both is acive, or it will be half
portalgun_portal[name].lifelime=portalgun_portal[name].lifelime-0.5
else
portalgun_portal[name].lifelime=portalgun_portal[name].lifelime-1
return self -- abort when only 1 is active (saves cpu)
end
if portalgun_portal[name].timer>0 then -- makes teleported stuff wont move back at same time (bug fix)
portalgun_portal[name].timer=portalgun_portal[name].timer-dtime
return self
end
if self.portal_max_use>0 then -- makes teleported stuff wont move back at same time (bug fix)
self.portal_max_use_time=self.portal_max_use_time+dtime
if self.portal_max_use>=portalgun_max_use_per_secund then
portal_delete(name,self.project)
return self
elseif self.portal_max_use_time>=portalgun_max_use_per_secund_time then
self.portal_max_use_time=0
self.portal_max_use=0
end
end
local pos1=0
local pos2=0
local d1=0
local d2=0
if self.project==1 then
pos1=portalgun_portal[name].portal1_pos
pos2=portalgun_portal[name].portal2_pos
d1=portalgun_portal[name].portal1_dir
d2=portalgun_portal[name].portal2_dir
else
pos1=portalgun_portal[name].portal2_pos
pos2=portalgun_portal[name].portal1_pos
d1=portalgun_portal[name].portal2_dir
d2=portalgun_portal[name].portal1_dir
end
-- portalgun_front_of_field should fix teleport through walls, but is not working in all directions
-- waiting with this issue
if pos2~=0 and pos1~=0 then
for ii, ob in pairs(minetest.get_objects_inside_radius(pos1, self.area)) do
if pos2~=0 then --and portalgun_front_of_field(self.object,ob)
if (ob:is_player() ) or (ob:get_luaentity() and ob:get_luaentity().portalgun~=1 and ob:get_luaentity().name:find(":text",4)==nil) then
if ob:get_attach() then
ob:set_detach()
ob:set_acceleration({x=0, y=-10, z=0})
end
--set velocity then teleport
local p=pos2
local x=0
local y=0
local z=0
local dis=2
if p==nil or p.x==nil then
return self
end
if ob:is_player() then
local v=ob:get_player_velocity()
local player_name=ob:get_player_name()
portalgun_power.user=player_name
portalgun_power.target=ob
local vv={x=v.x,y=v.y,z=v.z}
-- get the highest velocity
dis=2
if vv.x+vv.y+vv.z<=0.3 then
if self.small==true then
vv.x=1.4
else
vv.x=2
end
end
if vv.x+vv.y+vv.z==0 then vv.x=2 end
if vv.x<0 then vv.x=vv.x*-1 end
if vv.y<0 then vv.y=vv.y*-1 end
if vv.z<0 then vv.z=vv.z*-1 end
if vv.x>vv.z then vv.a=vv.x else vv.a=vv.z end
if vv.a<vv.y then vv.a=vv.y end
portalgun_power_tmp_power=vv.a
local m=minetest.add_entity(ob:get_pos(), "portalgun:power2")
ob:set_attach(m, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
m:set_velocity(v)
m:set_acceleration({x=0,y=-10,z=0})
ob=m
end
if ob:is_player()==false then
local v=ob:get_velocity()
if v.x<0 then v.x=v.x*-1 end
if v.y<0 then v.y=v.y*-1 end
if v.z<0 then v.z=v.z*-1 end
local vv=0 -- get the highest velocity
if v.x>v.z then vv=v.x else vv=v.z end
if vv<v.y then vv=v.y end
v.x=0
v.y=0
v.z=0
if d2=="x+" then v.x=vv end
if d2=="x-" then v.x=vv*-1 end
if d2=="y+" then v.y=vv end
if d2=="y-" then v.y=vv*-1 end
if d2=="z+" then v.z=vv end
if d2=="z-" then v.z=vv*-1 end
ob:set_velocity({x=v.x, y=v.y, z=v.z})
end
if d2=="x+" then x=2
elseif d2=="x-" then x=-dis
elseif d2=="y+" then y=dis
elseif d2=="y-" then y=-dis
elseif d2=="z+" then z=dis
elseif d2=="z-" then z=-dis
end
local obpos={x=p.x+x,y=p.y+y,z=p.z+z}
portalgun_portal[name].timer=0.2
self.portal_max_use=self.portal_max_use+1
ob:set_pos(obpos,false)
portalgun_portal[name].lifelime=portalgun_lifelime
minetest.sound_play("portalgun_teleport", {pos=portalgun_portal[name].portal1_pos,max_hear_distance = 10, gain = 30})
minetest.sound_play("portalgun_teleport", {pos=portalgun_portal[name].portal2_pos,max_hear_distance = 10, gain = 30})
end --end of set velocity part then teleport
end
end
end
end
minetest.register_entity("portalgun:portal",{ -- the portals
hp_max=10000,
visual = "mesh",
mesh = "portalgun_portal_xp.obj",
physical = false,
textures ={"portalgun_blue.png"},
visual_size = {x=1, y=1},
spritediv = {x=7, y=0},
collisionbox = {0,0,0,0,0,0},
timer=0,
user="",
project=1,
portalgun=1,
portal_max_use=0,
portal_max_use_time=0,
area=2,
small=false,
get_staticdata = function(self)
return minetest.serialize({
user= self.user,
project=self.project,
use=self.use
})
end,
on_activate= function(self, staticdata)
local data=minetest.deserialize(staticdata)
if data and type(data) == "table" then
self.user = data.user
self.project = data.project
self.use=data.use
if portalgun_portal[self.user]==nil then
self.object:remove()
return self
end
if (self.project==1 and self.use~=portalgun_portal[self.user].portal1_use)
or (self.project==2 and self.use~=portalgun_portal[self.user].portal2_use) then
self.object:remove()
return self
end
elseif portalgun_portal_tmp_user~="" then
self.user=portalgun_portal_tmp_user
portalgun_portal_tmp_user=""
self.project=portalgun_portal[self.user].project
if self.project==1 then-- if inactivated then activated and another portal is created: remove
self.use=portalgun_portal[self.user].portal1_use
else
self.use=portalgun_portal[self.user].portal2_use
end
else
self.object:remove()
return self
end
if portalgun_portal[self.user]==nil then
self.object:remove()
return self
end
local d=""
if self.project==1 then
d=portalgun_portal[self.user].portal1_dir
self.object:set_properties({textures = {"portalgun_blue.png"}})
else
d=portalgun_portal[self.user].portal2_dir
self.object:set_properties({textures = {"portalgun_orange.png"}})
end
if d=="x+" then self.object:set_yaw(math.pi * 0)
elseif d=="x-" then self.object:set_yaw(math.pi * 1)
elseif d=="y+" then self.object:set_properties({mesh = "portalgun_portal_yp.obj",}) -- becaouse there is no "setpitch"
elseif d=="y-" then self.object:set_properties({mesh = "portalgun_portal_ym.obj",}) -- becaouse there is no "setpitch"
elseif d=="z+" then self.object:set_yaw(math.pi * 0.5)
elseif d=="z-" then self.object:set_yaw(math.pi * 1.5)
end
if d=="y+" then
local pos1={}
if self.project==1 then
pos1=portalgun_portal[self.user].portal1_pos
else
pos1=portalgun_portal[self.user].portal2_pos
end
if portalgun_portal[self.user].y>8 then
pos1.y=pos1.y+1
end
if portalgun_portal[self.user].y>12 then
pos1.y=pos1.y+1
end
if self.project==1 then
portalgun_portal[self.user].portal1_pos=pos1
else
portalgun_portal[self.user].portal2_pos=pos1
end
elseif string.find(d,"y",1)==nil and (portalgun_portal[self.user].x+portalgun_portal[self.user].z<2.5) then
self.area=1.2
self.small=true
self.object:set_properties({visual_size = {x=0.7, y=0.7},})
end
end,
on_step=portalgun_on_step,
})
minetest.register_craftitem(":", {
description = "Portalgun",
range = 100,
inventory_image = "portalgun_gun0_rndr.png",
wield_image = "portalgun_gun0_rndr.png",
tool_capabilities = {
full_punch_interval = 0.5,
max_drop_level = 3,
groupcaps = {
fleshy = {times={[2]=0.80, [3]=0.40}, uses=100, maxlevel=3},
oddly_breakable_by_hand = {times={[1]=1}, uses=100, maxlevel=1},
},
damage_groups = {fleshy=1},
},
on_place=function(itemstack, user, pointed_thing)
local node = minetest.get_node(pointed_thing.under)
if node.name=="portalgun:button"then
--use the item normally
minetest.item_place(itemstack, user, pointed_thing)
else
portalgun_onuse(itemstack, user, pointed_thing, 2)
end
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
--if pointing at turret then start breaking it
if pointed_thing.type=="node" then
local node=minetest.get_node(pointed_thing.under)
if node.name=="portalgun:turretgun" or node.name=="portalgun:turretgun2" then
minetest.remove_node(pointed_thing.under)
end
end
portalgun_onuse(itemstack, user, pointed_thing, 1)
return itemstack
end
})
local function rnd(r)
return math.floor(r+ 0.5)
end
function portalgun_onuse(itemstack, user, pointed_thing, mode) -- using the gun
if pointed_thing.type=="object" then
portalgun_gravity(itemstack, user, pointed_thing)
return itemstack
end
local pos = user:get_pos()
local dir = user:get_look_dir()
local key = user:get_player_control()
local name=user:get_player_name()
local exist=0
local item=itemstack:to_table()
local ob={}
ob.project=1
ob.lifelime=portalgun_lifelime
ob.portal1=0
ob.portal2=0
ob.portal1_dir=0
ob.portal2_dir=0
ob.portal2_pos=0
ob.portal1_pos=0
ob.user = user:get_player_name()
if portalgun_portal[name]==nil then -- new portal profile
portalgun_portal[name]={lifelime=portalgun_lifelime,project=1,timer=0,portal1_active=false,portal2_active=false,portal1_use=0,portal2_use=0}
end
if key.sneak then
portal_delete(name,0)
return itemstack
end
pos.y=pos.y+1.5
-- the project
for i=1, portalgun_max_rage,0.5 do
local nname=minetest.get_node({x=pos.x+(dir.x*i), y=pos.y+(dir.y*i), z=pos.z+(dir.z*i)}).name
if minetest.registered_nodes[nname].walkable then
portalgun_portal[name].lifelime=portalgun_lifelime
if not proportal_group_only and minetest.get_node_group(nname, "antiportal") > 0 then
minetest.sound_play("portalgun_error", {pos=pos,max_hear_distance = 5, gain = 3})
return itemstack
elseif proportal_group_only and minetest.get_node_group(nname, "proportal") == 0 then
minetest.sound_play("portalgun_error", {pos=pos,max_hear_distance = 5, gain = 3})
return itemstack
end
if minetest.registered_nodes[minetest.get_node({x=rnd(pos.x+(dir.x*i)), y=rnd(pos.y+(dir.y*i)+1), z=rnd(pos.z+(dir.z*i))}).name].walkable==false and rnd(user:get_pos().y)>rnd(pos.y+(dir.y*i)) then
portalgun_setportal(pos,name,dir,i,mode,"y+")
return itemstack
elseif minetest.registered_nodes[minetest.get_node({x=rnd(pos.x+(dir.x*i)), y=rnd(pos.y+(dir.y*i)-1), z=rnd(pos.z+(dir.z*i))}).name].walkable==false and rnd(user:get_pos().y)<rnd(pos.y+(dir.y*i)) then
portalgun_setportal(pos,name,dir,i,mode,"y-")
return itemstack
elseif minetest.registered_nodes[minetest.get_node({x=rnd(pos.x+(dir.x*i)-1), y=rnd(pos.y+(dir.y*i)), z=rnd(pos.z+(dir.z*i))}).name].walkable==false and rnd(user:get_pos().x)<rnd(pos.x+(dir.x*i)) then
portalgun_setportal(pos,name,dir,i,mode,"x-")
return itemstack
elseif minetest.registered_nodes[minetest.get_node({x=rnd(pos.x+(dir.x*i))+1, y=rnd(pos.y+(dir.y*i)), z=rnd(pos.z+(dir.z*i))}).name].walkable==false and rnd(user:get_pos().x)>rnd(pos.x+(dir.x*i)) then
portalgun_setportal(pos,name,dir,i,mode,"x+")
return itemstack
elseif minetest.registered_nodes[minetest.get_node({x=rnd(pos.x+(dir.x*i)), y=rnd(pos.y+(dir.y*i)), z=rnd(pos.z+(dir.z*i)-1)}).name].walkable==false and rnd(user:get_pos().z)<rnd(pos.z+(dir.z*i)) then
portalgun_setportal(pos,name,dir,i,mode,"z-")
return itemstack
elseif minetest.registered_nodes[minetest.get_node({x=rnd(pos.x+(dir.x*i)), y=rnd(pos.y+(dir.y*i)), z=rnd(pos.z+(dir.z*i)+1)}).name].walkable==false and rnd(user:get_pos().z)>rnd(pos.z+(dir.z*i)) then
portalgun_setportal(pos,name,dir,i,mode,"z+")
return itemstack
end
minetest.sound_play("portalgun_error", {pos=pos,max_hear_distance = 20, gain = 3})
return itemstack
end
end
return itemstack
end
function portalgun_setportal(pos,name,dir,i,mode,portal_dir)
local lpos={x=pos.x+(dir.x*(i-1)), y=pos.y+(dir.y*(i-1)), z=pos.z+(dir.z*(i-1))} -- last pos
local cpos={x=pos.x+(dir.x*i), y=pos.y+(dir.y*i), z=pos.z+(dir.z*i)} -- corrent poss
if portal_dir=="y+" then
cpos.y=(math.floor(cpos.y+ 0.5))+0.524
elseif portal_dir=="y-" then
cpos.y=(math.floor(cpos.y+ 0.5))-0.524
elseif portal_dir=="z+" then
cpos.z=(math.floor(cpos.z+ 0.5))+0.524
elseif portal_dir=="z-" then
cpos.z=(math.floor(cpos.z+ 0.5))-0.524
elseif portal_dir=="x+" then
cpos.x=(math.floor(cpos.x+ 0.5))+0.524
elseif portal_dir=="x-" then
cpos.x=(math.floor(cpos.x+ 0.5))-0.524
end
if portal_dir=="x+" or portal_dir=="x-" then -- auto correct (place in center)
cpos.y=(math.floor(cpos.y+ 0.5))
cpos.z=(math.floor(cpos.z+ 0.5))
elseif portal_dir=="y+" or portal_dir=="y-" then
cpos.x=(math.floor(cpos.x+ 0.5))
cpos.z=(math.floor(cpos.z+ 0.5))
elseif portal_dir=="z+" or portal_dir=="z-" then
cpos.x=(math.floor(cpos.x+ 0.5))
cpos.y=(math.floor(cpos.y+ 0.5))
end
if minetest.registered_nodes[minetest.get_node(cpos).name].walkable then
minetest.sound_play("portalgun_error", {pos=pos,max_hear_distance = 5, gain = 3})
return false
end
if string.find(portal_dir,"x",1) or string.find(portal_dir,"z",1) then-- auto correct (move from bottom / top)
local testpos1={x=cpos.x,y=cpos.y-1,z=cpos.z}
local testpos2={x=cpos.x,y=cpos.y+1,z=cpos.z}
if minetest.registered_nodes[minetest.get_node(testpos1).name].walkable
and minetest.registered_nodes[minetest.get_node(testpos2).name].walkable==false then
cpos.y=cpos.y+0.5
elseif minetest.registered_nodes[minetest.get_node(testpos2).name].walkable
and minetest.registered_nodes[minetest.get_node(testpos1).name].walkable==false then
cpos.y=cpos.y-0.5
end
end
portalgun_portal_tmp_user=name
portalgun_portal[name].x=pos.x-lpos.x
portalgun_portal[name].y=pos.y-lpos.y
portalgun_portal[name].z=pos.z-lpos.z
portalgun_portal[name].project=mode
if portalgun_portal[name].x<0 then
portalgun_portal[name].x=portalgun_portal[name].x*-1
end
if portalgun_portal[name].z<0 then
portalgun_portal[name].z=portalgun_portal[name].z*-1
end
if mode==1 then
portal_delete(name,1)
portalgun_portal[name].portal1_use=portalgun_portal[name].portal1_use+1
portalgun_portal[name].portal1_dir=portal_dir
portalgun_portal[name].portal1_pos=cpos
portalgun_portal[name].portal1=minetest.add_entity(cpos, "portalgun:portal")
portalgun_portal[name].portal1_active=true
minetest.sound_play("portalgun_portalblue", {pos=cpos, max_hear_distance = 20, gain = 1})
else
portal_delete(name,2)
portalgun_portal[name].portal2_use=portalgun_portal[name].portal2_use+1
portalgun_portal[name].portal2_dir=portal_dir
portalgun_portal[name].portal2_pos=cpos
portalgun_portal[name].portal2=minetest.add_entity(cpos, "portalgun:portal")
portalgun_portal[name].portal2_active=true
minetest.sound_play("portalgun_portalorange", {pos=cpos,max_hear_distance = 20, gain = 1})
end
end
portalgun_front_of_field=function(ob,ob2)
local pos2=ob2:get_pos()
return vector.distance(ob:get_pos(),pos2)>vector.distance(portalgun_pointat(ob),pos2)
end
portalgun_pointat=function(ob)
local pos=ob:get_pos()
local yaw=ob:get_yaw()
if yaw ~= yaw or type(yaw)~="number" then
yaw=0
end
local z =math.sin(yaw) * -0.1
local x =math.cos(yaw) * 0.1
return {x=pos.x+x,y=pos.y,z=pos.z+z}
end
--portalgun
dofile(minetest.get_modpath("portalgun") .. "/scripts/portalgun.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/gravityuse.lua")
--powerball
dofile(minetest.get_modpath("portalgun") .. "/scripts/powerball.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/powerballspawner.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/powerballtarget.lua")
--cubes
dofile(minetest.get_modpath("portalgun") .. "/scripts/weightedstoragecube.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/cubespawners.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/pressureplatforms.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/fizzlers.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/checkpoint.lua")
--misc
dofile(minetest.get_modpath("portalgun") .. "/scripts/buildingblocks.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/warntape.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/cake.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/editingtools.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/portaltarget.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/signs.lua")
--hazardous
dofile(minetest.get_modpath("portalgun") .. "/scripts/toxicwater.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/turrets.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/camera.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/damageblock.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/objectdestroyer.lua")
--logic
dofile(minetest.get_modpath("portalgun") .. "/scripts/delayer.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/button.lua")
dofile(minetest.get_modpath("portalgun") .. "/scripts/doors.lua")

@ -1,3 +1,3 @@
name = portalgun
description = Portals and stuff
optional_depends = mesecons
depends = mesecons

637
other.lua

@ -1,637 +0,0 @@
local pgad_rules={{x = 1, y = 0, z = 0},{x =-1, y = 0, z = 0},{x = 0, y = 1, z = 0},{x = 0, y =-1, z = 0},{x = 0, y = 0, z = 1},{x = 0, y = 0, z =-1}}
stone_sounds = {}
stone_sounds.footstep = {name="stone_walk", gain=1.0}
stone_sounds.dug = {name="stone_break", gain=1.0}
stone_sounds.place = {name="block_place", gain=1.0}
glass_sounds = {}
glass_sounds.footstep = {name="glass_walk", gain=1.0}
glass_sounds.dug = {name="glass_break", gain=1.0}
glass_sounds.place = {name="block_place", gain=1.0}
wood_sounds = {}
wood_sounds.footstep = {name="wood_walk", gain=1.0}
wood_sounds.dug = {name="wood_break", gain=1.0}
wood_sounds.place = {name="block_place", gain=1.0}
minetest.register_node("portalgun:cplps1", {
description = "Close player portal",
tiles = {"portalgun_gray.png"},
groups = {mesecon=2,snappy = 3, not_in_creative_inventory=0},
sounds = stone_sounds,
is_ground_content = false,
mesecons = {effector = {
action_on = function (pos, node)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 6)) do
if ob and ob:is_player() then
portal_delete(ob:get_player_name(),0)
end
end
minetest.swap_node(pos, {name="portalgun:cplps2"})
minetest.after((2), function(pos)
minetest.swap_node(pos, {name="portalgun:cplps1"})
end, pos)
return false
end,
}}
})
minetest.register_node("portalgun:cplps3", {
description = "Close player portal when player is near",
tiles = {"portalgun_gray.png"},
groups = {snappy = 3, not_in_creative_inventory=0},
sounds = stone_sounds,
is_ground_content = false,
--every 2 seconds, check if player is near and close portal if so
on_timer = function (pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 4)) do
if ob and ob:is_player() then
minetest.sound_play("portalgun_close", {pos=pos, gain=1.0, max_hear_distance = 10,})
portal_delete(ob:get_player_name(),0)
end
--destroy Weighted storage cubes
--if name starts with '''portalgun:wsc'''
if ob and ob:get_luaentity() and ob:get_luaentity().name and string.sub(ob:get_luaentity().name,1,13) == "portalgun:wsc" then
ob:remove()
end
end
local timer = minetest.get_node_timer(pos)
timer:start(2)
return true
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local timer = minetest.get_node_timer(pos)
timer:start(2)
end,
})
minetest.register_node("portalgun:cplps2", {
description = "Close player portal",
tiles = {"portalgun_gray.png^[colorize:#ffe85977"},
groups = {mesecon=2,snappy = 3, not_in_creative_inventory=1},
sounds = stone_sounds,
is_ground_content = false,
paramtype = "light",
light_source = 4,
})
minetest.register_node("portalgun:sign_v", {
description = "Sign V",
tiles = {"portalgun_v.png"},
inventory_image = "portalgun_v.png",
drop="portalgun:sign_x",
drawtype = "nodebox",
groups = {mesecon=2,snappy = 3, not_in_creative_inventory=1},
sounds = wood_sounds,
is_ground_content = false,
paramtype2 = "facedir",
paramtype = "light",
light_source = 5,
node_box = {
type="fixed",
fixed={-0.5,-0.5,0.45,0.5,0.5,0.5}},
mesecons = {effector = {
action_off = function (pos, node)
minetest.swap_node(pos, {name="portalgun:sign_x", param2=minetest.get_node(pos).param2})
end,
}}
})
minetest.register_node("portalgun:sign_x", {
description = "Sign X",
tiles = {"portalgun_x.png"},
inventory_image = "portalgun_x.png",
drawtype = "nodebox",
groups = {mesecon=2,snappy = 3, not_in_creative_inventory=0},
sounds = wood_sounds,
is_ground_content = false,
paramtype2 = "facedir",
paramtype = "light",
light_source = 3,
node_box = {
type="fixed",
fixed={-0.5,-0.5,0.45,0.5,0.5,0.5}},
mesecons = {effector = {
action_on = function (pos, node)
minetest.swap_node(pos, {name="portalgun:sign_v", param2=minetest.get_node(pos).param2})
end,
}}
})
local portaltarget_sig={
{1,"portalgun_blue.png"},
{2,"portalgun_orange.png"},
}
for ii = 1, #portaltarget_sig, 1 do
minetest.register_node("portalgun:portaltarget_" .. portaltarget_sig[ii][1], {
description = "Portal target " .. portaltarget_sig[ii][1] ,
tiles = {"portalgun_testblock.png^" .. portaltarget_sig[ii][2]},
groups = {mesecon = 2,cracky=2},
mesecons = {receptor = {state = "off"}},
sounds = stone_sounds,
is_ground_content = false,
paramtype2 = "facedir",
paramtype = "light",
on_timer = function (pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 2)) do
if ob:get_luaentity() and ob:get_luaentity().portalgun and ob:get_luaentity().project==portaltarget_sig[ii][1] then
mesecon.receptor_on(pos)
return true
end
end
mesecon.receptor_off(pos)
return true
end,
on_construct = function(pos)
if not mesecon then return false end
minetest.get_node_timer(pos):start(2)
end,
})
end
minetest.register_node("portalgun:button", {
description = "Button",
tiles = {"portalgun_bu.png"},
groups = {cracky = 3,mesecon=1},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
selection_box = {type = "fixed",fixed = { -0.2, -0.5, -0.2, 0.2, 0.85, 0.2 }},
sounds = stone_sounds,
mesecons = {receptor = {state = "off"}},
on_rightclick = function(pos, node, clicker)
mesecon.receptor_on(pos)
minetest.get_node_timer(pos):start(2)
minetest.sound_play("button_press", {pos=pos,max_hear_distance = 10, gain = 1})
end,
on_timer = function (pos, elapsed)
mesecon.receptor_off(pos)
end,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.25, -0.5, -0.25, 0.25, 0.7, 0.25},
{-0.125, 0.5, -0.125, 0.125, 0.77, 0.125},
}}
})
minetest.register_node("portalgun:dmgblock_1", {
description = "Damage block (hurts when not active)",
tiles = {"portalgun_powerwall.png"},
groups = {cracky = 1,mesecon=2},
drawtype="glasslike",
paramtype="light",
alpha = 50,
sunlight_propagates = true,
sounds = stone_sounds,
walkable=false,
damage_per_second = 5,
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "portalgun:dmgblock_2",
rules = pgad_rules
}},
})
minetest.register_node("portalgun:dmgblock_2", {
description = "Damage block",
tiles = {"portalgun_gravity.png"},
groups = {mesecon=2,not_in_creative_inventory=1},
drawtype="airlike",
pointable=false,
sunlight_propagates = true,
drop="portalgun:dmgblock_1",
paramtype="light",
walkable=false,
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "portalgun:dmgblock_1",
rules = pgad_rules
}},
})
minetest.register_on_respawnplayer(function(player)
local name=player:get_player_name()
minetest.after(1, function(name)
if portalgun.checkpoints[name]~=nil then
player:move_to(portalgun.checkpoints[name])
end
end, name)
end)
minetest.register_on_leaveplayer(function(player)
local name=player:get_player_name()
if portalgun.checkpoints[name]~=nil then
portalgun.checkpoints[name]=nil
end
end)
minetest.register_node("portalgun:autocheckpoint", {
description = "Checkpoint (teleports to here on death)",
tiles = {"portalgun_checkpoint.png"},
groups = {cracky = 3,not_in_creative_inventory=0},
paramtype = "light",
sunlight_propagates = true,
light_source = 5,
sounds = stone_sounds,
drawtype="nodebox",
node_box = {
type="fixed",
fixed={-0.5,-0.5,-0.5,0.5,-0.4,0.5}},
on_construct = function(pos)
minetest.get_meta(pos):set_string("infotext","Checkpoint")
minetest.get_node_timer(pos):start(2)
end,
on_timer = function (pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do
if ob:is_player() then
local name=ob:get_player_name()
if portalgun.checkpoints[name]~=nil then
local cp=portalgun.checkpoints[name]
if cp.x==pos.x and cp.y==pos.y and cp.z==pos.z then
return true
end
end
portal_delete(name,0)
portalgun_portal[name]=nil
portalgun.checkpoints[name]=pos
minetest.sound_play("portalgun_checkpoint", {pos=pos,max_hear_distance = 5, gain = 1})
minetest.chat_send_player(name, "<Portalgun> You will spawn here next time you die")
end
end
return true
end,
})
minetest.register_node("portalgun:powerdoor1_1", {
description = "Power door",
inventory_image = "portalgun_powerwall.png",
wield_image = "portalgun_powerwall.png",
groups = {mesecon=1,unbreakable = 1,not_in_creative_inventory=0},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype="nodebox",
alpha = 160,
node_box = {
type="fixed",
fixed={-0.5,-0.5,0.4,0.5,0.5,0.5}},
tiles = {
{
name = "portalgun_powerwall1.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.2,
},
},
},
after_place_node = function(pos, placer, itemstack)
local name=placer:get_player_name()
minetest.get_meta(pos):set_string("owner",name)
local p2=minetest.get_node(pos)
pos.y=pos.y+1
local n=minetest.get_node(pos)
if n.name=="air" then
minetest.set_node(pos,{name="portalgun:powerdoor1_2",param2=p2.param2})
minetest.get_meta(pos):set_string("owner",name)
end
end,
on_punch = function(pos, node, player, pointed_thing)
local meta = minetest.get_meta(pos);
if meta:get_string("owner")==player:get_player_name() then
minetest.node_dig(pos,minetest.get_node(pos),player)
pos.y=pos.y+1
local un=minetest.get_node(pos).name
if un=="portalgun:powerdoor1_2" then
minetest.set_node(pos,{name="air"})
end
pos.y=pos.y-1
return true
end
end,
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "portalgun:powerdoor2_1",
rules = pgad_rules
}},
})
minetest.register_node("portalgun:powerdoor1_2", {
description = "Power door",
inventory_image = "portalgun_powerwall.png",
groups = {mesecon=1,unbreakable = 1,not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype="nodebox",
alpha = 160,
node_box = {
type="fixed",
fixed={-0.5,-0.5,0.4,0.5,0.5,0.5}},
tiles = {
{
name = "portalgun_powerwall1.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.2,
},
},
},
on_punch = function(pos, node, player, pointed_thing)
local meta = minetest.get_meta(pos);
if meta:get_string("owner")==player:get_player_name() then
minetest.set_node(pos,{name="air"})
pos.y=pos.y-1
local un=minetest.get_node(pos).name
if un=="portalgun:powerdoor1_1" then
minetest.node_dig(pos,minetest.get_node(pos),player)
end
pos.y=pos.y+1
return true
end
end,
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "portalgun:powerdoor2_2",
rules = pgad_rules
}},
})
minetest.register_node("portalgun:powerdoor2_1", {
description = "Power door",
inventory_image = "portalgun_powerwall.png",
groups = {unbreakable=1,mesecon=1,not_in_creative_inventory=1},
paramtype = "light",
sunlight_propagates = true,
drawtype="airlike",
walkable = false,
pointable = false,
diggable = false,
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "portalgun:powerdoor1_1",
rules = pgad_rules
}},
})
minetest.register_node("portalgun:powerdoor2_2", {
description = "Power door",
inventory_image = "portalgun_powerwall.png",
groups = {unbreakable=1,mesecon=1,not_in_creative_inventory=1},
paramtype = "light",
sunlight_propagates = true,
drawtype="airlike",
walkable = false,
pointable = false,
diggable = false,
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "portalgun:powerdoor1_2",
rules = pgad_rules
}},
})
minetest.register_node("portalgun:delayer", {
description = "Delayer (Punsh to change time)",
tiles = {"portalgun_delayer.png","portalgun_testblock.png"},
groups = {dig_immediate = 2,mesecon=1},
sounds = stone_sounds,
paramtype = "light",
sunlight_propagates = true,
drawtype="nodebox",
node_box = {
type="fixed",
fixed={-0.5,-0.5,-0.5,0.5,-0.4,0.5}},
on_punch = function(pos, node, player, pointed_thing)
if minetest.is_protected(pos, player:get_player_name())==false then
local meta = minetest.get_meta(pos)
local time=meta:get_int("time")
if time>=10 then time=0 end
meta:set_int("time",time+1)
meta:set_string("infotext","Delayer (" .. (time+1) ..")")
end
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("time",1)
meta:set_string("infotext","Delayer (1)")
meta:set_int("case",0)
end,
on_timer = function (pos, elapsed)
local meta = minetest.get_meta(pos)
if meta:get_int("case")==2 then
meta:set_int("case",0)
mesecon.receptor_off(pos)
end
if meta:get_int("case")==1 then
meta:set_int("case",2)
mesecon.receptor_on(pos)
minetest.get_node_timer(pos):start(meta:get_int("time"))
end
return false
end,
mesecons = {effector = {
action_on = function (pos, node)
local meta = minetest.get_meta(pos)
if meta:get_int("case")==0 then
meta:set_int("case",1)
minetest.get_node_timer(pos):start(meta:get_int("time"))
end
end,
}}
})
minetest.register_node("portalgun:testblocks", {
description = "Trapblock",
tiles = {"portalgun_testblock.png"},
groups = {cracky = 1,mesecon=2},
sounds = stone_sounds,
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "portalgun:testblocks2",
rules = pgad_rules
}},
})
minetest.register_node("portalgun:testblocks2", {
description = "Damage block",
tiles = {"portalgun_gravity.png"},
groups = {mesecon=2,not_in_creative_inventory=1},
drawtype="airlike",
pointable=false,
sunlight_propagates = true,
drop="portalgun:testblocks",
paramtype="light",
walkable=false,
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "portalgun:testblocks",
rules = pgad_rules
}},
})
minetest.register_node("portalgun:door_1", {
description = "Mesecon Door",
drop="portalgun:door_1",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.125, 0.5, 0.5, 0.125},
}
},
tiles = {"portalgun_testblock.png"},
groups = {mesecon=1,cracky = 1, level = 2, not_in_creative_inventory=0},
sounds = stone_sounds,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local p={x=pos.x,y=pos.y+1,z=pos.z}
if minetest.registered_nodes[minetest.get_node(p).name].walkable then
return false
else
minetest.set_node(p, {name = "portalgun:door_2",param2=minetest.get_node(pos).param2})
end
end,
mesecons = {effector = {
action_on = function (pos, node)
local p={x=pos.x,y=pos.y+1,z=pos.z}
minetest.swap_node(p, {name="portalgun:door_open_2", param2=minetest.get_node(pos).param2})
minetest.swap_node(pos, {name="portalgun:door_open_1", param2=minetest.get_node(pos).param2})
minetest.sound_play("portalgun_door", {pos=pos, gain = 1, max_hear_distance = 5})
end,
}},
after_dig_node = function (pos, name, digger)
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name = "air"})
end,
})
minetest.register_node("portalgun:door_2", {
description = "Door 2-1",
drawtype = "nodebox",
drop="portalgun:door_1",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.125, 0.5, 0.5, 0.125},
}
},
tiles = {"portalgun_testblock.png"},
groups = {mesecon=1,cracky = 1, level = 2, not_in_creative_inventory=1},
sounds = wood_sounds,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
mesecons = {effector = {
action_on = function (pos, node)
local p={x=pos.x,y=pos.y-1,z=pos.z}
minetest.swap_node(p, {name="portalgun:door_open_1", param2=minetest.get_node(pos).param2})
minetest.swap_node(pos, {name="portalgun:door_open_2", param2=minetest.get_node(pos).param2})
minetest.sound_play("portalgun_door", {pos=pos, gain = 1, max_hear_distance = 5})
end,
}},
after_dig_node = function (pos, name, digger)
minetest.set_node({x=pos.x,y=pos.y-1,z=pos.z}, {name = "air"})
end,
})
minetest.register_node("portalgun:door_open_1", {
description = "Door (open) 2-o-1",
drop="portalgun:door_1",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{0.41, -0.5, -0.124, 1.41, 0.5, 0.125},
}
},
tiles = {"portalgun_testblock.png"},
groups = {mesecon=1,cracky = 1, level = 2, not_in_creative_inventory=1},
sounds = wood_sounds,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
after_dig_node = function (pos, name, digger)
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name = "air"})
end,
mesecons = {effector = {
action_off = function (pos, node)
local p={x=pos.x,y=pos.y+1,z=pos.z}
minetest.sound_play("portalgun_door", {pos=pos, gain = 1, max_hear_distance = 5})
minetest.swap_node(p, {name="portalgun:door_2", param2=minetest.get_node(pos).param2})
minetest.swap_node(pos, {name="portalgun:door_1", param2=minetest.get_node(pos).param2})
end,
}}
})
minetest.register_node("portalgun:door_open_2", {
description = "Door (open) 2-o-1",
drawtype = "nodebox",
drop="portalgun:door_1",
node_box = {
type = "fixed",
fixed = {
{0.41, -0.5, -0.124, 1.41, 0.5, 0.125},
}
},
tiles = {"portalgun_testblock.png"},
groups = {mesecon=1,cracky = 1, level = 2, not_in_creative_inventory=1},
sounds = wood_sounds,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
after_dig_node = function (pos, name, digger)
minetest.set_node({x=pos.x,y=pos.y-1,z=pos.z}, {name = "air"})
end,
mesecons = {effector = {
action_off = function (pos, node)
local p={x=pos.x,y=pos.y-1,z=pos.z}
minetest.sound_play("portalgun_door", {pos=pos, gain = 1, max_hear_distance = 5})
minetest.swap_node(p, {name="portalgun:door_1", param2=minetest.get_node(pos).param2})
minetest.swap_node(pos, {name="portalgun:door_2", param2=minetest.get_node(pos).param2})
end,
}}
})

@ -1,147 +0,0 @@
stone_sounds = {}
stone_sounds.footstep = {name="stone_walk", gain=1.0}
stone_sounds.dug = {name="stone_break", gain=1.0}
stone_sounds.place = {name="block_place", gain=1.0}
glass_sounds = {}
glass_sounds.footstep = {name="glass_walk", gain=1.0}
glass_sounds.dug = {name="glass_break", gain=1.0}
glass_sounds.place = {name="block_place", gain=1.0}
wood_sounds = {}
wood_sounds.footstep = {name="wood_walk", gain=1.0}
wood_sounds.dug = {name="wood_break", gain=1.0}
wood_sounds.place = {name="block_place", gain=1.0}
minetest.register_node("portalgun:powerballspawner", {
description = "Power ball spawner" ,
tiles = {"steel.png","steel.png","steel.png","steel.png","steel.png","portalgun_powerballspawner.png"},
groups = {cracky=2},
sounds = glass_sounds,
is_ground_content = false,
paramtype2 = "facedir",
on_construct = function(pos)
minetest.get_node_timer(pos):start(10)
end,
on_timer = function (pos, elapsed)
local dir=minetest.get_node(pos).param2
local v={x=0, y=0, z=0}
if dir==0 then v.z=-1
elseif dir==1 then v.x=-1
elseif dir==2 then v.z=1
elseif dir==3 then v.x=1
elseif dir==5 then v.y=-1
elseif dir==4 then v.y=1
else v.y = -1
end
local pv={x=pos.x+v.x, y=pos.y+v.y, z=pos.z+v.z}
portalgun.new=1
local m=minetest.add_entity(pv, "portalgun:powerball")
m:set_velocity({x=v.x*4, y=v.y*4, z=v.z*4})
return true
end,
})
minetest.register_node("portalgun:powerballspawner2", {
description = "Power ball spawner (spawn on activate)" ,
tiles = {"steel.png","steel.png","steel.png","steel.png","steel.png","portalgun_powerballspawner.png^[colorize:#aaaa0055"},
groups = {cracky=2,mesecon=1},
sounds = glass_sounds,
is_ground_content = false,
paramtype2 = "facedir",
on_place = minetest.rotate_node,
mesecons = {effector = {
action_on = function (pos, node)
local dir=minetest.get_node(pos).param2
local v={x=0, y=0, z=0}
if dir==0 then v.z=-1
elseif dir==1 then v.x=-1
elseif dir==2 then v.z=1
elseif dir==3 then v.x=1
elseif dir==8 then v.y=-1
elseif dir==4 then v.y=1
end
local pv={x=pos.x+v.x, y=pos.y+v.y, z=pos.z+v.z}
portalgun.new=1
local m=minetest.add_entity(pv, "portalgun:powerball")
m:set_velocity({x=v.x*4, y=v.y*4, z=v.z*4})
end
}}
})
minetest.register_entity("portalgun:powerball",{
hp_max = 1000,
physical = true,
weight = 0,
collisionbox = {-0.4,-0.4,-0.4, 0.4,0.4,0.4},
visual = "sprite",
visual_size = {x=1.1, y=1.1},
textures = {"portalgun_powrball.png"},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = 0,
portalgun=2,
powerball=1,
on_activate= function(self, staticdata)
if portalgun.new==0 then
self.object:remove()
return self
end
portalgun.new=0
local pos=self.object:get_pos()
self.sound=minetest.sound_play("portalgun_powerball", {pos=pos,max_hear_distance = 10, gain = 0.5})
minetest.sound_play("portalgun_powerballbonce", {pos=pos,max_hear_distance = 10, gain = 1})
end,
on_step= function(self, dtime)
self.timer=self.timer+dtime
if self.timer<0.2 then return self end
self.timer=0
local pos=self.object:get_pos()
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 2)) do
if ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().portalgun~=1 and ob:get_luaentity().wsc==nil and ob:get_luaentity().powerball~=1) then
ob:set_hp(0)
end
end
self.timer2=self.timer2+1
self.timer3=self.timer3+1
if self.timer3>=9 then
self.timer3=0
minetest.sound_stop(self.sound)
self.sound=minetest.sound_play("portalgun_powerball", {pos=pos,max_hear_distance = 10, gain = 0.5})
end
if self.timer2>40 then
minetest.sound_stop(self.sound)
self.object:set_hp(0)
return self
end
local v=self.object:get_velocity()
local nextn={x=pos.x+(v.x)/3, y=pos.y+(v.y)/3, z=pos.z+(v.z)/3}
local nname=minetest.get_node(nextn).name
if minetest.registered_nodes[nname].walkable then
if nname=="portalgun:powerballtarget" and mesecon then
mesecon.receptor_on(nextn)
minetest.get_node_timer(nextn):start(5)
self.object:remove()
end
self.object:set_velocity({x=v.x*-1, y=v.y*-1, z=v.z*-1})
minetest.sound_play("portalgun_powerballbonce", {pos=pos,max_hear_distance = 10, gain = 1})
end
end,
timer=0,
timer2=0,
timer3=0,
sound={}
})
minetest.register_node("portalgun:powerballtarget", {
description = "Power ball target" ,
tiles = {"portalgun_powerballstarget.png"},
groups = {mesecon = 2,cracky=2},
mesecons = {receptor = {state = "off"}},
sounds = stone_sounds,
is_ground_content = false,
on_timer = function (pos, elapsed)
mesecon.receptor_off(pos)
return false
end,
})

101
scripts/buildingblocks.lua Normal file

@ -0,0 +1,101 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
local pgad_rules = {
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y = -1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1}
}
minetest.register_node(
"portalgun:testblock",
{
description = "Test block",
tiles = {"portalgun_testblock.png"},
groups = {cracky = 1},
sounds = stone_sounds
}
)
minetest.register_node(
"portalgun:apb",
{
description = "Anti portal block",
tiles = {"portalgun_testblock.png^[colorize:#ffffffaa"},
groups = {cracky = 3, antiportal = 1},
sounds = stone_sounds
}
)
minetest.register_node(
"portalgun:apg",
{
description = "Anti portal glass",
drawtype = "glasslike",
paramtype = "light",
sunlight_propagates = true,
tiles = {"glass.png^[colorize:#ffffffaa"},
groups = {cracky = 1, antiportal = 1},
sounds = glass_sounds
}
)
minetest.register_node(
"portalgun:hard_glass",
{
description = "Hard glass",
drawtype = "glasslike",
paramtype = "light",
sunlight_propagates = true,
tiles = {"glass.png^[colorize:#ddddddaa"},
groups = {cracky = 1},
sounds = glass_sounds
}
)
minetest.register_node(
"portalgun:testblocks",
{
description = "Trapblock",
tiles = {"portalgun_testblock.png"},
groups = {cracky = 1, mesecon = 2},
sounds = stone_sounds,
mesecons = {
conductor = {
state = mesecon.state.off,
onstate = "portalgun:testblocks2",
rules = pgad_rules
}
}
}
)
minetest.register_node(
"portalgun:testblocks2",
{
description = "Air block",
tiles = {"portalgun_gravity.png"},
groups = {mesecon = 2, not_in_creative_inventory = 1},
drawtype = "airlike",
pointable = false,
sunlight_propagates = true,
drop = "portalgun:testblocks",
paramtype = "light",
walkable = false,
mesecons = {
conductor = {
state = mesecon.state.on,
offstate = "portalgun:testblocks",
rules = pgad_rules
}
}
}
)

51
scripts/button.lua Normal file

@ -0,0 +1,51 @@
local pgad_rules = {
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y = -1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1}
}
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:button",
{
description = "Button",
tiles = {"portalgun_bu.png"},
groups = {cracky = 3, mesecon = 1},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
selection_box = {type = "fixed", fixed = {-0.2, -0.5, -0.2, 0.2, 0.85, 0.2}},
sounds = stone_sounds,
mesecons = {receptor = {state = "off"}},
on_rightclick = function(pos, node, clicker)
mesecon.receptor_on(pos)
minetest.get_node_timer(pos):start(2)
minetest.sound_play("button_press", {pos = pos, max_hear_distance = 10, gain = 1})
end,
on_timer = function(pos, elapsed)
mesecon.receptor_off(pos)
end,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.25, -0.5, -0.25, 0.25, 0.7, 0.25},
{-0.125, 0.5, -0.125, 0.125, 0.77, 0.125}
}
}
}
)

43
scripts/cake.lua Normal file

@ -0,0 +1,43 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:cake",
{
description = "Cake",
groups = {dig_immediate = 3, not_in_creative_inventory = 0},
paramtype = "light",
sunlight_propagates = true,
selection_box = {type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0, 0.3}},
sounds = stone_sounds,
tiles = {
"dirt.png^portalgun_cake1.png",
"dirt.png^portalgun_cake2.png"
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.3125, -0.5, 0.375, 0.3125, -0.125, 0.4375},
{-0.3125, -0.5, -0.4375, 0.3125, -0.125, -0.375},
{-0.4375, -0.5, -0.3125, -0.375, -0.125, 0.3125},
{0.375, -0.5, -0.3125, 0.4375, -0.125, 0.3125},
{-0.375, -0.5, -0.375, 0.375, -0.125, 0.375},
{-0.25, -0.5, 0.4375, 0.25, -0.125, 0.5},
{-0.25, -0.5, -0.5, 0.25, -0.125, -0.4375},
{0.4375, -0.5, -0.25, 0.5, -0.125, 0.25},
{-0.5, -0.5, -0.25, -0.4375, -0.125, 0.25},
{0, -0.125, -0.0625, 0.0625, 0.1875, 0}
}
}
}
)

73
scripts/camera.lua Normal file

@ -0,0 +1,73 @@
stone_sounds = {}
stone_sounds.footstep = {name="stone_walk", gain=1.0}
stone_sounds.dug = {name="stone_break", gain=1.0}
stone_sounds.place = {name="block_place", gain=1.0}
glass_sounds = {}
glass_sounds.footstep = {name="glass_walk", gain=1.0}
glass_sounds.dug = {name="glass_break", gain=1.0}
glass_sounds.place = {name="block_place", gain=1.0}
wood_sounds = {}
wood_sounds.footstep = {name="wood_walk", gain=1.0}
wood_sounds.dug = {name="wood_break", gain=1.0}
wood_sounds.place = {name="block_place", gain=1.0}
minetest.register_node("portalgun:secam_off", {
description = "Security cam (off)" ,
tiles = {"portalgun_scam.png"},
drawtype = "nodebox",
walkable=false,
groups = {dig_immediate = 3},
sounds = glass_sounds,
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 = glass_sounds,
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,
})

64
scripts/checkpoint.lua Normal file

@ -0,0 +1,64 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
checkpoints={}
minetest.register_node("portalgun:autocheckpoint", {
description = "Checkpoint (teleports to here on death)",
tiles = {"portalgun_checkpoint.png"},
groups = {cracky = 3,not_in_creative_inventory=0},
paramtype = "light",
sunlight_propagates = true,
light_source = 5,
sounds = stone_sounds,
drawtype="nodebox",
node_box = {
type="fixed",
fixed={-0.5,-0.5,-0.5,0.5,-0.4,0.5}},
on_construct = function(pos)
minetest.get_meta(pos):set_string("infotext","Checkpoint")
minetest.get_node_timer(pos):start(2)
end,
on_timer = function (pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do
if ob:is_player() then
local name=ob:get_player_name()
if checkpoints[name]~=nil then
local cp=checkpoints[name]
if cp.x==pos.x and cp.y==pos.y and cp.z==pos.z then
return true
end
end
portal_delete(name,0)
portalgun_portal[name]=nil
checkpoints[name]=pos
minetest.sound_play("portalgun_checkpoint", {pos=pos,max_hear_distance = 5, gain = 1})
minetest.chat_send_player(name, "<Portalgun> You will spawn here next time you die")
end
end
return true
end,
})
minetest.register_on_respawnplayer(function(player)
local name=player:get_player_name()
minetest.after(1, function(name)
if checkpoints[name]~=nil then
player:move_to(checkpoints[name])
end
end, name)
end)
minetest.register_on_leaveplayer(function(player)
local name=player:get_player_name()
if checkpoints[name]~=nil then
checkpoints[name]=nil
end
end)

101
scripts/cubespawners.lua Normal file

@ -0,0 +1,101 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
new = 0
local ptgwsc = {
{"weightedstoragecube.png", "portalgun_presplat.png", "(blue)"},
{"weightedstoragecube2.png", "portalgun_presplat2.png", "(orange)"},
{"weightedstoragecube3.png", "portalgun_presplat3.png", "(yellow)"},
{"weightedstoragecube4.png", "portalgun_presplat4.png", "(green)"},
{"weightedcompanioncube.png", "portalgun_presplat.png", "(blue companion)"},
{"weightedcompanioncube2.png", "portalgun_presplat2.png", "(orange companion)"},
{"weightedcompanioncube3.png", "portalgun_presplat3.png", "(yellow companion)"},
{"weightedcompanioncube4.png", "portalgun_presplat4.png", "(green companion)"}
}
for ii = 1, #ptgwsc, 1 do
minetest.register_node(
"portalgun:wscspawner2_" .. ii,
{
description = "Weighted storage cube spawner2 " .. ptgwsc[ii][3],
tiles = {"steel.png", "steel.png", "steel.png", "steel.png", "steel.png", ptgwsc[ii][1]},
groups = {cracky = 2, mesecon_receptor_off = 1, mesecon_effector_off = 1},
sounds = glass_sounds,
is_ground_content = false,
paramtype2 = "facedir",
mesecons = {
receptor = {state = "off"},
effector = {
action_on = function(pos, node)
local dir = minetest.get_node(pos).param2
local v = {x = 0, y = 0, z = 0}
if dir == 0 then
v.z = -1
elseif dir == 1 then
v.x = -1.2
elseif dir == 2 then
v.z = 1.2
elseif dir == 3 then
v.x = 1.2
elseif dir == 8 then
v.y = -1.2
elseif dir == 4 then
v.y = 1.2
end
local pv = {x = pos.x + v.x, y = pos.y + v.y, z = pos.z + v.z}
new = 1
local m = minetest.add_entity(pv, "portalgun:wsc" .. ii)
m:set_acceleration({x = 0, y = -10, z = 0})
end
}
}
}
)
minetest.register_node(
"portalgun:wscspawner" .. ii,
{
description = "Weighted storage cube spawner " .. ptgwsc[ii][3],
tiles = {ptgwsc[ii][1]},
groups = {cracky = 1, not_in_creative_inventory = 0},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
light_source = 14,
sounds = stone_sounds,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9}
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(5)
end,
on_timer = function(pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 40)) do
if ob:get_luaentity() and ob:get_luaentity().wsc == ii then
return true
end
end
new = 1
local m = minetest.add_entity(pos, "portalgun:wsc" .. ii)
m:set_acceleration({x = 0, y = -10, z = 0})
return true
end
}
)
end -- of for #

63
scripts/damageblock.lua Normal file

@ -0,0 +1,63 @@
local pgad_rules = {
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y = -1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1}
}
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:dmgblock_1",
{
description = "Damage block (hurts when not active)",
tiles = {"portalgun_powerwall.png"},
groups = {cracky = 1, mesecon = 2},
drawtype = "glasslike",
paramtype = "light",
alpha = 50,
sunlight_propagates = true,
sounds = stone_sounds,
walkable = false,
damage_per_second = 5,
mesecons = {
conductor = {
state = mesecon.state.off,
onstate = "portalgun:dmgblock_2",
rules = pgad_rules
}
}
}
)
minetest.register_node(
"portalgun:dmgblock_2",
{
description = "Damage block",
tiles = {"portalgun_gravity.png"},
groups = {mesecon = 2, not_in_creative_inventory = 1},
drawtype = "airlike",
pointable = false,
sunlight_propagates = true,
drop = "portalgun:dmgblock_1",
paramtype = "light",
walkable = false,
mesecons = {
conductor = {
state = mesecon.state.on,
offstate = "portalgun:dmgblock_1",
rules = pgad_rules
}
}
}
)

78
scripts/delayer.lua Normal file

@ -0,0 +1,78 @@
local pgad_rules = {
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y = -1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1}
}
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:delayer",
{
description = "Delayer (Punsh to change time)",
tiles = {"portalgun_delayer.png", "portalgun_testblock.png"},
groups = {dig_immediate = 2, mesecon = 1},
sounds = stone_sounds,
paramtype = "light",
sunlight_propagates = true,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}
},
on_punch = function(pos, node, player, pointed_thing)
if minetest.is_protected(pos, player:get_player_name()) == false then
local meta = minetest.get_meta(pos)
local time = meta:get_int("time")
if time >= 10 then
time = 0
end
meta:set_int("time", time + 1)
meta:set_string("infotext", "Delayer (" .. (time + 1) .. ")")
end
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("time", 1)
meta:set_string("infotext", "Delayer (1)")
meta:set_int("case", 0)
end,
on_timer = function(pos, elapsed)
local meta = minetest.get_meta(pos)
if meta:get_int("case") == 2 then
meta:set_int("case", 0)
mesecon.receptor_off(pos)
end
if meta:get_int("case") == 1 then
meta:set_int("case", 2)
mesecon.receptor_on(pos)
minetest.get_node_timer(pos):start(meta:get_int("time"))
end
return false
end,
mesecons = {
effector = {
action_on = function(pos, node)
local meta = minetest.get_meta(pos)
if meta:get_int("case") == 0 then
meta:set_int("case", 1)
minetest.get_node_timer(pos):start(meta:get_int("time"))
end
end
}
}
}
)

322
scripts/doors.lua Normal file

@ -0,0 +1,322 @@
local pgad_rules = {
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y = -1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1}
}
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:powerdoor1_1",
{
description = "Power door",
inventory_image = "portalgun_powerwall.png",
wield_image = "portalgun_powerwall.png",
groups = {mesecon = 1, unbreakable = 1, not_in_creative_inventory = 0},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype = "nodebox",
alpha = 160,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, 0.4, 0.5, 0.5, 0.5}
},
tiles = {
{
name = "portalgun_powerwall1.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.2
}
}
},
after_place_node = function(pos, placer, itemstack)
local name = placer:get_player_name()
minetest.get_meta(pos):set_string("owner", name)
local p2 = minetest.get_node(pos)
pos.y = pos.y + 1
local n = minetest.get_node(pos)
if n.name == "air" then
minetest.set_node(pos, {name = "portalgun:powerdoor1_2", param2 = p2.param2})
minetest.get_meta(pos):set_string("owner", name)
end
end,
on_punch = function(pos, node, player, pointed_thing)
local meta = minetest.get_meta(pos)
if meta:get_string("owner") == player:get_player_name() then
minetest.node_dig(pos, minetest.get_node(pos), player)
pos.y = pos.y + 1
local un = minetest.get_node(pos).name
if un == "portalgun:powerdoor1_2" then
minetest.set_node(pos, {name = "air"})
end
pos.y = pos.y - 1
return true
end
end,
mesecons = {
conductor = {
state = mesecon.state.off,
onstate = "portalgun:powerdoor2_1",
rules = pgad_rules
}
}
}
)
minetest.register_node(
"portalgun:powerdoor1_2",
{
description = "Power door",
inventory_image = "portalgun_powerwall.png",
groups = {mesecon = 1, unbreakable = 1, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype = "nodebox",
alpha = 160,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, 0.4, 0.5, 0.5, 0.5}
},
tiles = {
{
name = "portalgun_powerwall1.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.2
}
}
},
on_punch = function(pos, node, player, pointed_thing)
local meta = minetest.get_meta(pos)
if meta:get_string("owner") == player:get_player_name() then
minetest.set_node(pos, {name = "air"})
pos.y = pos.y - 1
local un = minetest.get_node(pos).name
if un == "portalgun:powerdoor1_1" then
minetest.node_dig(pos, minetest.get_node(pos), player)
end
pos.y = pos.y + 1
return true
end
end,
mesecons = {
conductor = {
state = mesecon.state.off,
onstate = "portalgun:powerdoor2_2",
rules = pgad_rules
}
}
}
)
minetest.register_node(
"portalgun:powerdoor2_1",
{
description = "Power door",
inventory_image = "portalgun_powerwall.png",
groups = {unbreakable = 1, mesecon = 1, not_in_creative_inventory = 1},
paramtype = "light",
sunlight_propagates = true,
drawtype = "airlike",
walkable = false,
pointable = false,
diggable = false,
mesecons = {
conductor = {
state = mesecon.state.on,
offstate = "portalgun:powerdoor1_1",
rules = pgad_rules
}
}
}
)
minetest.register_node(
"portalgun:powerdoor2_2",
{
description = "Power door",
inventory_image = "portalgun_powerwall.png",
groups = {unbreakable = 1, mesecon = 1, not_in_creative_inventory = 1},
paramtype = "light",
sunlight_propagates = true,
drawtype = "airlike",
walkable = false,
pointable = false,
diggable = false,
mesecons = {
conductor = {
state = mesecon.state.on,
offstate = "portalgun:powerdoor1_2",
rules = pgad_rules
}
}
}
)
minetest.register_node(
"portalgun:door_1",
{
description = "Mesecon Door",
drop = "portalgun:door_1",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.125, 0.5, 0.5, 0.125}
}
},
tiles = {"portalgun_testblock.png"},
groups = {mesecon = 1, cracky = 1, level = 2, not_in_creative_inventory = 0},
sounds = stone_sounds,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local p = {x = pos.x, y = pos.y + 1, z = pos.z}
if minetest.registered_nodes[minetest.get_node(p).name].walkable then
return false
else
minetest.set_node(p, {name = "portalgun:door_2", param2 = minetest.get_node(pos).param2})
end
end,
mesecons = {
effector = {
action_on = function(pos, node)
local p = {x = pos.x, y = pos.y + 1, z = pos.z}
minetest.swap_node(p, {name = "portalgun:door_open_2", param2 = minetest.get_node(pos).param2})
minetest.swap_node(pos, {name = "portalgun:door_open_1", param2 = minetest.get_node(pos).param2})
minetest.sound_play("portalgun_door", {pos = pos, gain = 1, max_hear_distance = 5})
end
}
},
after_dig_node = function(pos, name, digger)
minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "air"})
end
}
)
minetest.register_node(
"portalgun:door_2",
{
description = "Door 2-1",
drawtype = "nodebox",
drop = "portalgun:door_1",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.125, 0.5, 0.5, 0.125}
}
},
tiles = {"portalgun_testblock.png"},
groups = {mesecon = 1, cracky = 1, level = 2, not_in_creative_inventory = 1},
sounds = wood_sounds,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
mesecons = {
effector = {
action_on = function(pos, node)
local p = {x = pos.x, y = pos.y - 1, z = pos.z}
minetest.swap_node(p, {name = "portalgun:door_open_1", param2 = minetest.get_node(pos).param2})
minetest.swap_node(pos, {name = "portalgun:door_open_2", param2 = minetest.get_node(pos).param2})
minetest.sound_play("portalgun_door", {pos = pos, gain = 1, max_hear_distance = 5})
end
}
},
after_dig_node = function(pos, name, digger)
minetest.set_node({x = pos.x, y = pos.y - 1, z = pos.z}, {name = "air"})
end
}
)
minetest.register_node(
"portalgun:door_open_1",
{
description = "Door (open) 2-o-1",
drop = "portalgun:door_1",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{0.41, -0.5, -0.124, 1.41, 0.5, 0.125}
}
},
tiles = {"portalgun_testblock.png"},
groups = {mesecon = 1, cracky = 1, level = 2, not_in_creative_inventory = 1},
sounds = wood_sounds,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
after_dig_node = function(pos, name, digger)
minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "air"})
end,
mesecons = {
effector = {
action_off = function(pos, node)
local p = {x = pos.x, y = pos.y + 1, z = pos.z}
minetest.sound_play("portalgun_door", {pos = pos, gain = 1, max_hear_distance = 5})
minetest.swap_node(p, {name = "portalgun:door_2", param2 = minetest.get_node(pos).param2})
minetest.swap_node(pos, {name = "portalgun:door_1", param2 = minetest.get_node(pos).param2})
end
}
}
}
)
minetest.register_node(
"portalgun:door_open_2",
{
description = "Door (open) 2-o-1",
drawtype = "nodebox",
drop = "portalgun:door_1",
node_box = {
type = "fixed",
fixed = {
{0.41, -0.5, -0.124, 1.41, 0.5, 0.125}
}
},
tiles = {"portalgun_testblock.png"},
groups = {mesecon = 1, cracky = 1, level = 2, not_in_creative_inventory = 1},
sounds = wood_sounds,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
after_dig_node = function(pos, name, digger)
minetest.set_node({x = pos.x, y = pos.y - 1, z = pos.z}, {name = "air"})
end,
mesecons = {
effector = {
action_off = function(pos, node)
local p = {x = pos.x, y = pos.y - 1, z = pos.z}
minetest.sound_play("portalgun_door", {pos = pos, gain = 1, max_hear_distance = 5})
minetest.swap_node(p, {name = "portalgun:door_1", param2 = minetest.get_node(pos).param2})
minetest.swap_node(pos, {name = "portalgun:door_2", param2 = minetest.get_node(pos).param2})
end
}
}
}
)

64
scripts/editingtools.lua Normal file

@ -0,0 +1,64 @@
minetest.register_tool(
"portalgun:pick",
{
--a pickaxe that can mine all blocks
description = "Portalgun Pickaxe",
inventory_image = "portalgun_pick.png",
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level = 3,
groupcaps = {
unbreakable = {times = {[1] = 1, [2] = 1, [3] = 1}, uses = 0, maxlevel = 3},
fleshy = {times = {[1] = 1, [2] = 1, [3] = 1}, uses = 0, maxlevel = 3},
choppy = {times = {[1] = 1, [2] = 1, [3] = 1}, uses = 0, maxlevel = 3},
bendy = {times = {[1] = 1, [2] = 1, [3] = 1}, uses = 0, maxlevel = 3},
cracky = {times = {[1] = 1, [2] = 1, [3] = 1}, uses = 0, maxlevel = 3},
crumbly = {times = {[1] = 1, [2] = 1, [3] = 1}, uses = 0, maxlevel = 3},
snappy = {times = {[1] = 1, [2] = 1, [3] = 1}, uses = 0, maxlevel = 3}
},
damage_groups = {fleshy = 1000}
}
}
)
minetest.register_tool(
"portalgun:ed",
{
description = "Entity Destroyer",
inventory_image = "portalgun_edestroyer.png",
range = 15,
on_use = function(itemstack, user, pointed_thing)
local pos = user:get_pos()
if pointed_thing.type == "node" then
pos = pointed_thing.above
end
if pointed_thing.type == "object" then
pos = pointed_thing.ref:get_pos()
end
local name = user:get_player_name()
if minetest.check_player_privs(name, {kick = true}) == false then
minetest.chat_send_player(name, "You need the kick privilege to use this tool!")
return itemstack
end
for ii, ob in pairs(minetest.get_objects_inside_radius(pos, 7)) do
if ob:get_luaentity() then
ob:set_hp(0)
end
end
return itemstack
end
}
)
--register command for admins to build a testblock at the players position
minetest.register_chatcommand(
"testblock",
{
params = "",
description = "builds a testblock at the players position",
privs = {server = true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
local pos = player:get_pos()
minetest.set_node(pos, {name = "portalgun:testblock"})
end
}
)

88
scripts/fizzlers.lua Normal file

@ -0,0 +1,88 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:cplps1",
{
description = "Close player portal",
tiles = {"portalgun_gray.png"},
groups = {mesecon = 2, snappy = 3, not_in_creative_inventory = 0},
sounds = stone_sounds,
is_ground_content = false,
mesecons = {
effector = {
action_on = function(pos, node)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 6)) do
if ob and ob:is_player() then
portal_delete(ob:get_player_name(), 0)
end
end
minetest.swap_node(pos, {name = "portalgun:cplps2"})
minetest.after(
(2),
function(pos)
minetest.swap_node(pos, {name = "portalgun:cplps1"})
end,
pos
)
return false
end
}
}
}
)
minetest.register_node(
"portalgun:cplps3",
{
description = "Close player portal when player is near",
tiles = {"portalgun_gray.png"},
groups = {snappy = 3, not_in_creative_inventory = 0},
sounds = stone_sounds,
is_ground_content = false,
--every 2 seconds, check if player is near and close portal if so
on_t = function(pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 4)) do
if ob and ob:is_player() then
minetest.sound_play("portalgun_close", {pos = pos, gain = 1.0, max_hear_distance = 10})
portal_delete(ob:get_player_name(), 0)
end
--destroy all entities except players
if ob and not ob:is_player() then
ob:remove()
end
end
local timer = minetest.get_node_timer(pos)
timer:start(2)
return true
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local timer = minetest.get_node_timer(pos)
timer:start(2)
end
}
)
minetest.register_node(
"portalgun:cplps2",
{
description = "Close player portal",
tiles = {"portalgun_gray.png^[colorize:#ffe85977"},
groups = {mesecon = 2, snappy = 3, not_in_creative_inventory = 1},
sounds = stone_sounds,
is_ground_content = false,
paramtype = "light",
light_source = 4
}
)

173
scripts/gravityuse.lua Normal file

@ -0,0 +1,173 @@
portalgun_power = {}
portalgun_power_tmp_power = 0
function portalgun_gravity(itemstack, user, pointed_thing)
local ob = pointed_thing.ref
local at = ob:get_attach()
if at and at:get_luaentity() and at:get_luaentity().portalgun_power then
ob:set_detach()
local target = at:get_luaentity().target
if target and target:get_luaentity() and (target:get_luaentity().itemstring or target:get_luaentity().wsc) then
target:set_velocity({x = 0, y = -1, z = 0})
target:set_acceleration({x = 0, y = -8, z = 0})
end
return itemstack
end
if not ob:get_attach() and (ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().powerball ~= 1)) then
--if 4 blocks or closer to player
if vector.distance(ob:get_pos(), user:get_pos()) < 4 then
portalgun_power.user = user
portalgun_power.target = ob
if ob:is_player() then
portalgun_power.player = 1
end
local m = minetest.add_entity(ob:get_pos(), "portalgun:power")
ob:set_attach(m, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
return itemstack
end
end
return itemstack
end
minetest.register_entity(
"portalgun:power",
{
hp_max = 100,
physical = false,
weight = 0,
collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2},
visual = "sprite",
visual_size = {x = 1, y = 1},
textures = {"portalgun_gravity.png"},
spritediv = {x = 1, y = 1},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = 0,
timer = 0,
time = 0.1,
portalgun_power = 1,
portalgun = 1,
lifelime = 100,
on_activate = function(self, staticdata)
if portalgun_power.user then
self.user = portalgun_power.user
self.target = portalgun_power.target
self.player = portalgun_power.player
portalgun_power = {}
else
self.object:remove()
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if self.target and self.target:get_attach() then
self.target:set_detach()
self.target:set_hp(0)
end
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer < self.time then
return self
end
self.timer = 0
if self.target == nil or (not self.target:get_attach()) then
self.object:set_hp(0)
if self.sound then
minetest.sound_stop(self.sound)
end
end
if self.player then
self.lifelime = self.lifelime - 1
if self.lifelime < 0 then
self.target:set_detach()
return self
end
end
local pos = self.user:get_pos()
if pos == nil then
return self
end
pos.y = pos.y + 1.6
local dir = self.user:get_look_dir()
local npos = {x = pos.x + (dir.x * 2), y = pos.y + (dir.y * 2), z = pos.z + (dir.z * 2)}
if minetest.registered_nodes[minetest.get_node(npos).name].walkable then
return self
end
self.object:move_to(npos)
return self
end
}
)
minetest.register_entity(
"portalgun:power2",
{
hp_max = 100,
physical = true,
weight = 10,
collisionbox = {-0.35, 0, -0.35, 0.35, 1, 0.35},
visual = "sprite",
visual_size = {x = 1, y = 1},
textures = {"portalgun_gravity.png"},
spritediv = {x = 1, y = 1},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = 0,
timer = 0,
time = 0.025,
portalgun_power = 1,
portalgun = 1,
lifelime = 1000,
v = 0.3,
ltime = 0,
on_activate = function(self, staticdata)
if portalgun_power.user then
self.user = portalgun_power.user
self.target = portalgun_power.target
self.ltime = portalgun_power_tmp_power
portalgun_power = {}
else
self.object:remove()
end
end,
on_step = function(self, dtime)
local pos = self.object:get_pos()
local v = self.object:get_velocity()
local v2 = {x = v.x - self.v, y = (v.y - self.v) * 0.99, z = v.z - self.v}
if v2.x < 0.5 and v2.x > -0.5 then
v2.x = 0
end
if v2.y < 0.5 and v2.y > -0.5 then
v2.y = 0
end
if v2.z < 0.5 and v2.z > -0.5 then
v2.z = 0
end
self.object:set_velocity(v2)
self.ltime = self.ltime - self.v
if self.ltime < self.v or (v2.x + v2.y + v2.z == 0) then
self.lifelime = -1
end
local nexpos = {x = pos.x + (v.x * 0.05), y = pos.y + (v.y * 0.05) + 1, z = pos.z + (v.z * 0.05)}
if minetest.registered_nodes[minetest.get_node(nexpos).name].walkable then
self.lifelime = -1
end
self.lifelime = self.lifelime - 1
if self.lifelime < 0 then
self.target:set_detach()
end
if self.target == nil or (not self.target:get_attach()) then
self.object:set_hp(0)
return self
end
return self
end
}
)

@ -0,0 +1,51 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:objdestroyer_1",
{
description = "Object destroyer (destroys on active)",
tiles = {"portalgun_testblock.png^[colorize:#FF0000aa"},
groups = {cracky = 2, mesecon = 1},
sounds = stone_sounds,
mesecons = {
effector = {
action_on = function(pos, node)
minetest.set_node(pos, {name = "portalgun:objdestroyer_2"})
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 5)) do
if ob:get_luaentity() then
ob:set_hp(0)
end
end
end
}
}
}
)
minetest.register_node(
"portalgun:objdestroyer_2",
{
description = "Obj destroyer",
tiles = {"portalgun_testblock.png^[colorize:#FF0000cc"},
groups = {cracky = 2, mesecon = 1, not_in_creative_inventory = 1},
sunlight_propagates = true,
drop = "portalgun:objdestroyer_1",
paramtype = "light",
light_source = 14,
mesecons = {
conductor = {
state = mesecon.state.on,
offstate = "portalgun:objdestroyer_1"
}
}
}
)

664
scripts/portalgun.lua Normal file

@ -0,0 +1,664 @@
portalgun_portal = {}
portalgun_portal_tmp_user_abort = 0
portalgun_portal_tmp_user = ""
local portalgun_timer = 1.2
local portalgun_time = 0
portalgun_lifelime = 1200 --deletes portals that not used after a while
portalgun_max_rage = 100
portalgun_max_use_per_secund_time = 4 --destroys the portal if excessive used
portalgun_max_use_per_secund = 25 --4 & 25 is default = teleported (teleported 25 times in 4 sec)
function portalgun_param2(pos, param2, r)
local pos2 = {x = pos.x, y = pos.y, z = pos.z}
if r then
if param2 == 0 then
pos2.x = pos2.x - 1
elseif param2 == 1 then
pos2.z = pos2.z + 1
elseif param2 == 2 then
pos2.x = pos2.x + 1
elseif param2 == 3 then
pos2.z = pos2.z - 1
end
else
if param2 == 0 then
pos2.x = pos2.x + 1
elseif param2 == 1 then
pos2.z = pos2.z - 1
elseif param2 == 2 then
pos2.x = pos2.x - 1
elseif param2 == 3 then
pos2.z = pos2.z + 1
end
end
return pos2
end
local function portalgun_getLength(a) -- get length of an array / table
local count = 0
for _ in pairs(a) do
count = count + 1
end
return count
end
function portal_delete(name, n) -- using set_hp & :punch instand of :remove ... no risk for crash if something attach it
if portalgun_portal[name] == nil then
return
end
if (n == 1 or n == 0) and portalgun_portal[name].portal1 ~= nil then
if n == 0 then
local pos = portalgun_portal[name].portal1:get_pos()
if pos ~= nil then
minetest.sound_play("portalgun_closeportals", {pos = pos, max_hear_distance = 20, gain = 1})
end
end
portalgun_portal[name].portal1_active = false
portalgun_portal[name].portal1:set_hp(0)
end
if (n == 2 or n == 0) and portalgun_portal[name].portal2 ~= nil then
if n == 0 then
local pos = portalgun_portal[name].portal2:get_pos()
if pos ~= nil then
minetest.sound_play("portalgun_closeportals", {pos = pos, max_hear_distance = 20, gain = 1})
end
end
portalgun_portal[name].portal2_active = false
portalgun_portal[name].portal2:set_hp(0)
end
if n == 0 then
portalgun_portal[name] = nil
end
end
minetest.register_on_leaveplayer(
function(player) -- deletes user the profile (saveing memory)
local name = player:get_player_name()
portal_delete(name, 0)
portalgun_portal[name] = nil
end
)
minetest.register_on_dieplayer(
function(player)
local name = player:get_player_name()
portal_delete(name, 0)
portalgun_portal[name] = nil
end
)
portalgun_on_step = function(self, dtime)
local name = self.user
if portalgun_portal[self.user] == nil then
self.object:remove()
return self
end
if
(self.project == 1 and self.use ~= portalgun_portal[self.user].portal1_use) or
(self.project == 2 and self.use ~= portalgun_portal[self.user].portal2_use)
then
self.object:remove()
return self
end
if portalgun_portal[name].lifelime < 0 then
portal_delete(name, 0)
return self
end
if portalgun_portal[name].portal1_active and portalgun_portal[name].portal2_active then -- makes lifetime equal when both is acive, or it will be half
portalgun_portal[name].lifelime = portalgun_portal[name].lifelime - 0.5
else
portalgun_portal[name].lifelime = portalgun_portal[name].lifelime - 1
return self -- abort when only 1 is active (saves cpu)
end
if portalgun_portal[name].timer > 0 then -- makes teleported stuff wont move back at same time (bug fix)
portalgun_portal[name].timer = portalgun_portal[name].timer - dtime
return self
end
if self.portal_max_use > 0 then -- makes teleported stuff wont move back at same time (bug fix)
self.portal_max_use_time = self.portal_max_use_time + dtime
if self.portal_max_use >= portalgun_max_use_per_secund then
portal_delete(name, self.project)
return self
elseif self.portal_max_use_time >= portalgun_max_use_per_secund_time then
self.portal_max_use_time = 0
self.portal_max_use = 0
end
end
local pos1 = 0
local pos2 = 0
local d1 = 0
local d2 = 0
if self.project == 1 then
pos1 = portalgun_portal[name].portal1_pos
pos2 = portalgun_portal[name].portal2_pos
d1 = portalgun_portal[name].portal1_dir
d2 = portalgun_portal[name].portal2_dir
else
pos1 = portalgun_portal[name].portal2_pos
pos2 = portalgun_portal[name].portal1_pos
d1 = portalgun_portal[name].portal2_dir
d2 = portalgun_portal[name].portal1_dir
end
-- portalgun_front_of_field should fix teleport through walls, but is not working in all directions
-- waiting with this issue
if pos2 ~= 0 and pos1 ~= 0 then
for ii, ob in pairs(minetest.get_objects_inside_radius(pos1, self.area)) do
if pos2 ~= 0 then --and portalgun_front_of_field(self.object,ob)
if
(ob:is_player()) or
(ob:get_luaentity() and ob:get_luaentity().portalgun ~= 1 and
ob:get_luaentity().name:find(":text", 4) == nil)
then
if ob:get_attach() then
ob:set_detach()
ob:set_acceleration({x = 0, y = -10, z = 0})
end
--set velocity then teleport
local p = pos2
local x = 0
local y = 0
local z = 0
local dis = 2
if p == nil or p.x == nil then
return self
end
if ob:is_player() then
local v = ob:get_player_velocity()
local player_name = ob:get_player_name()
portalgun_power.user = player_name
portalgun_power.target = ob
local vv = {x = v.x, y = v.y, z = v.z}
-- get the highest velocity
dis = 2
if vv.x + vv.y + vv.z <= 0.3 then
if self.small == true then
vv.x = 1.4
else
vv.x = 2
end
end
if vv.x + vv.y + vv.z == 0 then
vv.x = 2
end
if vv.x < 0 then
vv.x = vv.x * -1
end
if vv.y < 0 then
vv.y = vv.y * -1
end
if vv.z < 0 then
vv.z = vv.z * -1
end
if vv.x > vv.z then
vv.a = vv.x
else
vv.a = vv.z
end
if vv.a < vv.y then
vv.a = vv.y
end
portalgun_power_tmp_power = vv.a
local m = minetest.add_entity(ob:get_pos(), "portalgun:power2")
ob:set_attach(m, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
m:set_velocity(v)
m:set_acceleration({x = 0, y = -10, z = 0})
ob = m
end
if ob:is_player() == false then
local v = ob:get_velocity()
if v.x < 0 then
v.x = v.x * -1
end
if v.y < 0 then
v.y = v.y * -1
end
if v.z < 0 then
v.z = v.z * -1
end
local vv = 0 -- get the highest velocity
if v.x > v.z then
vv = v.x
else
vv = v.z
end
if vv < v.y then
vv = v.y
end
v.x = 0
v.y = 0
v.z = 0
if d2 == "x+" then
v.x = vv
end
if d2 == "x-" then
v.x = vv * -1
end
if d2 == "y+" then
v.y = vv
end
if d2 == "y-" then
v.y = vv * -1
end
if d2 == "z+" then
v.z = vv
end
if d2 == "z-" then
v.z = vv * -1
end
ob:set_velocity({x = v.x, y = v.y, z = v.z})
end
if d2 == "x+" then
x = 2
elseif d2 == "x-" then
x = -dis
elseif d2 == "y+" then
y = dis
elseif d2 == "y-" then
y = -dis
elseif d2 == "z+" then
z = dis
elseif d2 == "z-" then
z = -dis
end
local obpos = {x = p.x + x, y = p.y + y, z = p.z + z}
portalgun_portal[name].timer = 0.2
self.portal_max_use = self.portal_max_use + 1
ob:set_pos(obpos, false)
portalgun_portal[name].lifelime = portalgun_lifelime
minetest.sound_play(
"portalgun_teleport",
{pos = portalgun_portal[name].portal1_pos, max_hear_distance = 10, gain = 30}
)
minetest.sound_play(
"portalgun_teleport",
{pos = portalgun_portal[name].portal2_pos, max_hear_distance = 10, gain = 30}
)
end --end of set velocity part then teleport
end
end
end
end
minetest.register_entity(
"portalgun:portal",
{
-- the portals
hp_max = 10000,
visual = "mesh",
mesh = "portalgun_portal_xp.obj",
physical = false,
textures = {"portalgun_blue.png"},
visual_size = {x = 1, y = 1},
spritediv = {x = 7, y = 0},
collisionbox = {0, 0, 0, 0, 0, 0},
timer = 0,
user = "",
project = 1,
portalgun = 1,
portal_max_use = 0,
portal_max_use_time = 0,
area = 2,
small = false,
get_staticdata = function(self)
return minetest.serialize(
{
user = self.user,
project = self.project,
use = self.use
}
)
end,
on_activate = function(self, staticdata)
local data = minetest.deserialize(staticdata)
if data and type(data) == "table" then
self.user = data.user
self.project = data.project
self.use = data.use
if portalgun_portal[self.user] == nil then
self.object:remove()
return self
end
if
(self.project == 1 and self.use ~= portalgun_portal[self.user].portal1_use) or
(self.project == 2 and self.use ~= portalgun_portal[self.user].portal2_use)
then
self.object:remove()
return self
end
elseif portalgun_portal_tmp_user ~= "" then
self.user = portalgun_portal_tmp_user
portalgun_portal_tmp_user = ""
self.project = portalgun_portal[self.user].project
if self.project == 1 then -- if inactivated then activated and another portal is created: remove
self.use = portalgun_portal[self.user].portal1_use
else
self.use = portalgun_portal[self.user].portal2_use
end
else
self.object:remove()
return self
end
if portalgun_portal[self.user] == nil then
self.object:remove()
return self
end
local d = ""
if self.project == 1 then
d = portalgun_portal[self.user].portal1_dir
self.object:set_properties({textures = {"portalgun_blue.png"}})
else
d = portalgun_portal[self.user].portal2_dir
self.object:set_properties({textures = {"portalgun_orange.png"}})
end
if d == "x+" then
self.object:set_yaw(math.pi * 0)
elseif d == "x-" then
self.object:set_yaw(math.pi * 1)
elseif d == "y+" then
self.object:set_properties({mesh = "portalgun_portal_yp.obj"}) -- becaouse there is no "setpitch"
elseif d == "y-" then
self.object:set_properties({mesh = "portalgun_portal_ym.obj"}) -- becaouse there is no "setpitch"
elseif d == "z+" then
self.object:set_yaw(math.pi * 0.5)
elseif d == "z-" then
self.object:set_yaw(math.pi * 1.5)
end
if d == "y+" then
local pos1 = {}
if self.project == 1 then
pos1 = portalgun_portal[self.user].portal1_pos
else
pos1 = portalgun_portal[self.user].portal2_pos
end
if portalgun_portal[self.user].y > 8 then
pos1.y = pos1.y + 1
end
if portalgun_portal[self.user].y > 12 then
pos1.y = pos1.y + 1
end
if self.project == 1 then
portalgun_portal[self.user].portal1_pos = pos1
else
portalgun_portal[self.user].portal2_pos = pos1
end
elseif
string.find(d, "y", 1) == nil and (portalgun_portal[self.user].x + portalgun_portal[self.user].z < 2.5)
then
self.area = 1.2
self.small = true
self.object:set_properties({visual_size = {x = 0.7, y = 0.7}})
end
end,
on_step = portalgun_on_step
}
)
minetest.register_craftitem(
":",
{
description = "Portalgun",
range = 100,
inventory_image = "portalgun_gun0_rndr.png",
wield_image = "portalgun_gun0_rndr.png",
tool_capabilities = {
full_punch_interval = 0.5,
max_drop_level = 3,
damage_groups = {fleshy = 1}
},
on_place = function(itemstack, user, pointed_thing)
local node = minetest.get_node(pointed_thing.under)
if node.name == "portalgun:button" then
--use the item normally
minetest.item_place(itemstack, user, pointed_thing)
else
portalgun_onuse(itemstack, user, pointed_thing, 2)
end
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
--if pointing at turret then start breaking it
if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under)
if node.name == "portalgun:turretgun" or node.name == "portalgun:turretgun2" then
minetest.remove_node(pointed_thing.under)
end
end
portalgun_onuse(itemstack, user, pointed_thing, 1)
return itemstack
end
}
)
local function rnd(r)
return math.floor(r + 0.5)
end
function portalgun_onuse(itemstack, user, pointed_thing, mode) -- using the gun
if pointed_thing.type == "object" then
portalgun_gravity(itemstack, user, pointed_thing)
return itemstack
end
local pos = user:get_pos()
local dir = user:get_look_dir()
local key = user:get_player_control()
local name = user:get_player_name()
local exist = 0
local item = itemstack:to_table()
local ob = {}
ob.project = 1
ob.lifelime = portalgun_lifelime
ob.portal1 = 0
ob.portal2 = 0
ob.portal1_dir = 0
ob.portal2_dir = 0
ob.portal2_pos = 0
ob.portal1_pos = 0
ob.user = user:get_player_name()
if portalgun_portal[name] == nil then -- new portal profile
portalgun_portal[name] = {
lifelime = portalgun_lifelime,
project = 1,
timer = 0,
portal1_active = false,
portal2_active = false,
portal1_use = 0,
portal2_use = 0
}
end
if key.sneak then
portal_delete(name, 0)
return itemstack
end
pos.y = pos.y + 1.5
-- the project
for i = 1, portalgun_max_rage, 0.5 do
local nname =
minetest.get_node({x = pos.x + (dir.x * i), y = pos.y + (dir.y * i), z = pos.z + (dir.z * i)}).name
if minetest.registered_nodes[nname].walkable then
portalgun_portal[name].lifelime = portalgun_lifelime
if minetest.get_node_group(nname, "antiportal") > 0 then
minetest.sound_play("portalgun_error", {pos = pos, max_hear_distance = 5, gain = 3})
return itemstack
elseif minetest.get_node_group(nname, "proportal") == 0 then
minetest.sound_play("portalgun_error", {pos = pos, max_hear_distance = 5, gain = 3})
return itemstack
end
if
minetest.registered_nodes[
minetest.get_node(
{x = rnd(pos.x + (dir.x * i)), y = rnd(pos.y + (dir.y * i) + 1), z = rnd(pos.z + (dir.z * i))}
).name
].walkable == false and rnd(user:get_pos().y) > rnd(pos.y + (dir.y * i))
then
portalgun_setportal(pos, name, dir, i, mode, "y+")
return itemstack
elseif
minetest.registered_nodes[
minetest.get_node(
{x = rnd(pos.x + (dir.x * i)), y = rnd(pos.y + (dir.y * i) - 1), z = rnd(pos.z + (dir.z * i))}
).name
].walkable == false and rnd(user:get_pos().y) < rnd(pos.y + (dir.y * i))
then
portalgun_setportal(pos, name, dir, i, mode, "y-")
return itemstack
elseif
minetest.registered_nodes[
minetest.get_node(
{x = rnd(pos.x + (dir.x * i) - 1), y = rnd(pos.y + (dir.y * i)), z = rnd(pos.z + (dir.z * i))}
).name
].walkable == false and rnd(user:get_pos().x) < rnd(pos.x + (dir.x * i))
then
portalgun_setportal(pos, name, dir, i, mode, "x-")
return itemstack
elseif
minetest.registered_nodes[
minetest.get_node(
{x = rnd(pos.x + (dir.x * i)) + 1, y = rnd(pos.y + (dir.y * i)), z = rnd(pos.z + (dir.z * i))}
).name
].walkable == false and rnd(user:get_pos().x) > rnd(pos.x + (dir.x * i))
then
portalgun_setportal(pos, name, dir, i, mode, "x+")
return itemstack
elseif
minetest.registered_nodes[
minetest.get_node(
{x = rnd(pos.x + (dir.x * i)), y = rnd(pos.y + (dir.y * i)), z = rnd(pos.z + (dir.z * i) - 1)}
).name
].walkable == false and rnd(user:get_pos().z) < rnd(pos.z + (dir.z * i))
then
portalgun_setportal(pos, name, dir, i, mode, "z-")
return itemstack
elseif
minetest.registered_nodes[
minetest.get_node(
{x = rnd(pos.x + (dir.x * i)), y = rnd(pos.y + (dir.y * i)), z = rnd(pos.z + (dir.z * i) + 1)}
).name
].walkable == false and rnd(user:get_pos().z) > rnd(pos.z + (dir.z * i))
then
portalgun_setportal(pos, name, dir, i, mode, "z+")
return itemstack
end
minetest.sound_play("portalgun_error", {pos = pos, max_hear_distance = 20, gain = 3})
return itemstack
end
end
return itemstack
end
function portalgun_setportal(pos, name, dir, i, mode, portal_dir)
local lpos = {x = pos.x + (dir.x * (i - 1)), y = pos.y + (dir.y * (i - 1)), z = pos.z + (dir.z * (i - 1))} -- last pos
local cpos = {x = pos.x + (dir.x * i), y = pos.y + (dir.y * i), z = pos.z + (dir.z * i)} -- corrent poss
if portal_dir == "y+" then
cpos.y = (math.floor(cpos.y + 0.5)) + 0.524
elseif portal_dir == "y-" then
cpos.y = (math.floor(cpos.y + 0.5)) - 0.524
elseif portal_dir == "z+" then
cpos.z = (math.floor(cpos.z + 0.5)) + 0.524
elseif portal_dir == "z-" then
cpos.z = (math.floor(cpos.z + 0.5)) - 0.524
elseif portal_dir == "x+" then
cpos.x = (math.floor(cpos.x + 0.5)) + 0.524
elseif portal_dir == "x-" then
cpos.x = (math.floor(cpos.x + 0.5)) - 0.524
end
if portal_dir == "x+" or portal_dir == "x-" then -- auto correct (place in center)
cpos.y = (math.floor(cpos.y + 0.5))
cpos.z = (math.floor(cpos.z + 0.5))
elseif portal_dir == "y+" or portal_dir == "y-" then
cpos.x = (math.floor(cpos.x + 0.5))
cpos.z = (math.floor(cpos.z + 0.5))
elseif portal_dir == "z+" or portal_dir == "z-" then
cpos.x = (math.floor(cpos.x + 0.5))
cpos.y = (math.floor(cpos.y + 0.5))
end
if minetest.registered_nodes[minetest.get_node(cpos).name].walkable then
minetest.sound_play("portalgun_error", {pos = pos, max_hear_distance = 5, gain = 3})
return false
end
if string.find(portal_dir, "x", 1) or string.find(portal_dir, "z", 1) then -- auto correct (move from bottom / top)
local testpos1 = {x = cpos.x, y = cpos.y - 1, z = cpos.z}
local testpos2 = {x = cpos.x, y = cpos.y + 1, z = cpos.z}
if
minetest.registered_nodes[minetest.get_node(testpos1).name].walkable and
minetest.registered_nodes[minetest.get_node(testpos2).name].walkable == false
then
cpos.y = cpos.y + 0.5
elseif
minetest.registered_nodes[minetest.get_node(testpos2).name].walkable and
minetest.registered_nodes[minetest.get_node(testpos1).name].walkable == false
then
cpos.y = cpos.y - 0.5
end
end
portalgun_portal_tmp_user = name
portalgun_portal[name].x = pos.x - lpos.x
portalgun_portal[name].y = pos.y - lpos.y
portalgun_portal[name].z = pos.z - lpos.z
portalgun_portal[name].project = mode
if portalgun_portal[name].x < 0 then
portalgun_portal[name].x = portalgun_portal[name].x * -1
end
if portalgun_portal[name].z < 0 then
portalgun_portal[name].z = portalgun_portal[name].z * -1
end
if mode == 1 then
portal_delete(name, 1)
portalgun_portal[name].portal1_use = portalgun_portal[name].portal1_use + 1
portalgun_portal[name].portal1_dir = portal_dir
portalgun_portal[name].portal1_pos = cpos
portalgun_portal[name].portal1 = minetest.add_entity(cpos, "portalgun:portal")
portalgun_portal[name].portal1_active = true
minetest.sound_play("portalgun_portalblue", {pos = cpos, max_hear_distance = 20, gain = 1})
else
portal_delete(name, 2)
portalgun_portal[name].portal2_use = portalgun_portal[name].portal2_use + 1
portalgun_portal[name].portal2_dir = portal_dir
portalgun_portal[name].portal2_pos = cpos
portalgun_portal[name].portal2 = minetest.add_entity(cpos, "portalgun:portal")
portalgun_portal[name].portal2_active = true
minetest.sound_play("portalgun_portalorange", {pos = cpos, max_hear_distance = 20, gain = 1})
end
end
portalgun_front_of_field = function(ob, ob2)
local pos2 = ob2:get_pos()
return vector.distance(ob:get_pos(), pos2) > vector.distance(portalgun_pointat(ob), pos2)
end
portalgun_pointat = function(ob)
local pos = ob:get_pos()
local yaw = ob:get_yaw()
if yaw ~= yaw or type(yaw) ~= "number" then
yaw = 0
end
local z = math.sin(yaw) * -0.1
local x = math.cos(yaw) * 0.1
return {x = pos.x + x, y = pos.y, z = pos.z + z}
end

52
scripts/portaltarget.lua Normal file

@ -0,0 +1,52 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
local portaltarget_sig = {
{1, "portalgun_blue.png"},
{2, "portalgun_orange.png"}
}
for ii = 1, #portaltarget_sig, 1 do
minetest.register_node(
"portalgun:portaltarget_" .. portaltarget_sig[ii][1],
{
description = "Portal target " .. portaltarget_sig[ii][1],
tiles = {"portalgun_testblock.png^" .. portaltarget_sig[ii][2]},
groups = {mesecon = 2, cracky = 2},
mesecons = {receptor = {state = "off"}},
sounds = stone_sounds,
is_ground_content = false,
paramtype2 = "facedir",
paramtype = "light",
on_timer = function(pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 2)) do
if
ob:get_luaentity() and ob:get_luaentity().portalgun and
ob:get_luaentity().project == portaltarget_sig[ii][1]
then
mesecon.receptor_on(pos)
return true
end
end
mesecon.receptor_off(pos)
return true
end,
on_construct = function(pos)
if not mesecon then
return false
end
minetest.get_node_timer(pos):start(2)
end
}
)
end

86
scripts/powerball.lua Normal file

@ -0,0 +1,86 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
new = 0
minetest.register_entity(
"portalgun:powerball",
{
hp_max = 1000,
physical = true,
weight = 0,
collisionbox = {-0.4, -0.4, -0.4, 0.4, 0.4, 0.4},
visual = "sprite",
visual_size = {x = 1.1, y = 1.1},
textures = {"portalgun_powrball.png"},
initial_sprite_basepos = {x = 0, y = 0},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = 0,
portalgun = 2,
powerball = 1,
on_activate = function(self, staticdata)
if new == 0 then
self.object:remove()
return self
end
new = 0
local pos = self.object:get_pos()
self.sound = minetest.sound_play("portalgun_powerball", {pos = pos, max_hear_distance = 10, gain = 0.5})
minetest.sound_play("portalgun_powerballbonce", {pos = pos, max_hear_distance = 10, gain = 1})
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer < 0.2 then
return self
end
self.timer = 0
local pos = self.object:get_pos()
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 2)) do
if
ob:is_player() or
(ob:get_luaentity() and ob:get_luaentity().portalgun ~= 1 and ob:get_luaentity().wsc == nil and
ob:get_luaentity().powerball ~= 1)
then
ob:set_hp(0)
end
end
self.timer2 = self.timer2 + 1
self.timer3 = self.timer3 + 1
if self.timer3 >= 9 then
self.timer3 = 0
minetest.sound_stop(self.sound)
self.sound = minetest.sound_play("portalgun_powerball", {pos = pos, max_hear_distance = 10, gain = 0.5})
end
if self.timer2 > 40 then
minetest.sound_stop(self.sound)
self.object:set_hp(0)
return self
end
local v = self.object:get_velocity()
local nextn = {x = pos.x + (v.x) / 3, y = pos.y + (v.y) / 3, z = pos.z + (v.z) / 3}
local nname = minetest.get_node(nextn).name
if minetest.registered_nodes[nname].walkable then
if nname == "portalgun:powerballtarget" and mesecon then
mesecon.receptor_on(nextn)
minetest.get_node_timer(nextn):start(5)
self.object:remove()
end
self.object:set_velocity({x = v.x * -1, y = v.y * -1, z = v.z * -1})
minetest.sound_play("portalgun_powerballbonce", {pos = pos, max_hear_distance = 10, gain = 1})
end
end,
timer = 0,
timer2 = 0,
timer3 = 0,
sound = {}
}
)

@ -0,0 +1,95 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
new = 0
minetest.register_node(
"portalgun:powerballspawner",
{
description = "Power ball spawner",
tiles = {"steel.png", "steel.png", "steel.png", "steel.png", "steel.png", "portalgun_powerballspawner.png"},
groups = {cracky = 2},
sounds = glass_sounds,
is_ground_content = false,
paramtype2 = "facedir",
on_construct = function(pos)
minetest.get_node_timer(pos):start(10)
end,
on_timer = function(pos, elapsed)
local dir = minetest.get_node(pos).param2
local v = {x = 0, y = 0, z = 0}
if dir == 0 then
v.z = -1
elseif dir == 1 then
v.x = -1
elseif dir == 2 then
v.z = 1
elseif dir == 3 then
v.x = 1
elseif dir == 5 then
v.y = -1
elseif dir == 4 then
v.y = 1
else
v.y = -1
end
local pv = {x = pos.x + v.x, y = pos.y + v.y, z = pos.z + v.z}
new = 1
local m = minetest.add_entity(pv, "portalgun:powerball")
m:set_velocity({x = v.x * 4, y = v.y * 4, z = v.z * 4})
return true
end
}
)
minetest.register_node(
"portalgun:powerballspawner2",
{
description = "Power ball spawner (spawn on activate)",
tiles = {
"steel.png",
"steel.png",
"steel.png",
"steel.png",
"steel.png",
"portalgun_powerballspawner.png^[colorize:#aaaa0055"
},
groups = {cracky = 2, mesecon = 1},
sounds = glass_sounds,
is_ground_content = false,
paramtype2 = "facedir",
on_place = minetest.rotate_node,
mesecons = {
effector = {
action_on = function(pos, node)
local dir = minetest.get_node(pos).param2
local v = {x = 0, y = 0, z = 0}
if dir == 0 then
v.z = -1
elseif dir == 1 then
v.x = -1
elseif dir == 2 then
v.z = 1
elseif dir == 3 then
v.x = 1
elseif dir == 8 then
v.y = -1
elseif dir == 4 then
v.y = 1
end
local pv = {x = pos.x + v.x, y = pos.y + v.y, z = pos.z + v.z}
new = 1
local m = minetest.add_entity(pv, "portalgun:powerball")
m:set_velocity({x = v.x * 4, y = v.y * 4, z = v.z * 4})
end
}
}
}
)

@ -0,0 +1,27 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:powerballtarget",
{
description = "Power ball target",
tiles = {"portalgun_powerballstarget.png"},
groups = {mesecon = 2, cracky = 2},
mesecons = {receptor = {state = "off"}},
sounds = stone_sounds,
is_ground_content = false,
on_timer = function(pos, elapsed)
mesecon.receptor_off(pos)
return false
end
}
)

@ -0,0 +1,236 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
local ptgwsc = {
{"weightedstoragecube.png", "portalgun_presplat.png", "(blue)"},
{"weightedstoragecube2.png", "portalgun_presplat2.png", "(orange)"},
{"weightedstoragecube3.png", "portalgun_presplat3.png", "(yellow)"},
{"weightedstoragecube4.png", "portalgun_presplat4.png", "(green)"},
{"weightedcompanioncube.png", "portalgun_presplat.png", "(blue companion)"},
{"weightedcompanioncube2.png", "portalgun_presplat2.png", "(orange companion)"},
{"weightedcompanioncube3.png", "portalgun_presplat3.png", "(yellow companion)"},
{"weightedcompanioncube4.png", "portalgun_presplat4.png", "(green companion)"}
}
for ii = 1, #ptgwsc, 1 do
minetest.register_node(
"portalgun:plantform1_" .. ii,
{
description = "Pressure platform " .. ptgwsc[ii][3],
tiles = {ptgwsc[ii][2], "cloud.png", "cloud.png", "cloud.png", "cloud.png", "cloud.png"},
groups = {mesecon = 2, cracky = 1, not_in_creative_inventory = 0},
mesecons = {receptor = {state = "off"}},
paramtype = "light",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9},
{-0.5, -0.5, -0.5, 0.5, -0.3125, 0.5}
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(2)
end,
on_timer = function(pos, elapsed)
if not mesecon then
return false
end
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if ob:get_luaentity() and ob:get_luaentity().wsc == ii then
local node = minetest.get_node(pos)
mesecon.receptor_on(pos)
minetest.set_node(
pos,
{name = "portalgun:plantform2_" .. ii, param1 = node.param1, param2 = node.param2}
)
end
return true
end
return true
end
}
)
minetest.register_node(
"portalgun:plantform2_" .. ii,
{
description = "Pressure platform",
tiles = {ptgwsc[ii][2], "cloud.png", "cloud.png", "cloud.png", "cloud.png", "cloud.png"},
drop = "portalgun:plantform1_" .. ii,
groups = {mesecon = 2, cracky = 1, not_in_creative_inventory = 1},
mesecons = {receptor = {state = "on"}},
paramtype = "light",
sunlight_propagates = true,
light_source = 14,
sounds = stone_sounds,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9}
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(2)
end,
on_timer = function(pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if ob:get_luaentity() and ob:get_luaentity().wsc == ii then
return true
end
end
mesecon.receptor_off(pos)
local node = minetest.get_node(pos)
minetest.set_node(
pos,
{name = "portalgun:plantform1_" .. ii, param1 = node.param1, param2 = node.param2}
)
return true
end
}
)
end -- of for #
minetest.register_node(
"portalgun:plantform_nu1",
{
description = "Pressure platform (player or cube)",
tiles = {"portalgun_presplat5.png", "cloud.png", "cloud.png", "cloud.png", "cloud.png", "cloud.png"},
groups = {mesecon = 2, cracky = 1, not_in_creative_inventory = 0},
mesecons = {receptor = {state = "off"}},
paramtype = "light",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9},
{-0.5, -0.5, -0.5, 0.5, -0.3125, 0.5}
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(2)
end,
on_timer = function(pos, elapsed)
if not mesecon then
return false
end
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().wsc) then
local node = minetest.get_node(pos)
mesecon.receptor_on(pos)
minetest.set_node(
pos,
{name = "portalgun:plantform_nu2", param1 = node.param1, param2 = node.param2}
)
end
return true
end
return true
end
}
)
minetest.register_node(
"portalgun:plantform_nu2",
{
description = "Pressure platform",
tiles = {"portalgun_presplat5.png", "cloud.png", "cloud.png", "cloud.png", "cloud.png", "cloud.png"},
drop = "portalgun:plantform_nu1",
groups = {mesecon = 2, cracky = 1, not_in_creative_inventory = 1},
mesecons = {receptor = {state = "on"}},
paramtype = "light",
sunlight_propagates = true,
light_source = 14,
sounds = stone_sounds,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9}
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(2)
end,
on_timer = function(pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().wsc) then
return true
end
end
mesecon.receptor_off(pos)
local node = minetest.get_node(pos)
minetest.set_node(pos, {name = "portalgun:plantform_nu1", param1 = node.param1, param2 = node.param2})
return true
end
}
)
minetest.register_node(
"portalgun:planthole",
{
description = "Plathole (activate by any cube, 2 blocks under)",
tiles = {"cloud.png"},
groups = {mesecon = 2, cracky = 1},
mesecons = {receptor = {state = "off"}},
paramtype = "light",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-1.5, -0.5, -1.5, 0.5, -0.25, -1.3},
{-1.5, -0.5, 0.3, 0.5, -0.25, 0.5},
{0.3, -0.5, -1.5, 0.5, -0.25, 0.5},
{-1.5, -0.5, -1.5, -1.3, -0.25, 0.5},
{0.5, -0.5, -0.9, 0.7, -0.375, -0.0625},
{-1.7, -0.5, -0.9, -1.5, -0.3125, -0.0625},
{-0.9, -0.5, -1.7, -0.0625, -0.375, -1.5},
{-1, -0.5, 0.5, -0.0625, -0.375, 0.7}
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(5)
end,
on_timer = function(pos, elapsed)
local pos2 = {x = pos.x, y = pos.y - 2, z = pos.z}
for i, ob in pairs(minetest.get_objects_inside_radius(pos2, 1)) do
if ob:get_luaentity() and ob:get_luaentity().wsc then
mesecon.receptor_on(pos)
return true
end
end
mesecon.receptor_off(pos)
return true
end
}
)

202
scripts/signs.lua Normal file

@ -0,0 +1,202 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
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 = wood_sounds,
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 = wood_sounds,
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: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 = wood_sounds,
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 = wood_sounds,
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:sign_v",
{
description = "Sign V",
tiles = {"portalgun_v.png"},
inventory_image = "portalgun_v.png",
drop = "portalgun:sign_x",
drawtype = "nodebox",
groups = {mesecon = 2, snappy = 3, not_in_creative_inventory = 1},
sounds = wood_sounds,
is_ground_content = false,
paramtype2 = "facedir",
paramtype = "light",
light_source = 5,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, 0.45, 0.5, 0.5, 0.5}
},
mesecons = {
effector = {
action_off = function(pos, node)
minetest.swap_node(pos, {name = "portalgun:sign_x", param2 = minetest.get_node(pos).param2})
end
}
}
}
)
minetest.register_node(
"portalgun:sign_x",
{
description = "Sign X",
tiles = {"portalgun_x.png"},
inventory_image = "portalgun_x.png",
drawtype = "nodebox",
groups = {mesecon = 2, snappy = 3, not_in_creative_inventory = 0},
sounds = wood_sounds,
is_ground_content = false,
paramtype2 = "facedir",
paramtype = "light",
light_source = 3,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, 0.45, 0.5, 0.5, 0.5}
},
mesecons = {
effector = {
action_on = function(pos, node)
minetest.swap_node(pos, {name = "portalgun:sign_v", param2 = minetest.get_node(pos).param2})
end
}
}
}
)

58
scripts/toxicwater.lua Normal file

@ -0,0 +1,58 @@
minetest.register_node(
"portalgun:toxwater_1",
{
description = "Toxic water",
drawtype = "liquid",
tiles = {"portalgun_toxwat.png"},
alpha = 190,
paramtype = "light",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
damage_per_second = 20,
liquidtype = "source",
liquid_alternative_flowing = "portalgun:toxwater_2",
liquid_alternative_source = "portalgun:toxwater_1",
liquid_viscosity = 2,
liquid_renewable = false,
liquid_range = 3,
post_effect_color = {a = 200, r = 119, g = 70, b = 16},
groups = {water = 3, liquid = 3}
}
)
minetest.register_node(
"portalgun:toxwater_2",
{
description = "Toxic water 2",
drawtype = "flowingliquid",
tiles = {name = "portalgun_toxwat.png", backface_culling = false},
special_tiles = {
{name = "portalgun_toxwat.png", backface_culling = true},
{name = "portalgun_toxwat.png", backface_culling = false}
},
alpha = 190,
paramtype = "light",
paramtype2 = "flowingliquid",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
damage_per_second = 4,
liquidtype = "flowing",
liquid_alternative_flowing = "portalgun:toxwater_2",
liquid_alternative_source = "portalgun:toxwater_1",
liquid_viscosity = 2,
liquid_renewable = false,
liquid_range = 3,
post_effect_color = {a = 200, r = 119, g = 70, b = 16},
groups = {water = 3, liquid = 3, not_in_creative_inventory = 1}
}
)

257
scripts/turrets.lua Normal file

@ -0,0 +1,257 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:turretgun2",
{
description = "Sentry turret",
groups = {oddly_breakable_by_hand = 1, not_in_creative_inventory = 1},
drop = "portalgun:turretgun",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
tiles = {"portalgun_sentry_turret.png"},
drawtype = "mesh",
mesh = "turret2.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.y < pos.y + 2 and a.y > pos.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.x < pos.x and a.z == pos.z then
d = {x = -20, y = 0, z = 0}
break
elseif p == 2 and a.z > pos.z and a.x == pos.x then
d = {x = 0, y = 0, z = 20}
break
elseif p == 0 and a.z < pos.z and a.x == pos.x then
d = {x = 0, y = 0, z = -20}
break
end
end
end
end
local m = minetest.get_meta(pos)
if d then
m:set_int("stop", 0)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos = pos, gain = 1, max_hear_distance = 15})
for i = 2, 5, 1 do
minetest.after(
i * 0.1,
function(pos, d)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos = pos, gain = 1, max_hear_distance = 15})
end,
pos,
d
)
end
else
if m:get_int("stop") == 1 then
minetest.set_node(pos, {name = "portalgun:turretgun", param2 = p})
minetest.get_node_timer(pos):start(0.2)
else
m:set_int("stop", 1)
end
end
return true
end
}
)
minetest.register_node(
"portalgun:turretgun",
{
description = "Sentry turret",
groups = {oddly_breakable_by_hand = 1},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
tiles = {"portalgun_sentry_turret.png"},
drawtype = "mesh",
mesh = "turret1.obj",
selection_box = {
type = "fixed",
fixed = {
{-0.3, -0.5, -0.3, 0.3, 1, 0.3}
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(0.2)
end,
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(pos1, 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.y < pos.y + 2 and a.y > pos.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.x < pos.x and a.z == pos.z then
d = {x = -20, y = 0, z = 0}
break
elseif p == 2 and a.z > pos.z and a.x == pos.x then
d = {x = 0, y = 0, z = 20}
break
elseif p == 0 and a.z < pos.z and a.x == pos.x then
d = {x = 0, y = 0, z = -20}
break
end
end
end
end
if d then
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.set_node(pos, {name = "portalgun:turretgun2", param2 = p})
minetest.get_node_timer(pos):start(1)
minetest.sound_play("portalgun_bullet1", {pos = pos, gain = 1, max_hear_distance = 15})
for i = 2, 5, 1 do
minetest.after(
i * 0.1,
function(pos, d)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos = pos, gain = 1, max_hear_distance = 15})
end,
pos,
d
)
end
end
return true
end
}
)
function portalgun_visiable(pos, ob)
if ob == nil or ob:get_pos() == nil or ob:get_pos().y == nil then
return false
end
local ta = ob:get_pos()
local v = {x = pos.x - ta.x, y = pos.y - ta.y - 1, z = pos.z - ta.z}
v.y = v.y - 1
local amount = (v.x ^ 2 + v.y ^ 2 + v.z ^ 2) ^ 0.5
local d =
math.sqrt((pos.x - ta.x) * (pos.x - ta.x) + (pos.y - ta.y) * (pos.y - ta.y) + (pos.z - ta.z) * (pos.z - ta.z))
v.x = (v.x / amount) * -1
v.y = (v.y / amount) * -1
v.z = (v.z / amount) * -1
for i = 1, d, 1 do
local node =
minetest.registered_nodes[
minetest.get_node({x = pos.x + (v.x * i), y = pos.y + (v.y * i), z = pos.z + (v.z * i)}).name
]
if node.walkable then
return false
end
end
return true
end
function portalgun_round(x)
if x % 2 ~= 0.5 then
return math.floor(x + 0.5)
end
return x - 0.5
end
function portalgun_ra2shoot(pos, ob)
local op = ob:get_pos()
local m = minetest.get_meta(pos)
local x = m:get_int("x")
local y = m:get_int("y")
local z = m:get_int("z")
local ox = portalgun_round(op.x)
local oy = portalgun_round(op.y)
local oz = portalgun_round(op.z)
if x == 1 and ox == pos.x and oz <= pos.z then
return true
end
if x == -1 and ox == pos.x and oz >= 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_entity(
"portalgun:bullet1",
{
hp_max = 1,
--physical = true,
--collisionbox={-0.01,-0.01,-0.01,0.01,0.01,0.01},
pointable = false,
visual = "mesh",
mesh = "bullet.obj",
--yellow color as tiles
tiles = {"#color[yellow]"},
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() then
if ob:get_hp() > 2 then
ob:set_hp(ob:get_hp() - 2)
else
ob:set_hp(0)
end
self.object:remove()
return
end
end
end,
timer = 0,
timer2 = 0
}
)

32
scripts/warntape.lua Normal file

@ -0,0 +1,32 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:warntape",
{
description = "Warntape",
groups = {dig_immediate = 3, not_in_creative_inventory = 0},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
tiles = {"portalgun_warntape.png"},
walkable = false,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, 0.3125, 0.5, -0.4375, 0.5}
}
}
}
)

@ -0,0 +1,88 @@
stone_sounds = {}
stone_sounds.footstep = {name = "stone_walk", gain = 1.0}
stone_sounds.dug = {name = "stone_break", gain = 1.0}
stone_sounds.place = {name = "block_place", gain = 1.0}
glass_sounds = {}
glass_sounds.footstep = {name = "glass_walk", gain = 1.0}
glass_sounds.dug = {name = "glass_break", gain = 1.0}
glass_sounds.place = {name = "block_place", gain = 1.0}
wood_sounds = {}
wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
new = 0
local ptgwsc = {
{"weightedstoragecube.png", "portalgun_presplat.png", "(blue)"},
{"weightedstoragecube2.png", "portalgun_presplat2.png", "(orange)"},
{"weightedstoragecube3.png", "portalgun_presplat3.png", "(yellow)"},
{"weightedstoragecube4.png", "portalgun_presplat4.png", "(green)"},
{"weightedcompanioncube.png", "portalgun_presplat.png", "(blue companion)"},
{"weightedcompanioncube2.png", "portalgun_presplat2.png", "(orange companion)"},
{"weightedcompanioncube3.png", "portalgun_presplat3.png", "(yellow companion)"},
{"weightedcompanioncube4.png", "portalgun_presplat4.png", "(green companion)"}
}
for ii = 1, #ptgwsc, 1 do
minetest.register_craftitem(
"portalgun:wscube" .. ii,
{
description = "Weighted storage cube " .. ptgwsc[ii][3],
inventory_image = minetest.inventorycube(ptgwsc[ii][1]),
on_place = function(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
new = 1
local m = minetest.add_entity(pointed_thing.above, "portalgun:wsc" .. ii)
m:set_acceleration({x = 0, y = -10, z = 0})
itemstack:take_item()
end
return itemstack
end
}
)
minetest.register_entity(
"portalgun:wsc" .. ii,
{
hp_max = 100,
physical = true,
weight = 5,
collisionbox = {-0.6, -0.6, -0.6, 0.6, 0.6, 0.6},
visual = "cube",
visual_size = {x = 1.1, y = 1.1},
textures = {ptgwsc[ii][1], ptgwsc[ii][1], ptgwsc[ii][1], ptgwsc[ii][1], ptgwsc[ii][1], ptgwsc[ii][1]},
initial_sprite_basepos = {x = 0, y = 0},
is_visible = true,
makes_footstep_sound = true,
automatic_rotate = 0,
portalgun = 2,
wsc = ii,
on_activate = function(self, staticdata)
if new == 0 then
self.object:remove()
return self
end
new = 0
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer < 1 then
return self
end
self.timer = 0
self.object:set_acceleration({x = 0, y = -10, z = 0})
self.timer2 = self.timer2 + 1
if self.timer2 > 4 then
self.timer2 = 0
for i, ob in pairs(minetest.get_objects_inside_radius(self.object:get_pos(), 20)) do
if ob:is_player() then
return true
end
end
self.object:set_hp(0)
end
end,
timer = 0,
timer2 = 0
}
)
end -- of for #

606
stuff.lua

@ -1,606 +0,0 @@
stone_sounds = {}
stone_sounds.footstep = {name="stone_walk", gain=1.0}
stone_sounds.dug = {name="stone_break", gain=1.0}
stone_sounds.place = {name="block_place", gain=1.0}
glass_sounds = {}
glass_sounds.footstep = {name="glass_walk", gain=1.0}
glass_sounds.dug = {name="glass_break", gain=1.0}
glass_sounds.place = {name="block_place", gain=1.0}
wood_sounds = {}
wood_sounds.footstep = {name="wood_walk", gain=1.0}
wood_sounds.dug = {name="wood_break", gain=1.0}
wood_sounds.place = {name="block_place", gain=1.0}
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 = wood_sounds,
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 = wood_sounds,
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 = {oddly_breakable_by_hand=1,not_in_creative_inventory=1},
drop="portalgun:turretgun",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
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.y<pos.y+2 and a.y>pos.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.x<pos.x and a.z==pos.z then
d={x=-20,y=0,z=0}
break
elseif p==2 and a.z>pos.z and a.x==pos.x then
d={x=0,y=0,z=20}
break
elseif p==0 and a.z<pos.z and a.x==pos.x then
d={x=0,y=0,z=-20}
break
end
end
end
end
local m=minetest.get_meta(pos)
if d then
m:set_int("stop",0)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos=pos, gain = 1, max_hear_distance = 15})
for i=2,5,1 do
minetest.after(i*0.1, function(pos,d)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos=pos, gain = 1, max_hear_distance = 15})
end, pos,d)
end
else
if m:get_int("stop")==1 then
minetest.set_node(pos,{name="portalgun:turretgun",param2=p})
minetest.get_node_timer(pos):start(0.2)
else
m:set_int("stop",1)
end
end
return true
end
})
minetest.register_node("portalgun:turretgun", {
description = "Sentry turret",
groups = {oddly_breakable_by_hand=1},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
tiles = {"portalgun_sentry_turret.png"},
drawtype = "mesh",
mesh="torret1.obj",
selection_box = {
type = "fixed",
fixed = {
{-0.3, -0.5, -0.3, 0.3, 1,0.3},
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(0.2)
end,
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(pos1, 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.y<pos.y+2 and a.y>pos.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.x<pos.x and a.z==pos.z then
d={x=-20,y=0,z=0}
break
elseif p==2 and a.z>pos.z and a.x==pos.x then
d={x=0,y=0,z=20}
break
elseif p==0 and a.z<pos.z and a.x==pos.x then
d={x=0,y=0,z=-20}
break
end
end
end
end
if d then
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.set_node(pos,{name="portalgun:turretgun2",param2=p})
minetest.get_node_timer(pos):start(1)
minetest.sound_play("portalgun_bullet1", {pos=pos, gain = 1, max_hear_distance = 15})
for i=2,5,1 do
minetest.after(i*0.1, function(pos,d)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos=pos, gain = 1, max_hear_distance = 15})
end, pos,d)
end
end
return true
end
})
--giveitems register_chatcommand
minetest.register_chatcommand("giveitems", {
description = "Give items to player",
privs = {give=true},
func = function(name)
local player = minetest.get_player_by_name(name)
if player then
--clear inventory
player:get_inventory():set_list("main", {})
--GIVE turret
player:get_inventory():add_item("main", "portalgun:turretgun")
--give testblock
player:get_inventory():add_item("main", "portalgun:testblock")
end
end,
})
minetest.register_node("portalgun:warntape", {
description = "Warntape",
groups = {dig_immediate = 3,not_in_creative_inventory=0},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
tiles = {"portalgun_warntape.png",},
walkable = false,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, 0.3125, 0.5, -0.4375, 0.5},
}
}
})
minetest.register_node("portalgun:toxwater_1", {
description = "Toxic water",
drawtype = "liquid",
tiles = {"portalgun_toxwat.png"},
alpha = 190,
paramtype = "light",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
damage_per_second = 20,
liquidtype = "source",
liquid_alternative_flowing = "portalgun:toxwater_2",
liquid_alternative_source = "portalgun:toxwater_1",
liquid_viscosity = 2,
liquid_renewable = false,
liquid_range = 3,
post_effect_color = {a = 200, r = 119, g = 70, b = 16},
groups = {water = 3, liquid = 3},
})
minetest.register_node("portalgun:toxwater_2", {
description = "Toxic water 2",
drawtype = "flowingliquid",
tiles = {name = "portalgun_toxwat.png",backface_culling=false},
special_tiles = {{name = "portalgun_toxwat.png",backface_culling=true},{name = "portalgun_toxwat.png",backface_culling=false}},
alpha = 190,
paramtype = "light",
paramtype2 = "flowingliquid",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
damage_per_second = 4,
liquidtype = "flowing",
liquid_alternative_flowing = "portalgun:toxwater_2",
liquid_alternative_source = "portalgun:toxwater_1",
liquid_viscosity = 2,
liquid_renewable = false,
liquid_range = 3,
post_effect_color = {a = 200, r = 119, g = 70, b = 16},
groups = {water = 3, liquid = 3, not_in_creative_inventory = 1}
})
minetest.register_tool("portalgun:pick", {
--a pickaxe that can mine all blocks
description = "Portalgun Pickaxe",
inventory_image = "portalgun_pick.png",
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level = 3,
groupcaps = {
unbreakable = {times={[1]=1, [2]=1, [3]=1}, uses=0, maxlevel=3},
fleshy = {times={[1]=1, [2]=1, [3]=1}, uses=0, maxlevel=3},
choppy = {times={[1]=1, [2]=1, [3]=1}, uses=0, maxlevel=3},
bendy = {times={[1]=1, [2]=1, [3]=1}, uses=0, maxlevel=3},
cracky = {times={[1]=1, [2]=1, [3]=1}, uses=0, maxlevel=3},
crumbly = {times={[1]=1, [2]=1, [3]=1}, uses=0, maxlevel=3},
snappy = {times={[1]=1, [2]=1, [3]=1}, uses=0, maxlevel=3},
},
damage_groups = {fleshy = 1000},
},
})
minetest.register_tool("portalgun:ed", {
description = "Entity Destroyer",
inventory_image = "portalgun_edestroyer.png",
range = 15,
on_use = function(itemstack, user, pointed_thing)
local pos=user:get_pos()
if pointed_thing.type=="node" then
pos=pointed_thing.above
end
if pointed_thing.type=="object" then
pos=pointed_thing.ref:get_pos()
end
local name=user:get_player_name()
if minetest.check_player_privs(name, {kick=true})==false then
minetest.chat_send_player(name, "You need the kick privilege to use this tool!")
return itemstack
end
for ii, ob in pairs(minetest.get_objects_inside_radius(pos, 7)) do
if ob:get_luaentity() then
ob:set_hp(0)
end
end
return itemstack
end
})
minetest.register_node("portalgun:cake", {
description = "Cake",
groups = {dig_immediate = 3,not_in_creative_inventory=0},
paramtype = "light",
sunlight_propagates = true,
selection_box = {type = "fixed",fixed = { -0.3, -0.5, -0.3, 0.3, 0, 0.3 }},
sounds = stone_sounds,
tiles = {
"dirt.png^portalgun_cake1.png",
"dirt.png^portalgun_cake2.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.3125, -0.5, 0.375, 0.3125, -0.125, 0.4375},
{-0.3125, -0.5, -0.4375, 0.3125, -0.125, -0.375},
{-0.4375, -0.5, -0.3125, -0.375, -0.125, 0.3125},
{0.375, -0.5, -0.3125, 0.4375, -0.125, 0.3125},
{-0.375, -0.5, -0.375, 0.375, -0.125, 0.375},
{-0.25, -0.5, 0.4375, 0.25, -0.125, 0.5},
{-0.25, -0.5, -0.5, 0.25, -0.125, -0.4375},
{0.4375, -0.5, -0.25, 0.5, -0.125, 0.25},
{-0.5, -0.5, -0.25, -0.4375, -0.125, 0.25},
{0, -0.125, -0.0625, 0.0625, 0.1875, 0},
}
}
})
minetest.register_node("portalgun:testblock", {
description = "Test block",
tiles = {"portalgun_testblock.png"},
groups = {cracky = 1},
sounds = stone_sounds,
})
minetest.register_node("portalgun:apb", {
description = "Anti portal block",
tiles = {"portalgun_testblock.png^[colorize:#ffffffaa"},
groups = {cracky = 3,antiportal=1},
sounds = stone_sounds,
})
minetest.register_node("portalgun:apg", {
description = "Anti portal glass",
drawtype="glasslike",
paramtype="light",
sunlight_propagates = true,
tiles = {"glass.png^[colorize:#ffffffaa"},
groups = {cracky = 1,antiportal=1},
sounds = glass_sounds,
})
minetest.register_node("portalgun:hard_glass", {
description = "Hard glass",
drawtype="glasslike",
paramtype="light",
sunlight_propagates = true,
tiles = {"glass.png^[colorize:#ddddddaa"},
groups = {cracky = 1},
sounds = glass_sounds,
})
function portalgun_visiable(pos,ob)
if ob==nil or ob:get_pos()==nil or ob:get_pos().y==nil then return false end
local ta=ob:get_pos()
local v = {x = pos.x - ta.x, y = pos.y - ta.y-1, z = pos.z - ta.z}
v.y=v.y-1
local amount = (v.x ^ 2 + v.y ^ 2 + v.z ^ 2) ^ 0.5
local d=math.sqrt((pos.x-ta.x)*(pos.x-ta.x) + (pos.y-ta.y)*(pos.y-ta.y)+(pos.z-ta.z)*(pos.z-ta.z))
v.x = (v.x / amount)*-1
v.y = (v.y / amount)*-1
v.z = (v.z / amount)*-1
for i=1,d,1 do
local node=minetest.registered_nodes[minetest.get_node({x=pos.x+(v.x*i),y=pos.y+(v.y*i),z=pos.z+(v.z*i)}).name]
if node.walkable then
return false
end
end
return true
end
function portalgun_round(x)
if x%2 ~= 0.5 then
return math.floor(x+0.5)
end
return x-0.5
end
function portalgun_ra2shoot(pos,ob)
local op=ob:get_pos()
local m=minetest.get_meta(pos)
local x=m:get_int("x")
local y=m:get_int("y")
local z=m:get_int("z")
local ox=portalgun_round(op.x)
local oy=portalgun_round(op.y)
local oz=portalgun_round(op.z)
if x==1 and ox==pos.x and oz<=pos.z then
return true
end
if x==-1 and ox==pos.x and oz>=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 = glass_sounds,
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 = glass_sounds,
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,
})
--register command for admins to build a testblock at the players position
minetest.register_chatcommand("testblock", {
params = "",
description = "builds a testblock at the players position",
privs = {server=true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
local pos = player:get_pos()
minetest.set_node(pos, {name = "portalgun:testblock"})
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 = "mesh",
mesh = "bullet.obj",
--yellow color as tiles
tiles = {"#color[yellow]"},
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() then
if ob:get_hp() > 2 then
ob:set_hp(ob:get_hp()-2)
else
ob:set_hp(0)
end
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 = wood_sounds,
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 = wood_sounds,
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}},
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

@ -1,362 +0,0 @@
stone_sounds = {}
stone_sounds.footstep = {name="stone_walk", gain=1.0}
stone_sounds.dug = {name="stone_break", gain=1.0}
stone_sounds.place = {name="block_place", gain=1.0}
glass_sounds = {}
glass_sounds.footstep = {name="glass_walk", gain=1.0}
glass_sounds.dug = {name="glass_break", gain=1.0}
glass_sounds.place = {name="block_place", gain=1.0}
wood_sounds = {}
wood_sounds.footstep = {name="wood_walk", gain=1.0}
wood_sounds.dug = {name="wood_break", gain=1.0}
wood_sounds.place = {name="block_place", gain=1.0}
local ptgwsc={
{"weightedstoragecube.png","portalgun_presplat.png","(blue)"},
{"weightedstoragecube2.png","portalgun_presplat2.png","(orange)"},
{"weightedstoragecube3.png","portalgun_presplat3.png","(yellow)"},
{"weightedstoragecube4.png","portalgun_presplat4.png","(green)"},
}
for ii = 1, #ptgwsc, 1 do
minetest.register_craftitem("portalgun:wscube" ..ii, {
description = "Weighted storage cube " .. ptgwsc[ii][3],
inventory_image = minetest.inventorycube(ptgwsc[ii][1]),
on_place=function(itemstack, user, pointed_thing)
if pointed_thing.type=="node" then
portalgun.new=1
local m=minetest.add_entity(pointed_thing.above, "portalgun:wsc"..ii)
m:set_acceleration({x=0,y=-10,z=0})
itemstack:take_item()
end
return itemstack
end,
})
minetest.register_node("portalgun:wscspawner2_" .. ii, {
description = "Weighted storage cube spawner2 " ..ptgwsc[ii][3],
tiles = {"steel.png","steel.png","steel.png","steel.png","steel.png",ptgwsc[ii][1]},
groups = {cracky=2,mesecon_receptor_off = 1, mesecon_effector_off = 1},
sounds = glass_sounds,
is_ground_content = false,
paramtype2 = "facedir",
mesecons = {receptor = {state = "off"}, effector = {
action_on = function (pos, node)
local dir=minetest.get_node(pos).param2
local v={x=0, y=0, z=0}
if dir==0 then v.z=-1
elseif dir==1 then v.x=-1.2
elseif dir==2 then v.z=1.2
elseif dir==3 then v.x=1.2
elseif dir==8 then v.y=-1.2
elseif dir==4 then v.y=1.2
end
local pv={x=pos.x+v.x, y=pos.y+v.y, z=pos.z+v.z}
portalgun.new=1
local m=minetest.add_entity(pv, "portalgun:wsc" ..ii)
m:set_acceleration({x=0, y=-10, z=0})
end
}}
})
minetest.register_entity("portalgun:wsc" ..ii,{
hp_max = 100,
physical = true,
weight = 5,
collisionbox = {-0.6,-0.6,-0.6, 0.6,0.6,0.6},
visual = "cube",
visual_size = {x=1.1, y=1.1},
textures = {ptgwsc[ii][1],ptgwsc[ii][1],ptgwsc[ii][1],ptgwsc[ii][1],ptgwsc[ii][1],ptgwsc[ii][1]},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,
makes_footstep_sound = true,
automatic_rotate = 0,
portalgun=2,
wsc=ii,
on_activate= function(self, staticdata)
if portalgun.new==0 then
self.object:remove()
return self
end
portalgun.new=0
end,
on_step= function(self, dtime)
self.timer=self.timer+dtime
if self.timer<1 then return self end
self.timer=0
self.object:set_acceleration({x=0, y=-10, z=0})
self.timer2=self.timer2+1
if self.timer2>4 then
self.timer2=0
for i, ob in pairs(minetest.get_objects_inside_radius(self.object:get_pos(), 20)) do
if ob:is_player() then
return true
end
end
self.object:set_hp(0)
end
end,
timer=0,
timer2=0,
})
minetest.register_node("portalgun:wscspawner"..ii, {
description = "Weighted storage cube spawner " ..ptgwsc[ii][3],
tiles = {ptgwsc[ii][1]},
groups = {cracky = 1, not_in_creative_inventory=0},
paramtype = "light",
paramtype2="facedir",
sunlight_propagates = true,
light_source = 14,
sounds = stone_sounds,
drawtype="nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9},
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(5)
end,
on_timer = function (pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 40)) do
if ob:get_luaentity() and ob:get_luaentity().wsc==ii then
return true
end
end
portalgun.new=1
local m=minetest.add_entity(pos, "portalgun:wsc" ..ii)
m:set_acceleration({x=0,y=-10,z=0})
return true
end,
})
minetest.register_node("portalgun:plantform1_" ..ii, {
description = "Pressure platform " .. ptgwsc[ii][3],
tiles = {ptgwsc[ii][2],"cloud.png","cloud.png","cloud.png","cloud.png","cloud.png"},
groups = {mesecon = 2,cracky = 1, not_in_creative_inventory=0},
mesecons = {receptor = {state = "off"}},
paramtype = "light",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype="nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9},
{-0.5, -0.5, -0.5, 0.5, -0.3125, 0.5},
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(2)
end,
on_timer = function (pos, elapsed)
if not mesecon then return false end
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if ob:get_luaentity() and ob:get_luaentity().wsc==ii then
local node=minetest.get_node(pos)
mesecon.receptor_on(pos)
minetest.set_node(pos, {name ="portalgun:plantform2_"..ii, param1 = node.param1, param2 = node.param2})
end
return true
end
return true
end,
})
minetest.register_node("portalgun:plantform2_"..ii, {
description = "Pressure platform",
tiles = {ptgwsc[ii][2],"cloud.png","cloud.png","cloud.png","cloud.png","cloud.png"},
drop="portalgun:plantform1_"..ii,
groups = {mesecon = 2,cracky = 1, not_in_creative_inventory=1},
mesecons = {receptor = {state = "on"}},
paramtype = "light",
sunlight_propagates = true,
light_source = 14,
sounds = stone_sounds,
drawtype="nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9},
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(2)
end,
on_timer = function (pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if ob:get_luaentity() and ob:get_luaentity().wsc==ii then
return true
end
end
mesecon.receptor_off(pos)
local node=minetest.get_node(pos)
minetest.set_node(pos, {name ="portalgun:plantform1_"..ii, param1 = node.param1, param2 = node.param2})
return true
end,
})
end -- of for #
minetest.register_node("portalgun:plantform_nu1", {
description = "Pressure platform (player or cube)",
tiles = {"portalgun_presplat5.png","cloud.png","cloud.png","cloud.png","cloud.png","cloud.png"},
groups = {mesecon = 2,cracky = 1, not_in_creative_inventory=0},
mesecons = {receptor = {state = "off"}},
paramtype = "light",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype="nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9},
{-0.5, -0.5, -0.5, 0.5, -0.3125, 0.5},
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(2)
end,
on_timer = function (pos, elapsed)
if not mesecon then return false end
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().wsc) then
local node=minetest.get_node(pos)
mesecon.receptor_on(pos)
minetest.set_node(pos, {name ="portalgun:plantform_nu2", param1 = node.param1, param2 = node.param2})
end
return true
end
return true
end,
})
minetest.register_node("portalgun:plantform_nu2", {
description = "Pressure platform",
tiles = {"portalgun_presplat5.png","cloud.png","cloud.png","cloud.png","cloud.png","cloud.png"},
drop="portalgun:plantform_nu1",
groups = {mesecon = 2,cracky = 1, not_in_creative_inventory=1},
mesecons = {receptor = {state = "on"}},
paramtype = "light",
sunlight_propagates = true,
light_source = 14,
sounds = stone_sounds,
drawtype="nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.7, -0.5, -0.7, 0.7, -0.375, 0.7},
{0.7, -0.5, -0.1875, 0.9, -0.4375, 0.1875},
{-0.9, -0.5, -0.1875, -0.7, -0.4375, 0.1875},
{-0.1875, -0.5, -0.9, 0.1875, -0.4375, -0.7},
{-0.1875, -0.5, 0.7, 0.1875, -0.4375, 0.9},
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(2)
end,
on_timer = function (pos, elapsed)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if ob:is_player() or (ob:get_luaentity() and ob:get_luaentity().wsc) then
return true
end
end
mesecon.receptor_off(pos)
local node=minetest.get_node(pos)
minetest.set_node(pos, {name ="portalgun:plantform_nu1", param1 = node.param1, param2 = node.param2})
return true
end,
})
minetest.register_node("portalgun:planthole", {
description = "Plathole (activate by any cube, 2 blocks under)",
tiles = {"cloud.png"},
groups = {mesecon = 2,cracky = 1},
mesecons = {receptor = {state = "off"}},
paramtype = "light",
sunlight_propagates = true,
sounds = stone_sounds,
drawtype="nodebox",
node_box = {
type = "fixed",
fixed = {
{-1.5, -0.5, -1.5, 0.5, -0.25, -1.3},
{-1.5, -0.5, 0.3, 0.5, -0.25, 0.5},
{0.3, -0.5, -1.5, 0.5, -0.25, 0.5},
{-1.5, -0.5, -1.5, -1.3, -0.25, 0.5},
{0.5, -0.5, -0.9, 0.7, -0.375, -0.0625},
{-1.7, -0.5, -0.9, -1.5, -0.3125, -0.0625},
{-0.9, -0.5, -1.7, -0.0625, -0.375, -1.5},
{-1, -0.5, 0.5, -0.0625, -0.375, 0.7},
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(5)
end,
on_timer = function (pos, elapsed)
local pos2={x=pos.x,y=pos.y-2,z=pos.z}
for i, ob in pairs(minetest.get_objects_inside_radius(pos2, 1)) do
if ob:get_luaentity() and ob:get_luaentity().wsc then
mesecon.receptor_on(pos)
return true
end
end
mesecon.receptor_off(pos)
return true
end,
})
minetest.register_node("portalgun:objdestroyer_1", {
description = "Object destroyer (destroys on active)",
tiles = {"portalgun_testblock.png^[colorize:#FF0000aa"},
groups = {cracky = 2,mesecon=1},
sounds = stone_sounds,
mesecons = {effector = {
action_on = function (pos, node)
minetest.set_node(pos, {name ="portalgun:objdestroyer_2"})
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 5)) do
if ob:get_luaentity() then
ob:set_hp(0)
end
end
end
}}
})
minetest.register_node("portalgun:objdestroyer_2", {
description = "Obj destroyer",
tiles = {"portalgun_testblock.png^[colorize:#FF0000cc"},
groups = {cracky=2,mesecon=1,not_in_creative_inventory=1},
sunlight_propagates = true,
drop="portalgun:objdestroyer_1",
paramtype="light",
light_source = 14,
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "portalgun:objdestroyer_1",
}},
})