RealBadAngel
2013-07-17 dfd478b2e8786b98882e09d89139f9eaa9252770
stargate/gate_defs.lua
@@ -6,7 +6,6 @@
   node.param1=0
   node.param2=dir
   minetest.env:set_node(pos,node)
   meta=minetest.env:get_meta(pos)
   meta:from_table(meta0)
end
@@ -139,16 +138,18 @@
   minetest.env:set_node(gateNodes[8].pos,{name="stargate:gatenode1_off", param1=0, param2=dir})
   minetest.env:set_node(gateNodes[9].pos,{name="stargate:gatenode3_off", param1=0, param2=dir})
   local meta = minetest.env:get_meta(gateNodes[1].pos)
   meta:set_string("infotext", "Stargate inactive\nOwned by: "..player_name)
   meta:set_string("infotext", "Stargate\nOwned by: "..player_name)
   meta:set_string("gateNodes",minetest.serialize(gateNodes))
   meta:set_int("gateActive",0)
   meta:set_string("owner",player_name)
   stargate.registerGate(player_name,gateNodes[1].pos)
   meta:set_string("dont_destroy","false")
   stargate.registerGate(player_name,gateNodes[1].pos,dir)
   return true
end
function removeGate (pos)
   local meta = minetest.env:get_meta(pos)
   if meta:get_string("dont_destroy") == "true" then return end
   local player_name=meta:get_string("owner")
   local gateNodes=minetest.deserialize(meta:get_string("gateNodes"))
   for i=2,9,1 do
@@ -157,14 +158,14 @@
   stargate.unregisterGate(player_name,gateNodes[1].pos)
end
function activateGate (player,pos)
function activateGate (pos)
   local node = minetest.env:get_node(pos)
   local dir=node.param2
   local meta = minetest.env:get_meta(pos)
   local gateNodes=minetest.deserialize(meta:get_string("gateNodes"))
   meta:set_int("gateActive",1)
   meta:set_string("infotext", "Stargate active")
   minetest.sound_play("gate_activate", {pos = pos, gain = 1.0,loop = false, max_hear_distance = 72,})
   meta:set_string("dont_destroy","true")
   minetest.sound_play("gateOpen", {pos = pos, gain = 1.0,loop = false, max_hear_distance = 72,})
   swap_gate_node(gateNodes[1].pos,"stargate:gatenode8",dir)
   swap_gate_node(gateNodes[2].pos,"stargate:gatenode7",dir)
   swap_gate_node(gateNodes[3].pos,"stargate:gatenode9",dir)
@@ -174,15 +175,17 @@
   swap_gate_node(gateNodes[7].pos,"stargate:gatenode2",dir)
   swap_gate_node(gateNodes[8].pos,"stargate:gatenode1",dir)
   swap_gate_node(gateNodes[9].pos,"stargate:gatenode3",dir)
   meta:set_string("dont_destroy","false")
end
function deactivateGate (player,pos)
function deactivateGate (pos)
   local node = minetest.env:get_node(pos)
   local dir=node.param2
   local meta = minetest.env:get_meta(pos)
   local gateNodes=minetest.deserialize(meta:get_string("gateNodes"))
   meta:set_int("gateActive",0)
   meta:set_string("infotext", "Stargate inactive")
   meta:set_string("dont_destroy","true")
   minetest.sound_play("gateClose", {pos = pos, gain = 1.0,loop = false, max_hear_distance = 72,})
   swap_gate_node(gateNodes[1].pos,"stargate:gatenode8_off",dir)
   swap_gate_node(gateNodes[2].pos,"stargate:gatenode7_off",dir)
   swap_gate_node(gateNodes[3].pos,"stargate:gatenode9_off",dir)
@@ -192,11 +195,13 @@
   swap_gate_node(gateNodes[7].pos,"stargate:gatenode2_off",dir)
   swap_gate_node(gateNodes[8].pos,"stargate:gatenode1_off",dir)
   swap_gate_node(gateNodes[9].pos,"stargate:gatenode3_off",dir)
   meta:set_string("dont_destroy","false")
end
gateCanDig = function(pos,player)
   local player_name = player:get_player_name()
   local meta = minetest.env:get_meta(pos)
   if meta:get_string("dont_destroy") == "true" then return end
   local owner=meta:get_string("owner")
   if player_name==owner then return true
   else return false end
@@ -330,6 +335,7 @@
   on_destruct = function (pos)
   removeGate(pos)
   end,
   on_rightclick=stargate.gateFormspecHandler,
})
minetest.register_node("stargate:gatenode9",{
@@ -468,3 +474,50 @@
   selection_box = sg_selection_box_empty,
   node_box=sg_node_box,
})
minetest.register_abm({
   nodenames = {"stargate:gatenode8"},
   interval = 1,
   chance = 1,
   action = function(pos, node, active_object_count, active_object_count_wider)
      local meta = minetest.env:get_meta(pos)
      for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
         if object:is_player() then
            local player_name = object:get_player_name()
            local owner=meta:get_string("owner")
            local gate=stargate.findGate (pos)
            if gate==nil then print("Gate is not registered!") return end
            local pos1={}
            pos1.x=gate["destination"].x
            pos1.y=gate["destination"].y
            pos1.z=gate["destination"].z
            local dest_gate=stargate.findGate (pos1)
            if dest_gate==nil then
               gate["destination"]=nil
               deactivateGate(pos)
               stargate.save_data(owner)
               return
            end
            if player_name~=owner and gate["type"]=="private" then return end
            local dir1=gate["destination_dir"]
            local dest_angle
            if dir1 == 0 then
               pos1.z = pos1.z-2
               dest_angle = 180
            elseif dir1 == 1 then
               pos1.x = pos1.x-2
               dest_angle = 90
            elseif dir1 == 2 then
               pos1.z=pos1.z+2
               dest_angle = 0
            elseif dir1 == 3 then
               pos1.x = pos1.x+2
               dest_angle = -90
            end
            object:moveto(pos1,false)
            object:set_look_yaw(math.rad(dest_angle))
            minetest.sound_play("enterEventHorizon", {pos = pos, gain = 1.0,loop = false, max_hear_distance = 72,})
         end
      end
   end
})