allow to teleport to plots

This commit is contained in:
Sokomine 2017-07-24 20:58:19 +02:00
parent a918c05da3
commit 6d0d26fe10
2 changed files with 35 additions and 5 deletions

View File

@ -410,7 +410,7 @@ end
-- print information about which mobs "live" in a house
mg_villages.inhabitants.print_house_info = function( village_to_add_data_bpos, house_nr, village_id )
mg_villages.inhabitants.print_house_info = function( village_to_add_data_bpos, house_nr, village_id, pname )
local bpos = village_to_add_data_bpos[ house_nr ];
local building_data = mg_villages.BUILDINGS[ bpos.btype ];
@ -421,6 +421,9 @@ mg_villages.inhabitants.print_house_info = function( village_to_add_data_bpos, h
local str = "Plot Nr. "..tostring( house_nr ).." ["..tostring( building_data.typ or "-?-").."] ";
local people_str = "";
local add_str = "";
if( bpos.road_nr ) then
str = str.." at road nr. "..tostring( bpos.road_nr ).." ";
end
if( bpos.btype == "road" ) then
str = str.."is a road.";
@ -494,11 +497,22 @@ mg_villages.inhabitants.print_house_info = function( village_to_add_data_bpos, h
if( people_str == "" ) then
people_str = "- nobody lives or works here permanently -";
end
local link_teleport = "";
if( pname and minetest.check_player_privs( pname, {teleport=true})) then
-- teleport to the plotmarker and not somewhere where part of the house may stand
link_teleport = 'button[8.0,0;1,0.5;teleport_to;Visit]'..
"field[21,21;0.1,0.1;pos2str;Pos;"..minetest.pos_to_string(
handle_schematics.get_pos_in_front_of_house( bpos, 0 )).."]";
end
return 'size[12,4.5]'..
'button_exit[4.0,0;2,0.5;quit;Exit]'..
'button[9.5,0;2,0.5;back_to_plotlist;Back to plotlist]'..
-- the back button needs to know which village we are in
'field[20,20;0.1,0.1;village_id;VillageID;'..minetest.formspec_escape( village_id ).."]"..
-- show where the plot is located
'label[0.5,0;Location: '..minetest.formspec_escape( minetest.pos_to_string( bpos ))..']'..
-- allow to teleport there (if the player has the teleport priv)
link_teleport..
'label[0.5,0.5;'..minetest.formspec_escape(str)..']'..
'label[0.5,4.1;'..minetest.formspec_escape(add_str)..']'..
'tablecolumns[' ..
@ -904,7 +918,7 @@ mg_villages.inhabitants.part_of_village_spawned = function( village, minp, maxp,
end
--[[ deprecated
-- command for debugging all inhabitants of a village (useful for debugging only)
minetest.register_chatcommand( 'inhabitants', {
description = "Prints out a list of inhabitants of a village plus their professions.",
@ -926,7 +940,7 @@ minetest.register_chatcommand( 'inhabitants', {
minetest.chat_send_player( name, "Printing information about inhabitants of village no. "..tostring( v.nr )..", called "..( tostring( v.name or 'unknown')).." to console.");
-- actually print it
for house_nr = 1,#v.to_add_data.bpos do
minetest.chat_send_player( name, mg_villages.inhabitants.print_house_info( v.to_add_data.bpos, house_nr, v.nr ));
minetest.chat_send_player( name, mg_villages.inhabitants.print_house_info( v.to_add_data.bpos, house_nr, v.nr, name ));
end
return;
end
@ -936,3 +950,4 @@ minetest.register_chatcommand( 'inhabitants', {
end
});
--]]

View File

@ -51,7 +51,7 @@ mg_villages.plotmarker_formspec = function( pos, formname, fields, player )
-- show a list of who lives (or works) here at this plot
if( fields and fields.inhabitants ) then
minetest.show_formspec( pname, "mg_villages:plot_mob_list",
mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr, village_id ));
mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr, village_id, pname ));
--mg_villages.debug_inhabitants( village, plot_nr);
return;
end
@ -358,6 +358,21 @@ mg_villages.form_input_handler = function( player, formname, fields)
return false;
end
-- teleport to a plot or mob
if( fields[ 'teleport_to' ]
and fields[ 'pos2str' ]
and player ) then
local pname = player:get_player_name();
if( minetest.check_player_privs( pname, {teleport=true})) then
local pos = minetest.string_to_pos( fields.pos2str );
-- teleport the player to the target position
player:moveto( { x=pos.x, y=(pos.y+1), z=pos.z }, false);
else
minetest.chat_sned_player( pname, "Sorry. You do not have the teleport privilege.");
end
-- do not abort; continue with showing the formspec
end
-- provide information about the inhabitants of a particular plot
if( not( fields['back_to_plotlist'])
and fields['mg_villages:formspec_list_plots']
@ -373,7 +388,7 @@ mg_villages.form_input_handler = function( player, formname, fields)
local village = mg_villages.all_villages[ fields.village_id ];
local plot_nr = selection.row-1;
minetest.show_formspec( pname, "mg_villages:plot_mob_list",
mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr, fields.village_id ));
mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr, fields.village_id, pname ));
return true;
end
end