mirror of
https://github.com/minetest-mods/technic.git
synced 2024-08-20 13:34:12 +02:00
Update Stargates v1.0
This commit is contained in:
parent
92c9f662ba
commit
1d101ca1e5
@ -138,7 +138,7 @@ function placeGate (player,pos)
|
||||
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)
|
||||
@ -158,13 +158,12 @@ function removeGate (pos)
|
||||
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")
|
||||
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)
|
||||
@ -179,14 +178,13 @@ function activateGate (player,pos)
|
||||
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("dont_destroy","true")
|
||||
meta:set_string("infotext", "Stargate inactive")
|
||||
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)
|
||||
@ -486,13 +484,22 @@ minetest.register_abm({
|
||||
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 gate=stargate.getCurrentGate (player_name,pos)
|
||||
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 dir=minetest.dir_to_facedir(object:get_look_dir())
|
||||
if dir1 == 0 then
|
||||
pos1.z=pos1.z+2
|
||||
elseif dir1 == 1 then
|
||||
@ -502,10 +509,8 @@ minetest.register_abm({
|
||||
elseif dir1 == 3 then
|
||||
pos1.x=pos1.x-2
|
||||
end
|
||||
object:moveto(pos1,true)
|
||||
print(dump(gate["dest"]))
|
||||
object:moveto(pos1,false)
|
||||
minetest.sound_play("enterEventHorizon", {pos = pos, gain = 1.0,loop = false, max_hear_distance = 72,})
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -51,6 +51,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
local new={}
|
||||
new["player_name"]=player_name
|
||||
table.insert(stargate_network["registered_players"],new)
|
||||
stargate_network[player_name]={}
|
||||
stargate.save_data("registered_players")
|
||||
stargate.save_data(player_name)
|
||||
end
|
||||
@ -74,6 +75,7 @@ stargate.registerGate = function(player_name,pos,dir)
|
||||
new_gate["type"]="private"
|
||||
new_gate["description"]=""
|
||||
new_gate["dir"]=dir
|
||||
new_gate["owner"]=player_name
|
||||
table.insert(stargate_network[player_name],new_gate)
|
||||
if stargate.save_data(player_name)==nil then
|
||||
print ("[stargate] Couldnt update network file!")
|
||||
@ -92,12 +94,19 @@ stargate.unregisterGate = function(player_name,pos)
|
||||
end
|
||||
end
|
||||
|
||||
stargate.getCurrentGate = function(player_name,pos)
|
||||
stargate.findGate = function(pos)
|
||||
for __,tab in ipairs(stargate_network["registered_players"]) do
|
||||
local player_name=tab["player_name"]
|
||||
if type(stargate_network[player_name])=="table" then
|
||||
for __,gates in ipairs(stargate_network[player_name]) do
|
||||
if gates then
|
||||
if gates["pos"].x==pos.x and gates["pos"].y==pos.y and gates["pos"].z==pos.z then
|
||||
return gates
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
@ -111,6 +120,8 @@ stargate.gateFormspecHandler = function(pos, node, clicker, itemstack)
|
||||
stargate_network["players"][player_name]["own_gates"]={}
|
||||
stargate_network["players"][player_name]["public_gates"]={}
|
||||
local own_gates_count=0
|
||||
local public_gates_count=0
|
||||
|
||||
for __,gates in ipairs(stargate_network[player_name]) do
|
||||
if gates["pos"].x==pos.x and gates["pos"].y==pos.y and gates["pos"].z==pos.z then
|
||||
current_gate=gates
|
||||
@ -120,6 +131,21 @@ stargate.gateFormspecHandler = function(pos, node, clicker, itemstack)
|
||||
end
|
||||
end
|
||||
stargate_network["players"][player_name]["own_gates_count"]=own_gates_count
|
||||
|
||||
-- get all public gates
|
||||
for __,tab in ipairs(stargate_network["registered_players"]) do
|
||||
local temp=tab["player_name"]
|
||||
if type(stargate_network[temp])=="table" and temp~=player_name then
|
||||
for __,gates in ipairs(stargate_network[temp]) do
|
||||
if gates["type"]=="public" then
|
||||
public_gates_count=public_gates_count+1
|
||||
table.insert(stargate_network["players"][player_name]["public_gates"],gates)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print(dump(stargate_network["players"][player_name]["public_gates"]))
|
||||
if current_gate==nil then
|
||||
print ("Gate not registered in network! Please remove it and place once again.")
|
||||
return nil
|
||||
@ -186,7 +212,9 @@ stargate.get_formspec = function(player_name,page)
|
||||
|
||||
local list_index=stargate_network["players"][player_name]["current_index"]
|
||||
local page=math.floor(list_index / 24 + 1)
|
||||
local pagemax = math.floor((stargate_network["players"][player_name]["own_gates_count"] / 24) + 1)
|
||||
local pagemax
|
||||
if stargate_network["players"][player_name]["dest_type"] == "own" then
|
||||
pagemax = math.floor((stargate_network["players"][player_name]["own_gates_count"] / 24) + 1)
|
||||
local x,y
|
||||
for y=0,7,1 do
|
||||
for x=0,2,1 do
|
||||
@ -199,9 +227,24 @@ stargate.get_formspec = function(player_name,page)
|
||||
list_index=list_index+1
|
||||
end
|
||||
end
|
||||
else
|
||||
pagemax = math.floor((stargate_network["players"][player_name]["public_gates_count"] / 24) + 1)
|
||||
local x,y
|
||||
for y=0,7,1 do
|
||||
for x=0,2,1 do
|
||||
local gate_temp=stargate_network["players"][player_name]["public_gates"][list_index+1]
|
||||
if gate_temp then
|
||||
formspec = formspec.."image_button["..(x*4.5)..","..(2.5+y*.87)..";.6,.6;stargate_icon.png;list_button"..list_index..";]"
|
||||
formspec = formspec.."label["..(x*4.5+.5)..","..(2.3+y*.87)..";("..gate_temp["pos"].x..","..gate_temp["pos"].y..","..gate_temp["pos"].z..") "..gate_temp["owner"].."]"
|
||||
formspec = formspec.."label["..(x*4.5+.5)..","..(2.7+y*.87)..";"..gate_temp["description"].."]"
|
||||
end
|
||||
list_index=list_index+1
|
||||
end
|
||||
end
|
||||
end
|
||||
formspec=formspec.."label[7.5,1.7;Page: "..page.." of "..pagemax.."]"
|
||||
formspec = formspec.."image_button[6.5,1.8;.6,.6;left_icon.png;page_left;]"
|
||||
formspec = formspec.."image_button[6.9,1.8;.6,.6;right_icon.png;page_right;]"
|
||||
formspec=formspec.."label[7.5,1.7;Page: "..page.." of "..pagemax.."]"
|
||||
formspec = formspec.."image_button_exit[6.1,9.3;.8,.8;ok_icon.png;save_changes;]"
|
||||
formspec = formspec.."image_button_exit[7.1,9.3;.8,.8;cancel_icon.png;discard_changes;]"
|
||||
return formspec
|
||||
@ -219,6 +262,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if temp_gate["type"] == "private" then
|
||||
temp_gate["type"] = "public"
|
||||
else temp_gate["type"] = "private" end
|
||||
stargate_network["players"][player_name]["current_index"]=0
|
||||
formspec= stargate.get_formspec(player_name,"main")
|
||||
stargate_network["players"][player_name]["formspec"] = formspec
|
||||
minetest.show_formspec(player_name, "stargate_main", formspec)
|
||||
@ -226,9 +270,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
if fields.toggle_dest_type then
|
||||
if stargate_network["players"][player_name]["dest_type"] == "all own" then
|
||||
if stargate_network["players"][player_name]["dest_type"] == "own" then
|
||||
stargate_network["players"][player_name]["dest_type"] = "all public"
|
||||
else stargate_network["players"][player_name]["dest_type"] = "all own" end
|
||||
else stargate_network["players"][player_name]["dest_type"] = "own" end
|
||||
stargate_network["players"][player_name]["current_index"] = 0
|
||||
formspec = stargate.get_formspec(player_name,"main")
|
||||
stargate_network["players"][player_name]["formspec"] = formspec
|
||||
@ -292,6 +336,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
if fields.save_changes then
|
||||
minetest.sound_play("click", {to_player=player_name, gain = 0.5})
|
||||
local meta = minetest.env:get_meta(temp_gate["pos"])
|
||||
local infotext=""
|
||||
current_gate["type"]=temp_gate["type"]
|
||||
current_gate["description"]=temp_gate["description"]
|
||||
current_gate["pos"]={}
|
||||
@ -310,10 +356,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
current_gate["destination"]=nil
|
||||
end
|
||||
if current_gate["destination"] then
|
||||
activateGate (player,current_gate["pos"])
|
||||
activateGate (current_gate["pos"])
|
||||
else
|
||||
deactivateGate (player,current_gate["pos"])
|
||||
deactivateGate (current_gate["pos"])
|
||||
end
|
||||
if current_gate["type"]=="private" then infotext="Private" else infotext="Public" end
|
||||
infotext=infotext.." Gate: "..current_gate["description"].."\n"
|
||||
infotext=infotext.."Owned by "..player_name.."\n"
|
||||
if current_gate["destination"] then
|
||||
infotext=infotext.."Destination: ("..current_gate["pos"].x..","..current_gate["pos"].y..","..current_gate["pos"].z..") "
|
||||
infotext=infotext..current_gate["destination_description"]
|
||||
end
|
||||
meta:set_string("infotext",infotext)
|
||||
if stargate.save_data(player_name)==nil then
|
||||
print ("[stargate] Couldnt update network file!")
|
||||
end
|
||||
@ -330,7 +384,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if fields[button] then
|
||||
minetest.sound_play("click", {to_player=player_name, gain = 1.0})
|
||||
local gate=stargate_network["players"][player_name]["temp_gate"]
|
||||
local dest_gate=stargate_network["players"][player_name]["own_gates"][list_index+i+1]
|
||||
local dest_gate
|
||||
if stargate_network["players"][player_name]["dest_type"] == "own" then
|
||||
dest_gate=stargate_network["players"][player_name]["own_gates"][list_index+i+1]
|
||||
else
|
||||
dest_gate=stargate_network["players"][player_name]["public_gates"][list_index+i+1]
|
||||
end
|
||||
gate["destination"]={}
|
||||
gate["destination"].x=dest_gate["pos"].x
|
||||
gate["destination"].y=dest_gate["pos"].y
|
||||
|
Loading…
Reference in New Issue
Block a user