stricter luacheck / cleanups

This commit is contained in:
BuckarooBanzay 2021-01-15 08:26:42 +01:00
parent f379075b5a
commit 0a1b7dcf1b
12 changed files with 621 additions and 682 deletions

View File

@ -1,5 +1,3 @@
unused_args = false
globals = {
"travelnet"
}
@ -10,5 +8,5 @@ read_globals = {
"vector",
-- Deps
"creative", "locks", "mesecon",
"creative", "mesecon",
}

View File

@ -61,7 +61,7 @@ travelnet.add_target = function( station_name, network_name, pos, player_name, m
-- lua doesn't allow efficient counting here
local anz = 0;
for k,v in pairs( travelnet.targets[ owner_name ][ network_name ] ) do
for k in pairs( travelnet.targets[ owner_name ][ network_name ] ) do
if( k == station_name ) then
travelnet.show_message( pos, player_name, S("Error"),

View File

@ -74,16 +74,17 @@ end
-- function always return true;
-- if the function returns false, players with the travelnet_attach priv
-- can still add stations to that network
travelnet.allow_attach = function( player_name, owner_name, network_name )
return false;
-- params: player_name, owner_name, network_name
travelnet.allow_attach = function()
return false;
end
-- if this returns true, a player named player_name can remove a travelnet station
-- from network_name (owned by owner_name) even though he is neither the owner nor
-- has the travelnet_remove priv
travelnet.allow_dig = function( player_name, owner_name, network_name, pos )
-- params: player_name, owner_name, network_name, pos
travelnet.allow_dig = function()
return false;
end
@ -94,13 +95,8 @@ end
-- if this function returns true, the player will be transfered to the target station;
-- you can use this code to i.e. charge the player money for the transfer or to limit
-- usage of stations to players in the same fraction on PvP servers
travelnet.allow_travel = function( player_name, owner_name, network_name, station_name_start, station_name_target )
--minetest.chat_send_player( player_name, "Player "..tostring( player_name ).." tries to use station "..
-- tostring( station_name_start )..
-- " on network "..tostring( network_name ).." owned by "..tostring( owner_name ).." in order to travel to "..
-- tostring( station_name_target )..".");
-- params: player_name, owner_name, network_name, station_name_start, station_name_target
travelnet.allow_travel = function()
return true;
end

View File

@ -9,15 +9,15 @@ travelnet.register_door = function( node_base_name, def_tiles, material )
minetest.register_node( node_base_name.."_open", {
description = S("elevator door (open)"),
drawtype = "nodebox",
-- top, bottom, side1, side2, inner, outer
-- top, bottom, side1, side2, inner, outer
tiles = def_tiles,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = true,
-- only the closed variant is in creative inventory
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
-- larger than one node but slightly smaller than a half node so
-- that wallmounted torches pose no problem
-- larger than one node but slightly smaller than a half node so
-- that wallmounted torches pose no problem
node_box = {
type = "fixed",
fixed = {
@ -32,9 +32,9 @@ travelnet.register_door = function( node_base_name, def_tiles, material )
},
},
drop = node_base_name.."_closed",
on_rightclick = function(pos, node, puncher)
minetest.add_node(pos, {name = node_base_name.."_closed", param2 = node.param2})
end,
on_rightclick = function(pos, node)
minetest.add_node(pos, {name = node_base_name.."_closed", param2 = node.param2})
end,
})
minetest.register_node(node_base_name.."_closed", {
@ -59,19 +59,19 @@ travelnet.register_door = function( node_base_name, def_tiles, material )
{-0.5, -0.5, 0.4, 0.5, 1.5, 0.5},
},
},
on_rightclick = function(pos, node, puncher)
minetest.add_node(pos, {name = node_base_name.."_open", param2 = node.param2})
end,
on_rightclick = function(pos, node)
minetest.add_node(pos, {name = node_base_name.."_open", param2 = node.param2})
end,
})
-- add a craft receipe for the door
minetest.register_craft({
output = node_base_name.."_closed",
recipe = {
{material, '', material },
output = node_base_name.."_closed",
recipe = {
{material, '', material },
{material, '', material },
{material, '', material }
}
}
})
@ -95,7 +95,7 @@ end
-- actually register the doors
-- (but only if the materials for them exist)
if(minetest.get_modpath("default")) then
travelnet.register_door( "travelnet:elevator_door_steel", {"default_stone.png"}, "default:steel_ingot");
travelnet.register_door( "travelnet:elevator_door_glass", {"travelnet_elevator_door_glass.png"}, "default:glass");
travelnet.register_door( "travelnet:elevator_door_tin", {"default_clay.png"}, "default:tin_ingot");
travelnet.register_door( "travelnet:elevator_door_steel", {"default_stone.png"}, "default:steel_ingot");
travelnet.register_door( "travelnet:elevator_door_glass", {"travelnet_elevator_door_glass.png"}, "default:glass");
travelnet.register_door( "travelnet:elevator_door_tin", {"default_clay.png"}, "default:tin_ingot");
end

View File

