Skip to content

Commit

Permalink
Part teleport function as substantive func - as suggested by github u…
Browse files Browse the repository at this point in the history
…ser Reedych.
  • Loading branch information
AndrejIT committed Oct 8, 2017
1 parent 580a796 commit 1e07844
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions init.lua
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,32 @@ if minetest.setting_get_pos("static_spawnpoint") then
spawn_command.pos = minetest.setting_get_pos("static_spawnpoint")
end

function teleport_to_spawn(name)
local player = minetest.get_player_by_name(name)
if player == nil then
-- just a check to prevent the server crashing
return false
end
local pos = player:getpos()
if pos.x>-20 and pos.x<20 and pos.z>-20 and pos.z<20 then
minetest.chat_send_player(name, "Already close to spawn!")
elseif _G['cursed_world'] ~= nil and --check global table for cursed_world mod
cursed_world.location_y and cursed_world.dimension_y and
pos.y < (cursed_world.location_y + cursed_world.dimension_y) and --if player is in cursed world, stay in cursed world
pos.y > (cursed_world.location_y - cursed_world.dimension_y)
then --check global table for cursed_world mod
--minetest.chat_send_player(name, "T"..(cursed_world.location_y + cursed_world.dimension_y).." "..(cursed_world.location_y - cursed_world.dimension_y))
local spawn_pos = vector.round(spawn_command.pos);
spawn_pos.y = spawn_pos.y + cursed_world.location_y;
player:setpos(spawn_pos)
minetest.chat_send_player(name, "Teleported to spawn!")
else
player:setpos(spawn_command.pos)
minetest.chat_send_player(name, "Teleported to spawn!")
end
end

minetest.register_chatcommand("spawn", {
description = "Teleport you to spawn point.",
func = function(name)
local player = minetest.get_player_by_name(name)
if player == nil then
-- just a check to prevent the server crashing
return false
end
local pos = player:getpos()
if pos.x>-20 and pos.x<20 and pos.z>-20 and pos.z<20 then
minetest.chat_send_player(name, "Already close to spawn!")
elseif _G['cursed_world'] ~= nil and --check global table for cursed_world mod
cursed_world.location_y and cursed_world.dimension_y and
pos.y < (cursed_world.location_y + cursed_world.dimension_y) and --if player is in cursed world, stay in cursed world
pos.y > (cursed_world.location_y - cursed_world.dimension_y)
then --check global table for cursed_world mod
--minetest.chat_send_player(name, "T"..(cursed_world.location_y + cursed_world.dimension_y).." "..(cursed_world.location_y - cursed_world.dimension_y))
local spawn_pos = vector.round(spawn_command.pos);
spawn_pos.y = spawn_pos.y + cursed_world.location_y;
player:setpos(spawn_pos)
minetest.chat_send_player(name, "Teleported to spawn!")
else
player:setpos(spawn_command.pos)
minetest.chat_send_player(name, "Teleported to spawn!")
end
end,
func = teleport_to_spawn,
})

0 comments on commit 1e07844

Please sign in to comment.