Update init.lua

This commit is contained in:
Panquesito7 2019-07-25 14:53:20 -05:00 committed by GitHub
parent 4b992b30e4
commit 4108156118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,6 +38,11 @@ dofile(MP.."/config.lua")
local tpr_list = {} local tpr_list = {}
local tphr_list = {} local tphr_list = {}
local map_size = 30912
local function can_teleport(to)
return to.x < map_size and to.x > -map_size and to.y < map_size and to.y > -map_size and to.z < map_size and to.z > -map_size
end
-- Teleport player to a player (used in "/tpr" command). -- Teleport player to a player (used in "/tpr" command).
function tpr_teleport_player(name) function tpr_teleport_player(name)
local target_coords = source:get_pos() local target_coords = source:get_pos()
@ -48,6 +53,22 @@ function tpr_teleport_player(name)
--parti2(target_coords) --parti2(target_coords)
end end
-- TPJ
function tpj_teleport_player(player)
local pname = minetest.get_player_by_name(player)
minetest.sound_play("whoosh", {pos = pname:get_pos(), gain = 0.5, max_hear_distance = 10})
pname:set_pos(find_free_position_near(target_coords))
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
end
-- TPC
function tpc_teleport_player(player)
local pname = minetest.get_player_by_name(player)
minetest.sound_play("whoosh", {pos = pname:get_pos(), gain = 0.5, max_hear_distance = 10})
pname:set_pos(find_free_position_near(target_coords))
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
end
local function find_free_position_near(pos) local function find_free_position_near(pos)
local tries = { local tries = {
{x=1,y=0,z=0}, {x=1,y=0,z=0},
@ -192,7 +213,7 @@ function tpc_send(player, coordinates)
return nil return nil
end end
local target_coords = {x=posx, y=posy, z=posz} target_coords = {x=posx, y=posy, z=posz}
if can_teleport(target_coords) == false then if can_teleport(target_coords) == false then
minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!")) minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!"))
@ -203,10 +224,8 @@ function tpc_send(player, coordinates)
-- In future release we'll actually query the player who owns the area, if they're online, and ask for their permission. -- In future release we'll actually query the player who owns the area, if they're online, and ask for their permission.
-- Admin user (priv "tp_admin") overrides all protection -- Admin user (priv "tp_admin") overrides all protection
if minetest.check_player_privs(pname, {tp_admin=true}) then if minetest.check_player_privs(pname, {tp_admin=true}) then
tpc_teleport_player(player)
minetest.chat_send_player(player, S("Teleporting to: @1, @2, @3", posx, posy, posz)) minetest.chat_send_player(player, S("Teleporting to: @1, @2, @3", posx, posy, posz))
minetest.sound_play("whoosh", {pos = pname:get_pos(), gain = 0.5, max_hear_distance = 10})
pname:set_pos(find_free_position_near(target_coords))
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords) --parti2(target_coords)
else else
if minetest.check_player_privs(pname, {tp_tpc = true}) then if minetest.check_player_privs(pname, {tp_tpc = true}) then
@ -218,10 +237,8 @@ function tpc_send(player, coordinates)
return return
end end
end end
minetest.sound_play("whoosh", {pos = pname:get_pos(), gain = 0.5, max_hear_distance = 10}) tpc_teleport_player(player)
minetest.chat_send_player(player, S("Teleporting to: @1, @2, @3", posx, posy, posz)) minetest.chat_send_player(player, S("Teleporting to: @1, @2, @3", posx, posy, posz))
pname:set_pos(find_free_position_near(target_coords))
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords) --parti2(target_coords)
else else
minetest.chat_send_player(player, S("Error: You do not have permission to teleport to coordinates.")) minetest.chat_send_player(player, S("Error: You do not have permission to teleport to coordinates."))
@ -297,7 +314,7 @@ function tpj(player, param)
end end
-- Initially generate the target coords from the player's current position (since it's relative) and then perform the math. -- Initially generate the target coords from the player's current position (since it's relative) and then perform the math.
local target_coords = minetest.get_player_by_name(player):get_pos() target_coords = minetest.get_player_by_name(player):get_pos()
if args[1] == "x" then if args[1] == "x" then
target_coords["x"] = target_coords["x"] + tonumber(args[2]) target_coords["x"] = target_coords["x"] + tonumber(args[2])
elseif args[1] == "y" then elseif args[1] == "y" then
@ -312,9 +329,7 @@ function tpj(player, param)
minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!")) minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!"))
return return
end end
minetest.sound_play("whoosh", {pos = pname:get_pos(), gain = 0.5, max_hear_distance = 10}) tpj_teleport_player(player)
pname:set_pos(find_free_position_near(target_coords))
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords) --parti2(target_coords)
end end