@ -121,78 +121,66 @@ minetest.register_node("travelnet:elevator", {
elevator = 1
},
light_source = 10,
light_source = 10,
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos);
meta:set_string("infotext", S("Elevator (unconfigured)"));
meta:set_string("station_name", "");
meta:set_string("station_network","");
meta:set_string("owner", placer:get_player_name() );
-- request initial data
meta:set_string("formspec",
"size[12,10]"..
"field[0.3,5.6;6,0.7;station_name;"..S("Name of this station:")..";]"..
-- "field[0.3,6.6;6,0.7;station_network;Assign to Network:;]"..
-- "field[0.3,7.6;6,0.7;owner_name;(optional) owned by:;]"..
"button_exit[6.3,6.2;1.7,0.7;station_set;"..S("Store").."]" );
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos);
meta:set_string("infotext", S("Elevator (unconfigured)"));
meta:set_string("station_name", "");
meta:set_string("station_network","");
meta:set_string("owner", placer:get_player_name() );
-- request initial data
meta:set_string("formspec",
"size[12,10]"..
"field[0.3,5.6;6,0.7;station_name;"..S("Name of this station:")..";]"..
"button_exit[6.3,6.2;1.7,0.7;station_set;"..S("Store").."]"
);
local top_pos = {x=pos.x, y=pos.y+1, z=pos.z}
minetest.set_node(top_pos, {name="travelnet:hidden_top"})
travelnet.show_nearest_elevator( pos, placer:get_player_name(), minetest.dir_to_facedir(placer:get_look_dir()));
end,
local top_pos = {x=pos.x, y=pos.y+1, z=pos.z}
minetest.set_node(top_pos, {name="travelnet:hidden_top"})
travelnet.show_nearest_elevator( pos, placer:get_player_name(), minetest.dir_to_facedir(placer:get_look_dir()));
end,
on_receive_fields = travelnet.on_receive_fields,
on_punch = function(pos, node, puncher)
travelnet.update_formspec(pos, puncher:get_player_name())
end,
on_receive_fields = travelnet.on_receive_fields,
on_punch = function(pos, _, puncher)
travelnet.update_formspec(pos, puncher:get_player_name())
end,
can_dig = function( pos, player )
return travelnet.can_dig( pos, player, 'elevator' )
end,
can_dig = function( pos, player )
return travelnet.can_dig( pos, player, 'elevator' )
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
travelnet.remove_box( pos, oldnode, oldmetadata, digger )
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
travelnet.remove_box( pos, oldnode, oldmetadata, digger )
end,
-- TNT and overenthusiastic DMs do not destroy elevators either
on_blast = function(pos, intensity)
end,
-- TNT and overenthusiastic DMs do not destroy elevators either
on_blast = function()
end,
-- taken from VanessaEs homedecor fridge
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above;
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z});
local def = minetest.registered_nodes[node.name]
-- leftover top nodes can be removed by placing a new elevator underneath
if (not def or not def.buildable_to) and node.name ~= "travelnet:hidden_top" then
minetest.chat_send_player(
placer:get_player_name(),
S('Not enough vertical space to place the travelnet box!')
)
return;
end
return minetest.item_place(itemstack, placer, pointed_thing);
end,
-- taken from VanessaEs homedecor fridge
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above;
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z});
local def = minetest.registered_nodes[node.name]
-- leftover top nodes can be removed by placing a new elevator underneath
if (not def or not def.buildable_to) and node.name ~= "travelnet:hidden_top" then
minetest.chat_send_player(
placer:get_player_name(),
S('Not enough vertical space to place the travelnet box!')
)
return;
end
return minetest.item_place(itemstack, placer, pointed_thing);
end,
on_destruct = function(pos)
pos = {x=pos.x, y=pos.y+1, z=pos.z}
minetest.remove_node(pos)
end
on_destruct = function(pos)
pos = {x=pos.x, y=pos.y+1, z=pos.z}
minetest.remove_node(pos)
end
})
--if( minetest.get_modpath("technic") ~= nil ) then
-- minetest.register_craft({
-- output = "travelnet:elevator",
-- recipe = {
-- {"default:steel_ingot", "technic:motor", "default:steel_ingot", },
-- {"default:steel_ingot", "technic:control_logic_unit", "default:steel_ingot", },
-- {"default:steel_ingot", "moreores:copper_ingot", "default:steel_ingot", }
-- }
-- })
--else
minetest.register_craft({
output = "travelnet:elevator",
recipe = travelnet.elevator_recipe,
})
--end
minetest.register_craft({
output = "travelnet:elevator",
recipe = travelnet.elevator_recipe,
})

View File

@ -36,9 +36,6 @@ travelnet.form_input_handler = function( player, formname, fields)
return
end
if( locks and (fields.locks_config or fields.locks_authorize)) then
return locks:lock_handle_input( pos, formname, fields, player )
end
-- back button leads back to the main menu
if( fields.back and fields.back ~= "" ) then
return travelnet.show_current_formspec( pos,
@ -80,7 +77,6 @@ travelnet.reset_formspec = function( meta )
"label[0.3,3.1;"..S("You can have more than one network. If unsure, use \"@1\"", tostring(station_network)) .. ".]"..
"field[0.3,4.4;9,0.9;owner;"..S("Owned by:")..";]"..
"label[0.3,4.7;"..S("Unless you know what you are doing, leave this empty.").."]"..
"button_exit[1.3,5.3;1.7,0.7;station_help_setup;"..S("Help").."]"..
"button_exit[3.8,5.3;1.7,0.7;station_set;"..S("Save").."]"..
"button_exit[6.3,5.3;1.7,0.7;station_exit;"..S("Exit").."]");
end

View File

