2015-07-18 15:15:49 -05:00
|
|
|
|
|
|
|
|
2015-07-21 23:00:12 -05:00
|
|
|
function mg_villages.spawnplayer(player)
|
2015-07-18 15:15:49 -05:00
|
|
|
if( minetest.setting_get("static_spawnpoint")) then
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
-- make sure the village types are initialized
|
|
|
|
if( not( mg_villages.village_types )) then
|
|
|
|
mg_villages.init_weights();
|
|
|
|
end
|
|
|
|
|
|
|
|
local noise1 = minetest.get_perlin(12345, 6, 0.5, 256)
|
|
|
|
local min_dist = math.huge
|
2015-12-12 09:51:43 -06:00
|
|
|
local min_pos = game_origin
|
2015-07-18 15:15:49 -05:00
|
|
|
for bx = -20, 20 do
|
|
|
|
for bz = -20, 20 do
|
2015-12-12 23:57:59 -06:00
|
|
|
local minp = {x = min_pos.x + bx, y = -32, z = min_pos.z + bz}
|
2015-07-18 15:15:49 -05:00
|
|
|
for _, village in ipairs(mg_villages.villages_at_point(minp, noise1)) do
|
|
|
|
if math.abs(village.vx) + math.abs(village.vz) < min_dist then
|
|
|
|
min_pos = {x = village.vx, y = village.vh + 2, z = village.vz}
|
|
|
|
-- some villages are later adjusted in height; adapt these changes
|
|
|
|
local village_id = tostring( village.vx )..':'..tostring( village.vz );
|
|
|
|
if( mg_villages.all_villages[ village_id ]
|
|
|
|
and mg_villages.all_villages[ village_id ].optimal_height ) then
|
|
|
|
min_pos.y = mg_villages.all_villages[ village_id ].vh + 2;
|
|
|
|
-- the first villages will have a height of 1 in order to make sure that the player does not end up embedded in stone
|
|
|
|
else
|
|
|
|
min_pos.y = 1+2;
|
|
|
|
end
|
|
|
|
min_dist = math.abs(village.vx) + math.abs(village.vz)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
player:setpos(min_pos)
|
2015-07-21 22:58:01 -05:00
|
|
|
local name = player:get_player_name()
|
2015-09-07 01:25:16 -05:00
|
|
|
pd.set(name,"homepos",min_pos)
|
2015-07-18 15:15:49 -05:00
|
|
|
end
|
|
|
|
|
2015-09-07 01:25:16 -05:00
|
|
|
mg_villages.on_newplayer = function(player)
|
2015-07-21 23:44:55 -05:00
|
|
|
mg_villages.spawnplayer(player)
|
2015-09-07 01:25:16 -05:00
|
|
|
end
|
2015-07-18 15:15:49 -05:00
|
|
|
|
2015-07-21 22:44:35 -05:00
|
|
|
--minetest.register_on_respawnplayer(function(player)
|
|
|
|
--spawnplayer(player)
|
|
|
|
--return true
|
|
|
|
--end)
|
2015-07-18 15:15:49 -05:00
|
|
|
|