@ -4,23 +4,17 @@ local S = minetest.get_translator("travelnet")
-- however, that would be very annoying when actually trying to dig the thing.
-- Thus, check if the player is wielding a tool that can dig nodes of the
-- group cracky
travelnet.check_if_trying_to_dig = function( puncher, node )
travelnet.check_if_trying_to_dig = function(puncher)
-- if in doubt: show formspec
if( not( puncher) or not( puncher:get_wielded_item())) then
if not puncher or not puncher:get_wielded_item() then
return false;
end
-- show menu when in creative mode
if( creative
and creative.is_enabled_for(puncher:get_player_name())
-- and (not(puncher:get_wielded_item())
-- or puncher:get_wielded_item():get_name()~="default:pick_diamond")) then
) then
if creative and creative.is_enabled_for(puncher:get_player_name()) then
return false;
end
local tool_capabilities = puncher:get_wielded_item():get_tool_capabilities();
if( not( tool_capabilities )
or not( tool_capabilities["groupcaps"])
or not( tool_capabilities["groupcaps"]["cracky"])) then
if not tool_capabilities or not tool_capabilities["groupcaps"] or not tool_capabilities["groupcaps"]["cracky"] then
return false;
end
-- tools which can dig cracky items can start digging immediately
@ -30,140 +24,136 @@ end
-- allow doors to open
travelnet.open_close_door = function( pos, player, mode )
local this_node = minetest.get_node_or_nil( pos );
-- give up if the area is *still* not loaded
if not this_node then
return
end
local pos2 = {x=pos.x,y=pos.y,z=pos.z};
local this_node = minetest.get_node_or_nil( pos );
-- give up if the area is *still* not loaded
if( this_node == nil ) then
return
end
local pos2 = {x=pos.x,y=pos.y,z=pos.z};
if( this_node.param2 == 0 ) then pos2 = {x=pos.x,y=pos.y,z=(pos.z-1)};
elseif( this_node.param2 == 1 ) then pos2 = {x=(pos.x-1),y=pos.y,z=pos.z};
elseif( this_node.param2 == 2 ) then pos2 = {x=pos.x,y=pos.y,z=(pos.z+1)};
elseif( this_node.param2 == 3 ) then pos2 = {x=(pos.x+1),y=pos.y,z=pos.z};
end
if( this_node.param2 == 0 ) then pos2 = {x=pos.x,y=pos.y,z=(pos.z-1)};
elseif( this_node.param2 == 1 ) then pos2 = {x=(pos.x-1),y=pos.y,z=pos.z};
elseif( this_node.param2 == 2 ) then pos2 = {x=pos.x,y=pos.y,z=(pos.z+1)};
elseif( this_node.param2 == 3 ) then pos2 = {x=(pos.x+1),y=pos.y,z=pos.z};
end
local door_node = minetest.get_node( pos2 );
if door_node ~= nil and
door_node.name ~= 'ignore' and
door_node.name ~= 'air' and
minetest.registered_nodes[ door_node.name ] ~= nil and
local door_node = minetest.get_node(pos2);
if not door_node and door_node.name ~= 'ignore' and door_node.name ~= 'air' and
minetest.registered_nodes[ door_node.name ] ~= nil and
minetest.registered_nodes[ door_node.name ].on_rightclick ~= nil then
-- at least for homedecor, same facedir would mean "door closed"
-- at least for homedecor, same facedir would mean "door closed"
-- do not close the elevator door if it is already closed
if (mode==1 and ( string.sub( door_node.name, -7 ) == '_closed'
-- handle doors that change their facedir
or ( door_node.param2 == ((this_node.param2 + 2)%4)
and door_node.name ~= 'travelnet:elevator_door_glass_open'
and door_node.name ~= 'travelnet:elevator_door_tin_open'
and door_node.name ~= 'travelnet:elevator_door_steel_open'))) then
return;
end
-- do not close the elevator door if it is already closed
if( mode==1 and ( string.sub( door_node.name, -7 ) == '_closed'
-- handle doors that change their facedir
or ( door_node.param2 == ((this_node.param2 + 2)%4)
and door_node.name ~= 'travelnet:elevator_door_glass_open'
and door_node.name ~= 'travelnet:elevator_door_tin_open'
and door_node.name ~= 'travelnet:elevator_door_steel_open'))) then
return;
end
-- do not open the doors if they are already open (works only on elevator-doors; not on doors in general)
if( mode==2 and ( string.sub( door_node.name, -5 ) == '_open'
-- handle doors that change their facedir
or ( door_node.param2 ~= ((this_node.param2 + 2)%4)
and door_node.name ~= 'travelnet:elevator_door_glass_closed'
and door_node.name ~= 'travelnet:elevator_door_tin_closed'
and door_node.name ~= 'travelnet:elevator_door_steel_closed'))) then
return;
end
-- do not open the doors if they are already open (works only on elevator-doors; not on doors in general)
if( mode==2 and ( string.sub( door_node.name, -5 ) == '_open'
-- handle doors that change their facedir
or ( door_node.param2 ~= ((this_node.param2 + 2)%4)
and door_node.name ~= 'travelnet:elevator_door_glass_closed'
and door_node.name ~= 'travelnet:elevator_door_tin_closed'
and door_node.name ~= 'travelnet:elevator_door_steel_closed'))) then
return;
end
if( mode==2 ) then
minetest.after( 1, minetest.registered_nodes[ door_node.name ].on_rightclick, pos2, door_node, player );
else
minetest.registered_nodes[ door_node.name ].on_rightclick(pos2, door_node, player);
end
end
if mode == 2 then
minetest.after( 1, minetest.registered_nodes[ door_node.name ].on_rightclick, pos2, door_node, player );
else
minetest.registered_nodes[ door_node.name ].on_rightclick(pos2, door_node, player);
end
end
end
travelnet.rotate_player = function( target_pos, player, tries )
-- try later when the box is loaded
local node2 = minetest.get_node_or_nil( target_pos );
if( node2 == nil ) then
if( tries < 30 ) then
minetest.after( 0, travelnet.rotate_player, target_pos, player, tries+1 )
end
return
end
-- try later when the box is loaded
local node2 = minetest.get_node_or_nil( target_pos );
if node2 == nil then
if tries < 30 then
minetest.after( 0, travelnet.rotate_player, target_pos, player, tries+1 )
end
return
end
-- play sound at the target position as well
if( travelnet.travelnet_sound_enabled ) then
if ( node2.name == 'travelnet:elevator' ) then
minetest.sound_play("travelnet_bell", {pos = target_pos, gain = 0.75, max_hear_distance = 10,});
else
minetest.sound_play("travelnet_travel", {pos = target_pos, gain = 0.75, max_hear_distance = 10,});
end
end
-- play sound at the target position as well
if( travelnet.travelnet_sound_enabled ) then
if ( node2.name == 'travelnet:elevator' ) then
minetest.sound_play("travelnet_bell", {pos = target_pos, gain = 0.75, max_hear_distance = 10,});
else
minetest.sound_play("travelnet_travel", {pos = target_pos, gain = 0.75, max_hear_distance = 10,});
end
end
-- do this only on servers where the function exists
if( player.set_look_horizontal ) then
-- rotate the player so that he/she can walk straight out of the box
local yaw = 0;
local param2 = node2.param2;
if( param2==0 ) then
yaw = 180;
elseif( param2==1 ) then
yaw = 90;
elseif( param2==2 ) then
yaw = 0;
elseif( param2==3 ) then
yaw = 270;
end
-- do this only on servers where the function exists
if player.set_look_horizontal then
-- rotate the player so that he/she can walk straight out of the box
local yaw = 0;
local param2 = node2.param2;
if( param2==0 ) then
yaw = 180;
elseif param2==1 then
yaw = 90;
elseif param2==2 then
yaw = 0;
elseif param2==3 then
yaw = 270;
end
player:set_look_horizontal( math.rad( yaw ));
player:set_look_vertical( math.rad( 0 ));
end
player:set_look_horizontal( math.rad( yaw ));
player:set_look_vertical( math.rad( 0 ));
end
travelnet.open_close_door( target_pos, player, 2 );
travelnet.open_close_door( target_pos, player, 2 );
end
travelnet.remove_box = function( pos, oldnode, oldmetadata, digger )
if( not( oldmetadata ) or oldmetadata=="nil" or not(oldmetadata.fields)) then
minetest.chat_send_player( digger:get_player_name(), S("Error")..": "..
travelnet.remove_box = function(_, _, oldmetadata, digger )
if not oldmetadata or oldmetadata=="nil" or not oldmetadata.fields then
minetest.chat_send_player( digger:get_player_name(), S("Error")..": "..
S("Could not find information about the station that is to be removed."));
return;
end
return;
end
local owner_name = oldmetadata.fields[ "owner" ];
local station_name = oldmetadata.fields[ "station_name" ];
local station_network = oldmetadata.fields[ "station_network" ];
local owner_name = oldmetadata.fields[ "owner" ];
local station_name = oldmetadata.fields[ "station_name" ];
local station_network = oldmetadata.fields[ "station_network" ];
-- station is not known? then just remove it
if( not( owner_name )
or not( station_name )
or not( station_network )
or not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )) then
-- station is not known? then just remove it
if( not( owner_name )
or not( station_name )
or not( station_network )
or not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )) then
minetest.chat_send_player( digger:get_player_name(), S("Error")..": "..
minetest.chat_send_player( digger:get_player_name(), S("Error")..": "..
S("Could not find the station that is to be removed."));
return;
end
return;
end
travelnet.targets[ owner_name ][ station_network ][ station_name ] = nil;
travelnet.targets[ owner_name ][ station_network ][ station_name ] = nil;
-- inform the owner
minetest.chat_send_player( owner_name, S("Station '@1'" .." "..
"has been REMOVED from the network '@2'.", station_name, station_network));
if( digger ~= nil and owner_name ~= digger:get_player_name() ) then
minetest.chat_send_player( digger:get_player_name(), S("Station '@1'" .." "..
"has been REMOVED from the network '@2'.", station_name, station_network));
end
-- inform the owner
minetest.chat_send_player( owner_name, S("Station '@1'" .." "..
"has been REMOVED from the network '@2'.", station_name, station_network));
if digger ~= nil and owner_name ~= digger:get_player_name() then
minetest.chat_send_player( digger:get_player_name(), S("Station '@1'" .." "..
"has been REMOVED from the network '@2'.", station_name, station_network));
end
-- save the updated network data in a savefile over server restart
travelnet.save_data();
-- save the updated network data in a savefile over server restart
travelnet.save_data();
end
travelnet.can_dig = function( pos, player, description )
-- forbid digging of the travelnet
return false;
travelnet.can_dig = function()
-- forbid digging of the travelnet
return false;
end

View File

@ -80,55 +80,52 @@ minetest.register_node("travelnet:hidden_top", {
if( travelnet.travelnet_effect_enabled ) then
minetest.register_entity( 'travelnet:effect', {
minetest.register_entity( 'travelnet:effect', {
hp_max = 1,
physical = false,
weight = 5,
collisionbox = {-0.4,-0.5,-0.4, 0.4,1.5,0.4},
visual = "upright_sprite",
visual_size = {x=1, y=2},
textures = { "travelnet_flash.png" }, -- number of required textures depends on visual
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = true,
hp_max = 1,
physical = false,
weight = 5,
collisionbox = {-0.4,-0.5,-0.4, 0.4,1.5,0.4},
visual = "upright_sprite",
visual_size = {x=1, y=2},
-- mesh = "model",
textures = { "travelnet_flash.png" }, -- number of required textures depends on visual
-- colors = {}, -- number of required colors depends on visual
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = true,
anz_rotations = 0,
anz_rotations = 0,
on_step = function( self, dtime )
-- this is supposed to be more flickering than smooth animation
self.object:set_yaw( self.object:get_yaw()+1);
self.anz_rotations = self.anz_rotations + 1;
-- eventually self-destruct
if( self.anz_rotations > 15 ) then
self.object:remove();
end
end
})
on_step = function(self)
-- this is supposed to be more flickering than smooth animation
self.object:set_yaw( self.object:get_yaw()+1);
self.anz_rotations = self.anz_rotations + 1;
-- eventually self-destruct
if self.anz_rotations > 15 then
self.object:remove();
end
end
})
end
if( travelnet.travelnet_enabled ) then
-- register-functions for travelnet nodes
dofile(travelnet.path.."/register_travelnet.lua");
-- default travelnet registrations
dofile(travelnet.path.."/travelnet.lua");
-- register-functions for travelnet nodes
dofile(travelnet.path.."/register_travelnet.lua");
-- default travelnet registrations
dofile(travelnet.path.."/travelnet.lua");
end
if( travelnet.elevator_enabled ) then
dofile(travelnet.path.."/elevator.lua"); -- allows up/down transfers only
dofile(travelnet.path.."/elevator.lua"); -- allows up/down transfers only
end
if( travelnet.doors_enabled ) then
-- doors that open and close automaticly when the travelnet or elevator is used
dofile(travelnet.path.."/doors.lua");
dofile(travelnet.path.."/doors.lua");
end
if( travelnet.enable_abm ) then
-- restore travelnet data when players pass by broken networks
dofile(travelnet.path.."/restore_network_via_abm.lua");
dofile(travelnet.path.."/restore_network_via_abm.lua");
end
-- upon server start, read the savefile

View File

@ -1,207 +1,193 @@
local S = minetest.get_translator("travelnet")
travelnet.on_receive_fields = function(pos, formname, fields, player)
if( not( pos )) then
return;
end
local meta = minetest.get_meta(pos);
travelnet.on_receive_fields = function(pos, _, fields, player)
if not pos then
return;
end
local name = player:get_player_name();
local meta = minetest.get_meta(pos);
local name = player:get_player_name();
-- the player wants to quit/exit the formspec; do not save/update anything
if( fields and fields.station_exit and fields.station_exit ~= "" ) then
return;
end
-- the player wants to quit/exit the formspec; do not save/update anything
if fields and fields.station_exit and fields.station_exit ~= "" then
return
end
-- show special locks buttons if needed
if( locks and (fields.locks_config or fields.locks_authorize)) then
return locks:lock_handle_input( pos, formname, fields, player )
end
-- the player wants to remove the station
if fields.station_dig then
local owner = meta:get_string( "owner" );
local network_name = meta:get_string("station_network")
local node = minetest.get_node(pos)
local description
-- show help text
if( fields and fields.station_help_setup and fields.station_help_setup ~= "") then
-- simulate right-click
local node = minetest.get_node( pos );
if( node and node.name and minetest.registered_nodes[ node.name ] ) then
travelnet.show_message( pos, name, S("--> Help <--"),
-- TODO: actually add help page
S("No help available yet."));
end
return;
end
if node and minetest.get_item_group(node.name, "travelnet") == 1 then
description = "travelnet box"
elseif node and minetest.get_item_group(node.name, "elevator") == 1 then
description = "elevator"
elseif node and node.name == "locked_travelnet:travelnet" then
description = "locked travelnet"
elseif node and node.name == "locked_travelnet:elevator" then
description = "locked elevator"
else
minetest.chat_send_player(name, "Error: Unknown node.");
return
end
-- the player wants to remove the station
if( fields.station_dig ) then
local owner = meta:get_string( "owner" );
local network_name = meta:get_string("station_network")
local node = minetest.get_node(pos)
local description
if node and minetest.get_item_group(node.name, "travelnet") == 1 then
description = "travelnet box"
elseif node and minetest.get_item_group(node.name, "elevator") == 1 then
description = "elevator"
elseif node and node.name == "locked_travelnet:travelnet" then
description = "locked travelnet"
elseif node and node.name == "locked_travelnet:elevator" then
description = "locked elevator"
else
minetest.chat_send_player(name, "Error: Unknown node.");
return
end
-- players with travelnet_remove priv can dig the station
if( not(minetest.check_player_privs(name, {travelnet_remove=true}))
-- the function travelnet.allow_dig(..) may allow additional digging
and not(travelnet.allow_dig( name, owner, network_name, pos ))
-- the owner can remove the station
and owner ~= name
-- stations without owner can be removed by anybody
and owner ~= "") then
minetest.chat_send_player(name,
S("This %s belongs to %s. You can't remove it."):format(
-- players with travelnet_remove priv can dig the station
if( not(minetest.check_player_privs(name, {travelnet_remove=true}))
-- the function travelnet.allow_dig(..) may allow additional digging
and not(travelnet.allow_dig( name, owner, network_name, pos ))
-- the owner can remove the station
and owner ~= name
-- stations without owner can be removed by anybody
and owner ~= "") then
minetest.chat_send_player(name,
S("This %s belongs to %s. You can't remove it."):format(
description,
tostring( meta:get_string('owner'))
)
);
return
end
return
end
-- abort if protected by another mod
if( minetest.is_protected(pos, name)
and not(minetest.check_player_privs(name, {protection_bypass=true})) ) then
minetest.record_protection_violation(pos, name)
return
end
-- abort if protected by another mod
if( minetest.is_protected(pos, name)
and not(minetest.check_player_privs(name, {protection_bypass=true})) ) then
minetest.record_protection_violation(pos, name)
return
end
local pinv = player:get_inventory()
if(not(pinv:room_for_item("main", node.name))) then
minetest.chat_send_player(name, S("You do not have enough room in your inventory."));
return
end
local pinv = player:get_inventory()
if not pinv:room_for_item("main", node.name) then
minetest.chat_send_player(name, S("You do not have enough room in your inventory."));
return
end
-- give the player the box
pinv:add_item("main", node.name)
-- remove the box from the data structure
travelnet.remove_box( pos, nil, meta:to_table(), player );
-- remove the node as such
minetest.remove_node(pos)
return;
end
-- give the player the box
pinv:add_item("main", node.name)
-- remove the box from the data structure
travelnet.remove_box( pos, nil, meta:to_table(), player );
-- remove the node as such
minetest.remove_node(pos)
return;
end
-- if the box has not been configured yet
if( meta:get_string("station_network")=="" ) then
-- if the box has not been configured yet
if( meta:get_string("station_network")=="" ) then
travelnet.add_target( fields.station_name, fields.station_network, pos, name, meta, fields.owner );
return;
end
travelnet.add_target( fields.station_name, fields.station_network, pos, name, meta, fields.owner );
return;
end
if( fields.open_door ) then
travelnet.open_close_door( pos, player, 0 );
return;
end
if( fields.open_door ) then
travelnet.open_close_door( pos, player, 0 );
return;
end
-- the owner or players with the travelnet_attach priv can move stations up or down in the list
if( fields.move_up or fields.move_down) then
travelnet.update_formspec( pos, name, fields );
return;
end
-- the owner or players with the travelnet_attach priv can move stations up or down in the list
if( fields.move_up or fields.move_down) then
travelnet.update_formspec( pos, name, fields );
return;
end
if( not( fields.target )) then
minetest.chat_send_player(name, S("Please click on the target you want to travel to."));
return;
end
if( not( fields.target )) then
minetest.chat_send_player(name, S("Please click on the target you want to travel to."));
return;
end
-- if there is something wrong with the data
local owner_name = meta:get_string( "owner" );
local station_name = meta:get_string( "station_name" );
local station_network = meta:get_string( "station_network" );
-- if there is something wrong with the data
local owner_name = meta:get_string( "owner" );
local station_name = meta:get_string( "station_name" );
local station_network = meta:get_string( "station_network" );
if( not( owner_name )
or not( station_name )
or not( station_network )
or not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )) then
if( not( owner_name )
or not( station_name )
or not( station_network )
or not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )) then
if owner_name
and station_name
and station_network then
travelnet.add_target( station_name, station_network, pos, owner_name, meta, owner_name );
else
minetest.chat_send_player(name, S("Error")..": "..
S("There is something wrong with the configuration of this station.")..
" DEBUG DATA: owner: "..( owner_name or "?")..
" station_name: "..(station_name or "?")..
" station_network: "..(station_network or "?").."."
);
return
end
end
if( owner_name
and station_name
and station_network ) then
travelnet.add_target( station_name, station_network, pos, owner_name, meta, owner_name );
else
minetest.chat_send_player(name, S("Error")..": "..
S("There is something wrong with the configuration of this station.")..
" DEBUG DATA: owner: "..( owner_name or "?")..
" station_name: "..(station_name or "?")..
" station_network: "..(station_network or "?")..".");
return
end
end
if( not( owner_name )
or not( station_network )
or not( travelnet.targets )
or not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )) then
minetest.chat_send_player(name, S("Error")..": "..
if( not( owner_name )
or not( station_network )
or not( travelnet.targets )
or not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )) then
minetest.chat_send_player(name, S("Error")..": "..
S("This travelnet is lacking data and/or improperly configured."));
print( "ERROR: The travelnet at "..minetest.pos_to_string( pos ).." has a problem: "..
" DATA: owner: "..( owner_name or "?")..
" station_name: "..(station_name or "?")..
" station_network: "..(station_network or "?")..".");
return;
end
print( "ERROR: The travelnet at "..minetest.pos_to_string( pos ).." has a problem: "..
" DATA: owner: "..( owner_name or "?")..
" station_name: "..(station_name or "?")..
" station_network: "..(station_network or "?").."."
);
return;
end
local this_node = minetest.get_node( pos );
if( this_node ~= nil and this_node.name == 'travelnet:elevator' ) then
for k,v in pairs( travelnet.targets[ owner_name ][ station_network ] ) do
if( travelnet.targets[ owner_name ][ station_network ][ k ].nr
== fields.target) then
fields.target = k;
end
end
end
local this_node = minetest.get_node( pos );
if this_node ~= nil and this_node.name == 'travelnet:elevator' then
for k,_ in pairs( travelnet.targets[ owner_name ][ station_network ] ) do
if( travelnet.targets[ owner_name ][ station_network ][ k ].nr
== fields.target) then
fields.target = k;
end
end
end
-- if the target station is gone
if( not( travelnet.targets[ owner_name ][ station_network ][ fields.target ] )) then
minetest.chat_send_player(name, S("Station '@1' does not exist (anymore?)" ..
" " .. "on this network.", fields.target or "?"));
travelnet.update_formspec( pos, name, nil );
return;
end
-- if the target station is gone
if not travelnet.targets[ owner_name ][ station_network ][ fields.target ] then
minetest.chat_send_player(name, S("Station '@1' does not exist (anymore?)" ..
" " .. "on this network.", fields.target or "?")
);
travelnet.update_formspec( pos, name, nil );
return;
end
if( not( travelnet.allow_travel( name, owner_name, station_network, station_name, fields.target ))) then
return;
end
minetest.chat_send_player(name, S("Initiating transfer to station '@1'.", fields.target or "?"));
if( not( travelnet.allow_travel( name, owner_name, station_network, station_name, fields.target ))) then
return;
end
minetest.chat_send_player(name, S("Initiating transfer to station '@1'.", fields.target or "?"));
if( travelnet.travelnet_sound_enabled ) then
if ( this_node.name == 'travelnet:elevator' ) then
minetest.sound_play("travelnet_bell", {pos = pos, gain = 0.75, max_hear_distance = 10,});
else
minetest.sound_play("travelnet_travel", {pos = pos, gain = 0.75, max_hear_distance = 10,});
end
end
if( travelnet.travelnet_effect_enabled ) then
minetest.add_entity( {x=pos.x,y=pos.y+0.5,z=pos.z}, "travelnet:effect"); -- it self-destructs after 20 turns
end
if travelnet.travelnet_sound_enabled then
if this_node.name == 'travelnet:elevator' then
minetest.sound_play("travelnet_bell", {pos = pos, gain = 0.75, max_hear_distance = 10,});
else
minetest.sound_play("travelnet_travel", {pos = pos, gain = 0.75, max_hear_distance = 10,});
end
end
-- close the doors at the sending station
travelnet.open_close_door( pos, player, 1 );
if travelnet.travelnet_effect_enabled then
minetest.add_entity( {x=pos.x,y=pos.y+0.5,z=pos.z}, "travelnet:effect"); -- it self-destructs after 20 turns
end
-- transport the player to the target location
-- close the doors at the sending station
travelnet.open_close_door( pos, player, 1 );
-- may be 0.0 for some versions of MT 5 player model
local player_model_bottom = tonumber(minetest.settings:get("player_model_bottom")) or -.5;
local player_model_vec = vector.new(0, player_model_bottom, 0);
local target_pos = travelnet.targets[ owner_name ][ station_network ][ fields.target ].pos;
-- transport the player to the target location
-- may be 0.0 for some versions of MT 5 player model
local player_model_bottom = tonumber(minetest.settings:get("player_model_bottom")) or -.5;
local player_model_vec = vector.new(0, player_model_bottom, 0);
local target_pos = travelnet.targets[ owner_name ][ station_network ][ fields.target ].pos;
local top_pos = {x=pos.x, y=pos.y+1, z=pos.z}
local top_node = minetest.get_node(top_pos)
@ -212,31 +198,29 @@ travelnet.on_receive_fields = function(pos, formname, fields, player)
end
end
player:move_to( vector.add(target_pos, player_model_vec), false);
player:move_to( vector.add(target_pos, player_model_vec), false);
if( travelnet.enable_travelnet_effect ) then
-- it self-destructs after 20 turns
minetest.add_entity( {x=target_pos.x,y=target_pos.y+0.5,z=target_pos.z}, "travelnet:effect");
end
-- check if the box has at the other end has been removed.
local node2 = minetest.get_node_or_nil(target_pos);
if node2 ~= nil then
local node2_def = minetest.registered_nodes[node2.name]
local has_travelnet_group = node2_def.groups.travelnet or node2_def.groups.elevator
if not has_travelnet_group then
-- provide information necessary to identify the removed box
local oldmetadata = {
fields = {
owner = owner_name,
station_name = fields.target,
station_network = station_network
}
}
-- check if the box has at the other end has been removed.
local node2 = minetest.get_node_or_nil(target_pos);
if node2 ~= nil then
local node2_def = minetest.registered_nodes[node2.name]
local has_travelnet_group = node2_def.groups.travelnet or node2_def.groups.elevator
if not has_travelnet_group then
-- provide information necessary to identify the removed box
local oldmetadata = { fields = { owner = owner_name,
station_name = fields.target,
station_network = station_network }};
travelnet.remove_box( target_pos, nil, oldmetadata, player );
-- send the player back as there's no receiving travelnet
player:move_to( pos, false );
else
travelnet.rotate_player( target_pos, player, 0 )
end
end
travelnet.remove_box( target_pos, nil, oldmetadata, player );
-- send the player back as there's no receiving travelnet
player:move_to( pos, false );
else
travelnet.rotate_player( target_pos, player, 0 )
end
end
end

View File

@ -49,8 +49,8 @@ function travelnet.register_travelnet_box(cfg)
groups = {
travelnet = 1
},
light_source = cfg.light_source or 10,
after_place_node = function(pos, placer, itemstack)
light_source = cfg.light_source or 10,
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos);
travelnet.reset_formspec( meta );
meta:set_string("owner", placer:get_player_name());
@ -58,45 +58,43 @@ function travelnet.register_travelnet_box(cfg)
minetest.set_node(top_pos, {name="travelnet:hidden_top"})
end,
on_receive_fields = travelnet.on_receive_fields,
on_punch = function(pos, node, puncher)
on_receive_fields = travelnet.on_receive_fields,
on_punch = function(pos, _, puncher)
travelnet.update_formspec(pos, puncher:get_player_name(), nil)
end,
end,
can_dig = function( pos, player )
return travelnet.can_dig( pos, player, 'travelnet box' )
end,
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
after_dig_node = function(pos, oldnode, oldmetadata, digger)
travelnet.remove_box( pos, oldnode, oldmetadata, digger )
end,
end,
-- TNT and overenthusiastic DMs do not destroy travelnets
on_blast = function(pos, intensity)
end,
-- TNT and overenthusiastic DMs do not destroy travelnets
on_blast = function() end,
-- taken from VanessaEs homedecor fridge
on_place = function(itemstack, placer, pointed_thing)
-- taken from VanessaEs homedecor fridge
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above;
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
local def = minetest.registered_nodes[node.name]
-- leftover top nodes can be removed by placing a new travelnet underneath
if (not def or not def.buildable_to) and node.name ~= "travelnet:hidden_top" then
minetest.chat_send_player(
placer:get_player_name(),
S('Not enough vertical space to place the travelnet box!')
)
return;
end
return minetest.item_place(itemstack, placer, pointed_thing);
end,
local pos = pointed_thing.above;
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
local def = minetest.registered_nodes[node.name]
-- leftover top nodes can be removed by placing a new travelnet underneath
if (not def or not def.buildable_to) and node.name ~= "travelnet:hidden_top" then
minetest.chat_send_player(
placer:get_player_name(),
S('Not enough vertical space to place the travelnet box!')
)
return;
end
return minetest.item_place(itemstack, placer, pointed_thing);
end,
on_destruct = function(pos)
pos = {x=pos.x, y=pos.y+1, z=pos.z}
minetest.remove_node(pos)
end
pos = {x=pos.x, y=pos.y+1, z=pos.z}
minetest.remove_node(pos)
end
})
if cfg.recipe then

View File

@ -1,24 +1,23 @@
minetest.register_abm({
nodenames = {"travelnet:travelnet"},
interval = 20,
chance = 1,
action = function(pos, node)
nodenames = {"travelnet:travelnet"},
interval = 20,
chance = 1,
action = function(pos)
local meta = minetest.get_meta( pos );
local owner_name = meta:get_string( "owner" );
local station_name = meta:get_string( "station_name" );
local station_network = meta:get_string( "station_network" );
if( owner_name and station_name and station_network
and ( not( travelnet.targets )
or not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )
or not( travelnet.targets[ owner_name ][ station_network ][ station_name ] ))) then
and ( not( travelnet.targets )
or not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )
or not( travelnet.targets[ owner_name ][ station_network ][ station_name ] ))) then
travelnet.add_target( station_name, station_network, pos, owner_name, meta, owner_name );
print( 'TRAVELNET: re-adding '..tostring( station_name )..' to '..
tostring( station_network )..' owned by '..tostring( owner_name ));
travelnet.add_target( station_name, station_network, pos, owner_name, meta, owner_name );
print( 'TRAVELNET: re-adding '..tostring( station_name )..' to '..
tostring( station_network )..' owned by '..tostring( owner_name ));
end
end
})

View File

@ -2,236 +2,229 @@ local S = minetest.get_translator("travelnet")
-- called "on_punch" of travelnet and elevator
travelnet.update_formspec = function( pos, puncher_name, fields )
local meta = minetest.get_meta(pos);
local meta = minetest.get_meta(pos);
local this_node = minetest.get_node( pos );
local is_elevator = false;
local this_node = minetest.get_node( pos );
local is_elevator = false;
if( this_node ~= nil and this_node.name == 'travelnet:elevator' ) then
is_elevator = true;
end
if this_node ~= nil and this_node.name == 'travelnet:elevator' then
is_elevator = true;
end
if( not( meta )) then
return;
end
if not meta then
return;
end
local owner_name = meta:get_string( "owner" );
local station_name = meta:get_string( "station_name" );
local station_network = meta:get_string( "station_network" );
local owner_name = meta:get_string( "owner" );
local station_name = meta:get_string( "station_name" );
local station_network = meta:get_string( "station_network" );
if( not( owner_name )
or not( station_name ) or station_network == ''
or not( station_network )) then
if( not( owner_name )
or not( station_name ) or station_network == ''
or not( station_network )) then
if is_elevator then
travelnet.add_target( nil, nil, pos, puncher_name, meta, owner_name );
return;
end
travelnet.reset_formspec( meta );
travelnet.show_message( pos, puncher_name, "Error", S("Update failed! Resetting this box on the travelnet."));
return;
end
-- if the station got lost from the network for some reason (savefile corrupted?) then add it again
if( not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )
or not( travelnet.targets[ owner_name ][ station_network ][ station_name ] )) then
-- first one by this player?
if not travelnet.targets[owner_name] then
travelnet.targets[owner_name ] = {};
end
-- first station on this network?
if not travelnet.targets[ owner_name ][ station_network ] then
travelnet.targets[owner_name ][ station_network ] = {};
end
if( is_elevator == true ) then
travelnet.add_target( nil, nil, pos, puncher_name, meta, owner_name );
return;
end
local zeit = meta:get_int("timestamp");
if not( zeit) or type(zeit)~="number" or zeit<100000 then
zeit = os.time();
end
travelnet.reset_formspec( meta );
travelnet.show_message( pos, puncher_name, "Error", S("Update failed! Resetting this box on the travelnet."));
return;
end
-- add this station
travelnet.targets[ owner_name ][ station_network ][ station_name ] = {pos=pos, timestamp=zeit };
-- if the station got lost from the network for some reason (savefile corrupted?) then add it again
if( not( travelnet.targets[ owner_name ] )
or not( travelnet.targets[ owner_name ][ station_network ] )
or not( travelnet.targets[ owner_name ][ station_network ][ station_name ] )) then
-- first one by this player?
if( not( travelnet.targets[ owner_name ] )) then
travelnet.targets[ owner_name ] = {};
end
-- first station on this network?
if( not( travelnet.targets[ owner_name ][ station_network ] )) then
travelnet.targets[ owner_name ][ station_network ] = {};
end
minetest.chat_send_player(owner_name, S("Station '@1'" .." "..
"has been reattached to the network '@2'.", station_name, station_network)
);
travelnet.save_data();
end
local zeit = meta:get_int("timestamp");
if( not( zeit) or type(zeit)~="number" or zeit<100000 ) then
zeit = os.time();
end
-- add name of station + network + owner + update-button
local zusatzstr = "";
local trheight = "10";
-- add this station
travelnet.targets[ owner_name ][ station_network ][ station_name ] = {pos=pos, timestamp=zeit };
local formspec = "size[12,"..trheight.."]"..
"label[3.3,0.0;"..S("Travelnet-Box")..":]".."label[6.3,0.0;"..
S("Punch box to update target list.").."]"..
"label[0.3,0.4;"..S("Name of this station:").."]"..
"label[6.3,0.4;"..minetest.formspec_escape(station_name or "?").."]"..
"label[0.3,0.8;"..S("Assigned to Network:").."]" ..
"label[6.3,0.8;"..minetest.formspec_escape(station_network or "?").."]"..
"label[0.3,1.2;"..S("Owned by:").."]"..
"label[6.3,1.2;"..minetest.formspec_escape(owner_name or "?").."]"..
"label[3.3,1.6;"..S("Click on target to travel there:").."]"..
zusatzstr;
minetest.chat_send_player(owner_name, S("Station '@1'" .." "..
"has been reattached to the network '@2'.", station_name, station_network));
travelnet.save_data();
end
local x = 0;
local y = 0;
local i = 0;
-- add name of station + network + owner + update-button
local zusatzstr = "";
local trheight = "10";
if( this_node and this_node.name=="locked_travelnet:travelnet" and locks) then
zusatzstr = "field[0.3,11;6,0.7;locks_sent_lock_command;"..S("Locked travelnet. Type /help for help:")..";]"..
locks.get_authorize_button(10,"10.5")..
locks.get_config_button(11,"10.5")
trheight = "11.5";
end
local formspec = "size[12,"..trheight.."]"..
"label[3.3,0.0;"..S("Travelnet-Box")..":]".."label[6.3,0.0;"..
S("Punch box to update target list.").."]"..
"label[0.3,0.4;"..S("Name of this station:").."]"..
"label[6.3,0.4;"..minetest.formspec_escape(station_name or "?").."]"..
"label[0.3,0.8;"..S("Assigned to Network:").."]" ..
"label[6.3,0.8;"..minetest.formspec_escape(station_network or "?").."]"..
"label[0.3,1.2;"..S("Owned by:").."]"..
"label[6.3,1.2;"..minetest.formspec_escape(owner_name or "?").."]"..
"label[3.3,1.6;"..S("Click on target to travel there:").."]"..
zusatzstr;
-- "button_exit[5.3,0.3;8,0.8;do_update;Punch box to update destination list. Click on target to travel there.]"..
local x = 0;
local y = 0;
local i = 0;
-- collect all station names in a table
local stations = {};
for k in pairs( travelnet.targets[ owner_name ][ station_network ] ) do
table.insert( stations, k );
end
-- collect all station names in a table
local stations = {};
local ground_level = 1;
if is_elevator then
table.sort( stations, function(a,b) return travelnet.targets[ owner_name ][ station_network ][ a ].pos.y >
travelnet.targets[ owner_name ][ station_network ][ b ].pos.y end);
-- find ground level
local vgl_timestamp = 999999999999;
for index,k in ipairs( stations ) do
if not travelnet.targets[ owner_name ][ station_network ][ k ].timestamp then
travelnet.targets[ owner_name ][ station_network ][ k ].timestamp = os.time();
end
if travelnet.targets[ owner_name ][ station_network ][ k ].timestamp < vgl_timestamp then
vgl_timestamp = travelnet.targets[ owner_name ][ station_network ][ k ].timestamp;
ground_level = index;
end
end
for k,v in pairs( travelnet.targets[ owner_name ][ station_network ] ) do
table.insert( stations, k );
end
-- minetest.chat_send_player(puncher_name, "stations: "..minetest.serialize( stations ));
for index,k in ipairs( stations ) do
if( index == ground_level ) then
travelnet.targets[ owner_name ][ station_network ][ k ].nr = 'G';
else
travelnet.targets[ owner_name ][ station_network ][ k ].nr = tostring( ground_level - index );
end
end
else
-- sort the table according to the timestamp (=time the station was configured)
table.sort( stations, function(a,b)
return travelnet.targets[ owner_name ][ station_network ][ a ].timestamp <
travelnet.targets[ owner_name ][ station_network ][ b ].timestamp
end);
end
local ground_level = 1;
if( is_elevator ) then
table.sort( stations, function(a,b) return travelnet.targets[ owner_name ][ station_network ][ a ].pos.y >
travelnet.targets[ owner_name ][ station_network ][ b ].pos.y end);
-- find ground level
local vgl_timestamp = 999999999999;
for index,k in ipairs( stations ) do
if( not( travelnet.targets[ owner_name ][ station_network ][ k ].timestamp )) then
travelnet.targets[ owner_name ][ station_network ][ k ].timestamp = os.time();
end
if( travelnet.targets[ owner_name ][ station_network ][ k ].timestamp < vgl_timestamp ) then
vgl_timestamp = travelnet.targets[ owner_name ][ station_network ][ k ].timestamp;
ground_level = index;
end
end
for index,k in ipairs( stations ) do
if( index == ground_level ) then
travelnet.targets[ owner_name ][ station_network ][ k ].nr = 'G';
else
travelnet.targets[ owner_name ][ station_network ][ k ].nr = tostring( ground_level - index );
end
end
-- does the player want to move this station one position up in the list?
-- only the owner and players with the travelnet_attach priv can change the order of the list
-- Note: With elevators, only the "G"(round) marking is actually moved
if( fields
and (fields.move_up or fields.move_down)
and owner_name
and owner_name ~= ""
and ((owner_name == puncher_name)
or (minetest.check_player_privs(puncher_name, {travelnet_attach=true})))
) then
else
-- sort the table according to the timestamp (=time the station was configured)
table.sort( stations, function(a,b)
return travelnet.targets[ owner_name ][ station_network ][ a ].timestamp <
travelnet.targets[ owner_name ][ station_network ][ b ].timestamp
end);
end
local current_pos = -1;
for index,k in ipairs( stations ) do
if( k==station_name ) then
current_pos = index;
end
end
-- does the player want to move this station one position up in the list?
-- only the owner and players with the travelnet_attach priv can change the order of the list
-- Note: With elevators, only the "G"(round) marking is actually moved
if( fields
and (fields.move_up or fields.move_down)
and owner_name
and owner_name ~= ""
and ((owner_name == puncher_name)
or (minetest.check_player_privs(puncher_name, {travelnet_attach=true})))
) then
local swap_with_pos;
if( fields.move_up ) then
swap_with_pos = current_pos - 1;
else
swap_with_pos = current_pos + 1;
end
-- handle errors
if( swap_with_pos < 1) then
travelnet.show_message( pos, puncher_name, "Info", S("This station is already the first one on the list."));
return;
elseif( swap_with_pos > #stations ) then
travelnet.show_message( pos, puncher_name, "Info", S("This station is already the last one on the list."));
return;
else
-- swap the actual data by which the stations are sorted
local old_timestamp = travelnet.targets[ owner_name ][ station_network ][ stations[swap_with_pos]].timestamp;
travelnet.targets[ owner_name ][ station_network ][ stations[swap_with_pos]].timestamp =
travelnet.targets[ owner_name ][ station_network ][ stations[current_pos ]].timestamp;
travelnet.targets[ owner_name ][ station_network ][ stations[current_pos ]].timestamp =
old_timestamp;
local current_pos = -1;
for index,k in ipairs( stations ) do
if( k==station_name ) then
current_pos = index;
end
end
-- for elevators, only the "G"(round) marking is moved; no point in swapping stations
if( not( is_elevator )) then
-- actually swap the stations
local old_val = stations[ swap_with_pos ];
stations[ swap_with_pos ] = stations[ current_pos ];
stations[ current_pos ] = old_val;
end
local swap_with_pos;
if( fields.move_up ) then
swap_with_pos = current_pos - 1;
else
swap_with_pos = current_pos + 1;
end
-- handle errors
if( swap_with_pos < 1) then
travelnet.show_message( pos, puncher_name, "Info", S("This station is already the first one on the list."));
return;
elseif( swap_with_pos > #stations ) then
travelnet.show_message( pos, puncher_name, "Info", S("This station is already the last one on the list."));
return;
else
-- swap the actual data by which the stations are sorted
local old_timestamp = travelnet.targets[ owner_name ][ station_network ][ stations[swap_with_pos]].timestamp;
travelnet.targets[ owner_name ][ station_network ][ stations[swap_with_pos]].timestamp =
travelnet.targets[ owner_name ][ station_network ][ stations[current_pos ]].timestamp;
travelnet.targets[ owner_name ][ station_network ][ stations[current_pos ]].timestamp =
old_timestamp;
-- store the changed order
travelnet.save_data();
end
end
-- for elevators, only the "G"(round) marking is moved; no point in swapping stations
if( not( is_elevator )) then
-- actually swap the stations
local old_val = stations[ swap_with_pos ];
stations[ swap_with_pos ] = stations[ current_pos ];
stations[ current_pos ] = old_val;
end
-- if there are only 8 stations (plus this one), center them in the formspec
if #stations < 10 then
x = 4;
end
-- store the changed order
travelnet.save_data();
end
end
for _,k in ipairs(stations) do
-- check if there is an elevator door in front that needs to be opened
local open_door_cmd = false;
if( k==station_name ) then
open_door_cmd = true;
end
-- if there are only 8 stations (plus this one), center them in the formspec
if( #stations < 10 ) then
x = 4;
end
if( k ~= station_name or open_door_cmd) then
i = i+1;
for index,k in ipairs( stations ) do
-- new column
if y==8 then
x = x+4;
y = 0;
end
-- check if there is an elevator door in front that needs to be opened
local open_door_cmd = false;
if( k==station_name ) then
open_door_cmd = true;
end
if open_door_cmd then
formspec = formspec .."button_exit["..(x)..","..(y+2.5)..";1,0.5;open_door;<>]"..
"label["..(x+0.9)..","..(y+2.35)..";"..tostring( k ).."]";
elseif( is_elevator ) then
formspec = formspec .."button_exit["..(x)..","..(y+2.5)..";1,0.5;target;"..
tostring( travelnet.targets[ owner_name ][ station_network ][ k ].nr ).."]"..
"label["..(x+0.9)..","..(y+2.35)..";"..tostring( k ).."]";
else
formspec = formspec .."button_exit["..(x)..","..(y+2.5)..";4,0.5;target;"..k.."]";
end
if( k ~= station_name or open_door_cmd) then
i = i+1;
y = y+1;
end
end
-- new column
if( y==8 ) then
x = x+4;
y = 0;
end
formspec = formspec..
"label[8.0,1.6;"..S("Position in list:").."]"..
"button_exit[11.3,0.0;1.0,0.5;station_exit;"..S("Exit").."]"..
"button_exit[10.0,0.5;2.2,0.7;station_dig;"..S("Remove station").."]"..
"button[9.6,1.6;1.4,0.5;move_up;"..S("move up").."]"..
"button[10.9,1.6;1.4,0.5;move_down;"..S("move down").."]";
if( open_door_cmd ) then
formspec = formspec .."button_exit["..(x)..","..(y+2.5)..";1,0.5;open_door;<>]"..
"label["..(x+0.9)..","..(y+2.35)..";"..tostring( k ).."]";
elseif( is_elevator ) then
formspec = formspec .."button_exit["..(x)..","..(y+2.5)..";1,0.5;target;"..
tostring( travelnet.targets[ owner_name ][ station_network ][ k ].nr ).."]"..
"label["..(x+0.9)..","..(y+2.35)..";"..tostring( k ).."]";
else
formspec = formspec .."button_exit["..(x)..","..(y+2.5)..";4,0.5;target;"..k.."]";
end
meta:set_string( "formspec", formspec );
y = y+1;
--x = x+4;
end
end
formspec = formspec..
"label[8.0,1.6;"..S("Position in list:").."]"..
"button_exit[11.3,0.0;1.0,0.5;station_exit;"..S("Exit").."]"..
"button_exit[10.0,0.5;2.2,0.7;station_dig;"..S("Remove station").."]"..
"button[9.6,1.6;1.4,0.5;move_up;"..S("move up").."]"..
"button[10.9,1.6;1.4,0.5;move_down;"..S("move down").."]";
meta:set_string( "infotext", S("Station '@1'".." "..
"on travelnet '@2' (owned by @3)" .." "..
"ready for usage. Right-click to travel, punch to update.",
tostring(station_name), tostring(station_network), tostring(owner_name)));
meta:set_string( "formspec", formspec );
meta:set_string( "infotext", S("Station '@1'".." "..
"on travelnet '@2' (owned by @3)" .." "..
"ready for usage. Right-click to travel, punch to update.",
tostring(station_name), tostring(station_network), tostring(owner_name)));
-- show the player the updated formspec
travelnet.show_current_formspec( pos, meta, puncher_name );
-- show the player the updated formspec
travelnet.show_current_formspec( pos, meta, puncher_name );
end