2019-07-09 03:23:57 +02:00
--[[
2019-12-02 02:11:07 +01:00
Allows players to request from another player to be teleported to them , and do much more .
2020-01-01 20:50:42 +01:00
Copyright ( C ) 2015 - 2020 ChaosWormz and contributors
2019-07-18 01:04:52 +02:00
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
version 2.1 of the License , or ( at your option ) any later version .
This library is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public
License along with this library ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301
USA
----------------------------------------------------------------------------
2019-07-09 03:23:57 +02:00
Originally made by Traxie21 and released with the WTFPL license .
2019-07-18 01:04:52 +02:00
Forum link : https : // forum.minetest . net / viewtopic.php ? id = 4457
Updates by Zeno , Panquesito7 and ChaosWormz .
2019-11-22 19:56:08 +01:00
License : LGPLv2 .1 + for everything .
2019-07-09 03:23:57 +02:00
--]]
2014-07-26 08:20:32 +02:00
2019-07-15 20:52:31 +02:00
-- Load support for intllib.
local MP = minetest.get_modpath ( minetest.get_current_modname ( ) )
local S , NS = dofile ( MP .. " /intllib.lua " )
2020-01-02 03:00:50 +01:00
tp = {
intllib = S
}
2019-07-18 01:04:52 +02:00
-- Load configuration.
2019-07-19 22:53:49 +02:00
dofile ( MP .. " /config.lua " )
2014-07-26 08:20:32 +02:00
2019-08-06 06:04:38 +02:00
tp.tpr_list = { }
tp.tphr_list = { }
2014-07-26 08:20:32 +02:00
2019-07-25 21:53:20 +02:00
local map_size = 30912
2019-08-06 06:04:38 +02:00
function tp . can_teleport ( to )
2019-07-25 21:53:20 +02:00
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
2019-07-26 02:50:28 +02:00
-- Teleport player to a player (used in "/tpr" and in "/tphr" command).
2019-08-06 06:04:38 +02:00
function tp . tpr_teleport_player ( )
2019-07-25 21:16:48 +02:00
local target_coords = source : get_pos ( )
local target_sound = target : get_pos ( )
2019-08-06 06:04:38 +02:00
target : set_pos ( tp.find_free_position_near ( target_coords ) )
2019-07-25 21:16:48 +02:00
minetest.sound_play ( " whoosh " , { pos = target_coords , gain = 0.5 , max_hear_distance = 10 } )
minetest.sound_play ( " whoosh " , { pos = target_sound , gain = 0.5 , max_hear_distance = 10 } )
2019-08-06 06:04:38 +02:00
--tp.parti2(target_coords)
2019-07-25 21:16:48 +02:00
end
2019-07-26 06:51:04 +02:00
-- TPC & TPJ
2019-08-06 06:04:38 +02:00
function tp . tpc_teleport_player ( player )
2019-07-25 21:53:20 +02:00
local pname = minetest.get_player_by_name ( player )
minetest.sound_play ( " whoosh " , { pos = pname : get_pos ( ) , gain = 0.5 , max_hear_distance = 10 } )
2019-08-06 06:04:38 +02:00
pname : set_pos ( tp.find_free_position_near ( target_coords ) )
2019-07-25 21:53:20 +02:00
minetest.sound_play ( " whoosh " , { pos = target_coords , gain = 0.5 , max_hear_distance = 10 } )
2019-08-06 06:04:38 +02:00
--tp.parti2(target_coords)
2019-07-25 21:53:20 +02:00
end
2019-07-26 02:38:31 +02:00
-- TPP
2019-08-06 06:04:38 +02:00
function tp . tpp_teleport_player ( player )
2019-07-26 02:38:31 +02:00
local pname = minetest.get_player_by_name ( player )
minetest.sound_play ( " whoosh " , { pos = pname : get_pos ( ) , gain = 0.5 , max_hear_distance = 10 } )
2019-08-06 06:04:38 +02:00
pname : set_pos ( tp.find_free_position_near ( pos ) )
2019-07-26 02:38:31 +02:00
minetest.sound_play ( " whoosh " , { pos = pos , gain = 0.5 , max_hear_distance = 10 } )
2019-08-06 06:04:38 +02:00
--tp.parti2(target_coords)
2019-07-26 02:38:31 +02:00
end
2019-08-06 06:04:38 +02:00
function tp . find_free_position_near ( pos )
2016-05-13 19:41:44 +02:00
local tries = {
{ x = 1 , y = 0 , z = 0 } ,
{ x =- 1 , y = 0 , z = 0 } ,
{ x = 0 , y = 0 , z = 1 } ,
{ x = 0 , y = 0 , z =- 1 } ,
}
for _ , d in pairs ( tries ) do
local p = vector.add ( pos , d )
2019-12-30 08:49:22 +01:00
local def = minetest.registered_nodes [ minetest.get_node ( p ) . name ]
if def and not def.walkable then
2016-05-13 19:41:44 +02:00
return p , true
end
end
return pos , false
end
2019-08-06 06:04:38 +02:00
function tp . parti ( pos )
2016-05-13 20:59:32 +02:00
minetest.add_particlespawner ( 50 , 0.4 ,
{ x = pos.x + 0.5 , y = pos.y , z = pos.z + 0.5 } , { x = pos.x - 0.5 , y = pos.y , z = pos.z - 0.5 } ,
{ x = 0 , y = 5 , z = 0 } , { x = 0 , y = 0 , z = 0 } ,
{ x = 0 , y = 5 , z = 0 } , { x = 0 , y = 0 , z = 0 } ,
3 , 5 ,
3 , 5 ,
false ,
" tps_portal_parti.png " )
end
2019-08-06 06:04:38 +02:00
function tp . parti2 ( pos )
2016-05-13 20:59:32 +02:00
minetest.add_particlespawner ( 50 , 0.4 ,
{ x = pos.x + 0.5 , y = pos.y + 10 , z = pos.z + 0.5 } , { x = pos.x - 0.5 , y = pos.y , z = pos.z - 0.5 } ,
{ x = 0 , y =- 5 , z = 0 } , { x = 0 , y = 0 , z = 0 } ,
{ x = 0 , y =- 5 , z = 0 } , { x = 0 , y = 0 , z = 0 } ,
3 , 5 ,
3 , 5 ,
false ,
" tps_portal_parti.png " )
end
2019-07-09 03:23:57 +02:00
-- Teleport Request System
2019-08-06 06:04:38 +02:00
function tp . clear_tpr_list ( name )
if tp.tpr_list [ name ] then
tp.tpr_list [ name ] = nil
2019-07-27 01:51:52 +02:00
return
2019-07-25 04:53:58 +02:00
end
end
2019-08-06 06:04:38 +02:00
function tp . clear_tphr_list ( name )
if tp.tphr_list [ name ] then
tp.tphr_list [ name ] = nil
2019-07-27 01:51:52 +02:00
return
2019-07-25 04:53:58 +02:00
end
end
2019-07-29 01:03:32 +02:00
-- Clear requests when the player leaves
minetest.register_on_leaveplayer ( function ( name )
2019-08-06 06:04:38 +02:00
if tp.tpr_list [ name ] then
tp.tpr_list [ name ] = nil
2019-07-29 01:03:32 +02:00
return
end
2019-08-06 06:04:38 +02:00
if tp.tphr_list [ name ] then
tp.tphr_list [ name ] = nil
2019-07-29 01:03:32 +02:00
return
end
end )
2019-08-06 06:04:38 +02:00
function tp . tpr_send ( sender , receiver )
-- Compatibility with beerchat (UNTESTED)
if minetest.get_modpath ( " beerchat " ) and not minetest.check_player_privs ( sender , { tp_admin = true } ) then
2020-01-03 01:30:53 +01:00
if minetest.get_player_by_name ( receiver ) : get_meta ( ) : get_string ( " beerchat:muted: " .. sender ) == " true " then
2019-08-06 06:04:38 +02:00
minetest.chat_send_player ( sender , S ( " You are not allowed to send requests because you're muted. " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " You are not allowed to send requests because you're muted. " ) , 0xFFFFFF )
end
2019-08-06 06:04:38 +02:00
return
end
end
if minetest.check_player_privs ( sender , { tp_admin = true } ) and tp.enable_immediate_teleport then
2019-07-15 03:04:30 +02:00
if receiver == " " then
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( sender , S ( " Usage: /tpr <Player name> " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Usage: /tpr <Player name> " ) , 0xFFFFFF )
end
return
2019-07-15 03:04:30 +02:00
end
if not minetest.get_player_by_name ( receiver ) then
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( sender , S ( " There is no player by that name. Keep in mind this is case-sensitive, and the player must be online " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " There is no player by that name. Keep in mind this is case-sensitive, and the player must be online " ) , 0xFFFFFF )
end
2019-07-15 03:04:30 +02:00
return
end
2019-08-06 06:04:38 +02:00
tp.tpr_list [ receiver ] = sender
tp.tpr_accept ( receiver )
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( sender , S ( " You are teleporting to @1. " , receiver ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " You are teleporting to @1. " , receiver ) , 0xFFFFFF )
end
2019-07-09 03:23:57 +02:00
return
end
2014-07-30 04:15:08 +02:00
if receiver == " " then
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( sender , S ( " Usage: /tpr <Player name> " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Usage: /tpr <Player name> " ) , 0xFFFFFF )
end
2014-07-30 04:15:08 +02:00
return
end
2014-07-26 08:20:32 +02:00
2015-08-28 22:08:16 +02:00
if not minetest.get_player_by_name ( receiver ) then
2019-08-07 05:19:30 +02:00
minetest.chat_send_player ( sender , S ( " There is no player by that name. Keep in mind this is case-sensitive, and the player must be online " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " There is no player by that name. Keep in mind this is case-sensitive, and the player must be online " ) , 0xFFFFFF )
end
2015-08-28 22:08:16 +02:00
return
2014-07-30 04:15:08 +02:00
end
2019-11-22 20:50:10 +01:00
if minetest.get_modpath ( " gamehub " ) then -- Compatibility with gamehub (UNTESTED)
if gamehub.players [ receiver ] then
minetest.chat_send_player ( sender , S ( " Teleport request denied, player is in the gamehub! " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Teleport request denied, player is in the gamehub! " ) , 0xFFFFFF )
end
return
end
end
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( receiver ) , S ( " @1 is requesting to teleport to you. /tpy to accept " , sender ) , 0xFFFFFF )
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Teleport request sent! It will timeout in @1 seconds " , tp.timeout_delay ) , 0xFFFFFF )
end
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( receiver , S ( " @1 is requesting to teleport to you. /tpy to accept " , sender ) )
2019-08-16 19:09:41 +02:00
minetest.chat_send_player ( sender , S ( " Teleport request sent! It will timeout in @1 seconds " , tp.timeout_delay ) )
2019-07-09 03:23:57 +02:00
-- Write name values to list and clear old values.
2019-08-06 06:04:38 +02:00
tp.tpr_list [ receiver ] = sender
2019-07-25 23:59:37 +02:00
-- Teleport timeout delay
2019-08-06 06:04:38 +02:00
minetest.after ( tp.timeout_delay , function ( name )
if tp.tpr_list [ name ] then
tp.tpr_list [ name ] = nil
2019-07-27 01:51:52 +02:00
minetest.chat_send_player ( sender , S ( " Request timed-out. " ) )
minetest.chat_send_player ( receiver , S ( " Request timed-out. " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Request timed-out. " ) , 0xFFFFFF )
chat2.send_message ( minetest.get_player_by_name ( receiver ) , S ( " Request timed-out. " ) , 0xFFFFFF )
end
2019-07-27 01:51:52 +02:00
return
end
end , receiver )
2015-08-28 22:08:16 +02:00
end
2014-07-30 06:01:44 +02:00
2019-08-06 06:04:38 +02:00
function tp . tphr_send ( sender , receiver )
-- Compatibility with beerchat (UNTESTED)
if minetest.get_modpath ( " beerchat " ) and not minetest.check_player_privs ( sender , { tp_admin = true } ) then
2020-01-03 01:30:53 +01:00
if minetest.get_player_by_name ( receiver ) : get_meta ( ) : get_string ( " beerchat:muted: " .. sender ) == " true " then
2019-08-06 06:04:38 +02:00
minetest.chat_send_player ( sender , S ( " You are not allowed to send requests because you're muted. " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " You are not allowed to send requests because you're muted. " ) , 0xFFFFFF )
end
2019-08-06 06:04:38 +02:00
return
end
end
if minetest.check_player_privs ( sender , { tp_admin = true } ) and tp.enable_immediate_teleport then
2019-07-15 03:04:30 +02:00
if receiver == " " then
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( sender , S ( " Usage: /tphr <Player name> " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Usage. /tphr <Player name> " ) , 0xFFFFFF )
end
2019-07-15 03:04:30 +02:00
return
end
if not minetest.get_player_by_name ( receiver ) then
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( sender , S ( " There is no player by that name. Keep in mind this is case-sensitive, and the player must be online " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " There is no player by that name. Keep in mind this is case-sensitive, and the player must be online " ) , 0xFFFFFF )
end
2019-07-15 03:04:30 +02:00
return
end
2019-08-06 06:04:38 +02:00
tp.tphr_list [ receiver ] = sender
tp.tpr_accept ( receiver )
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( sender , S ( " @1 is teleporting to you. " , receiver ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " @1 is teleporting to you. " , receiver ) , 0xFFFFFF )
end
2019-07-09 03:23:57 +02:00
return
end
2019-11-22 20:50:10 +01:00
2014-07-30 06:05:03 +02:00
if receiver == " " then
2019-08-07 05:19:30 +02:00
minetest.chat_send_player ( sender , S ( " Usage: /tphr <Player name> " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Usage. /tphr <Player name> " ) , 0xFFFFFF )
end
2014-07-30 04:15:08 +02:00
return
end
2014-07-26 08:20:32 +02:00
2015-08-28 22:08:16 +02:00
if not minetest.get_player_by_name ( receiver ) then
2019-08-07 05:19:30 +02:00
minetest.chat_send_player ( sender , S ( " There is no player by that name. Keep in mind this is case-sensitive, and the player must be online " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " There is no player by that name. Keep in mind this is case-sensitive, and the player must be online " ) , 0xFFFFFF )
end
2015-08-28 22:08:16 +02:00
return
2014-07-30 04:15:08 +02:00
end
2019-11-22 20:50:10 +01:00
if minetest.get_modpath ( " gamehub " ) then -- Compatibility with gamehub (UNTESTED)
if gamehub.players [ receiver ] then
minetest.chat_send_player ( sender , S ( " Teleport request denied, player is in the gamehub! " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Teleport request denied, player is in the gamehub! " ) , 0xFFFFFF )
end
return
end
end
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( receiver ) , S ( " @1 is requesting that you teleport to them. /tpy to accept; /tpn to deny " , sender ) , 0xFFFFFF )
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Teleport request sent! It will timeout in @1 seconds " , tp.timeout_delay ) , 0xFFFFFF )
end
2019-11-22 20:50:10 +01:00
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( receiver , S ( " @1 is requesting that you teleport to them. /tpy to accept; /tpn to deny " , sender ) )
2019-08-16 19:09:41 +02:00
minetest.chat_send_player ( sender , S ( " Teleport request sent! It will timeout in @1 seconds " , tp.timeout_delay ) )
2019-07-09 03:23:57 +02:00
-- Write name values to list and clear old values.
2019-08-06 06:04:38 +02:00
tp.tphr_list [ receiver ] = sender
2019-07-25 20:39:40 +02:00
-- Teleport timeout delay
2019-08-06 06:04:38 +02:00
minetest.after ( tp.timeout_delay , function ( name )
if tp.tphr_list [ name ] then
tp.tphr_list [ name ] = nil
2019-07-27 01:51:52 +02:00
minetest.chat_send_player ( sender , S ( " Request timed-out. " ) )
minetest.chat_send_player ( receiver , S ( " Request timed-out. " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( sender ) , S ( " Request timed-out " ) , 0xFFFFFF )
chat2.send_message ( minetest.get_player_by_name ( receiver ) , S ( " Request timed-out " ) , 0xFFFFFF )
end
2019-07-27 01:51:52 +02:00
return
end
end , receiver )
2014-07-26 08:20:32 +02:00
end
2019-08-06 06:04:38 +02:00
function tp . tpc_send ( player , coordinates )
2016-05-10 17:11:31 +02:00
2019-07-09 03:23:57 +02:00
local posx , posy , posz = string.match ( coordinates , " ^(-?%d+), (-?%d+), (-?%d+)$ " )
2016-05-10 19:42:17 +02:00
local pname = minetest.get_player_by_name ( player )
2016-05-10 19:58:24 +02:00
if posx ~= nil or posy ~= nil or posz ~= nil then
posx = tonumber ( posx ) + 0.0
posy = tonumber ( posy ) + 0.0
posz = tonumber ( posz ) + 0.0
end
2016-05-10 17:11:31 +02:00
2016-05-10 20:20:28 +02:00
if posx == nil or posy == nil or posz == nil or string.len ( posx ) > 6 or string.len ( posy ) > 6 or string.len ( posz ) > 6 then
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( player , S ( " Usage: /tpc <x, y, z> " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Usage: /tpc <x, y, z> " ) , 0xFFFFFF )
end
2016-05-10 20:20:28 +02:00
return nil
end
2016-05-10 19:42:17 +02:00
2019-07-25 21:53:20 +02:00
target_coords = { x = posx , y = posy , z = posz }
2016-05-10 19:42:17 +02:00
2019-08-06 06:04:38 +02:00
if tp.can_teleport ( target_coords ) == false then
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( player , S ( " You cannot teleport to a location outside the map! " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " You cannot teleport to a location outside the map! " ) , 0xFFFFFF )
end
2019-03-24 16:38:32 +01:00
return nil
end
2016-05-10 17:11:31 +02:00
-- If the area is protected, reject the user's request to teleport to these coordinates
-- In future release we'll actually query the player who owns the area, if they're online, and ask for their permission.
2016-05-13 19:12:11 +02:00
-- Admin user (priv "tp_admin") overrides all protection
2019-08-06 06:04:38 +02:00
if minetest.check_player_privs ( pname , { tp_admin = true } ) then
tp.tpc_teleport_player ( player )
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( player , S ( " Teleporting to: @1, @2, @3 " , posx , posy , posz ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Teleporting to: @1, @2, @3 " , posx , posy , posz ) , 0xFFFFFF )
end
2016-05-13 19:12:11 +02:00
else
2019-07-12 03:59:46 +02:00
if minetest.check_player_privs ( pname , { tp_tpc = true } ) then
2019-12-02 02:11:07 +01:00
local protected = minetest.is_protected ( target_coords , pname )
2019-07-12 03:59:46 +02:00
if protected and minetest.get_modpath ( " areas " ) then
if not areas : canInteract ( target_coords , player ) then
local owners = areas : getNodeOwners ( target_coords )
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( player , S ( " Error: @1 is protected by @2. " , minetest.pos_to_string ( target_coords ) , table.concat ( owners , " , " ) ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Error: @1 is protected by @2. " , minetest.pos_to_string ( target_coords ) , table.concat ( owners , " , " ) ) , 0xFFFFFF )
end
2019-07-12 03:59:46 +02:00
return
end
2016-05-13 19:12:11 +02:00
end
2019-08-06 06:04:38 +02:00
tp.tpc_teleport_player ( player )
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( player , S ( " Teleporting to: @1, @2, @3 " , posx , posy , posz ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Teleporting to: @1, @2, @3 " , posx , posy , posz ) , 0xFFFFFF )
end
2016-05-17 19:15:48 +02:00
else
2019-08-07 05:19:30 +02:00
minetest.chat_send_player ( player , S ( " Error: You do not have permission to teleport to those coordinates. " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Error: You do not have permission to teleport to those coordinates. " ) , 0xFFFFFF )
end
2016-05-17 19:15:48 +02:00
return
2016-05-13 19:12:11 +02:00
end
end
2016-05-10 17:11:31 +02:00
end
2019-08-06 06:04:38 +02:00
function tp . tpr_deny ( name )
if tp.tpr_list [ name ] then
name2 = tp.tpr_list [ name ]
2019-07-29 06:11:54 +02:00
minetest.chat_send_player ( name2 , S ( " Teleport request denied. " ) )
minetest.chat_send_player ( name , S ( " You denied the request @1 sent you. " , name2 ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( name2 ) , S ( " Teleport request denied. " ) , 0xFFFFFF )
chat2.send_message ( minetest.get_player_by_name ( name ) , S ( " You denied the request @1 sent you. " , name2 ) , 0xFFFFFF )
end
2019-08-06 06:04:38 +02:00
tp.tpr_list [ name ] = nil
2019-12-02 02:11:07 +01:00
2019-08-06 06:04:38 +02:00
elseif tp.tphr_list [ name ] then
2019-08-07 05:19:30 +02:00
name2 = tp.tphr_list [ name ]
2019-07-29 06:11:54 +02:00
minetest.chat_send_player ( name2 , S ( " Teleport request denied. " ) )
minetest.chat_send_player ( name , S ( " You denied the request @1 sent you. " , name2 ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( name2 ) , S ( " Teleport request denied. " ) , 0xFFFFFF )
chat2.send_message ( minetest.get_player_by_name ( name ) , S ( " You denied the request @1 sent you. " , name2 ) , 0xFFFFFF )
end
2019-08-06 06:04:38 +02:00
tp.tphr_list [ name ] = nil
2019-12-02 02:11:07 +01:00
2019-07-29 06:11:54 +02:00
else
minetest.chat_send_player ( name , S ( " Usage: /tpn allows you to deny teleport requests sent to you by other players. " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( name ) , S ( " Usage: /tpn allows you to deny teleport requests sent to you by other players. " ) , 0xFFFFFF )
end
2019-07-29 04:31:24 +02:00
return
2014-07-26 08:20:32 +02:00
end
end
2014-07-30 04:30:37 +02:00
2019-07-12 03:43:42 +02:00
-- Teleport Accept Systems
2019-08-06 06:04:38 +02:00
function tp . tpr_accept ( name , param )
2019-07-09 03:23:57 +02:00
-- Check to prevent constant teleporting.
2019-08-16 19:09:41 +02:00
if not tp.tpr_list [ name ] and not tp.tphr_list [ name ] then
2019-08-06 06:07:02 +02:00
minetest.chat_send_player ( name , S ( " Usage: /tpy allows you to accept teleport requests sent to you by other players " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( name ) , S ( " Usage: /tpy allows you to accept teleport requests sent to you by other players " ) , 0xFFFFFF )
end
2014-07-26 08:20:32 +02:00
return
end
2019-08-03 02:31:03 +02:00
2019-08-06 06:04:38 +02:00
if tp.tpr_list [ name ] then
name2 = tp.tpr_list [ name ]
2014-12-09 04:03:30 +01:00
source = minetest.get_player_by_name ( name )
2019-08-06 06:04:38 +02:00
target = minetest.get_player_by_name ( name2 )
chatmsg = S ( " @1 is teleporting to you. " , name2 )
tp.tpr_list [ name ] = nil
2019-12-02 02:11:07 +01:00
2019-08-06 06:04:38 +02:00
elseif tp.tphr_list [ name ] then
name2 = tp.tphr_list [ name ]
source = minetest.get_player_by_name ( name2 )
2014-12-09 04:03:30 +01:00
target = minetest.get_player_by_name ( name )
2019-08-06 06:04:38 +02:00
chatmsg = S ( " You are teleporting to @1. " , name2 )
tp.tphr_list [ name ] = nil
2014-07-30 06:01:44 +02:00
else
2014-07-26 08:20:32 +02:00
return
end
2019-08-03 02:31:03 +02:00
2014-07-30 06:01:44 +02:00
-- Could happen if either player disconnects (or timeout); if so just abort
2015-08-28 22:08:16 +02:00
if not source
or not target then
2019-08-06 06:04:38 +02:00
minetest.chat_send_player ( name , S ( " @1 doesn't exist, or just disconnected/left (by timeout). " , name2 ) )
2019-12-02 02:11:07 +01:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( name ) , S ( " @1 doesn't exist, or just disconnected/left (by timeout). " , name2 ) , 0xFFFFFF )
end
2014-07-26 08:20:32 +02:00
return
end
2019-12-02 02:11:07 +01:00
2019-08-06 06:04:38 +02:00
tp.tpr_teleport_player ( )
minetest.chat_send_player ( name2 , S ( " Request Accepted! " ) )
2019-08-03 02:31:03 +02:00
minetest.chat_send_player ( name , chatmsg )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( name2 ) , S ( " Request Accepted! " ) , 0xFFFFFF )
chat2.send_message ( minetest.get_player_by_name ( name ) , chatmsg , 0xFFFFFF )
end
2014-07-26 08:20:32 +02:00
end
2016-05-18 13:40:42 +02:00
-- Teleport Jump - Relative Position Teleportation by number of nodes
2019-08-06 06:04:38 +02:00
function tp . tpj ( player , param )
2016-05-18 13:40:42 +02:00
local pname = minetest.get_player_by_name ( player )
2016-05-19 00:47:49 +02:00
2016-05-18 13:40:42 +02:00
if param == " " then
2019-08-07 05:19:30 +02:00
minetest.chat_send_player ( player , S ( " Usage: <x|y|z> <number> " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Usage: <x|y|z> <number> " ) , 0xFFFFFF )
end
2016-05-18 13:40:42 +02:00
return false
end
2016-05-19 00:47:49 +02:00
2016-05-18 23:17:05 +02:00
local args = param : split ( " " ) -- look into this. Can it crash if the player does not have two parameters?
2016-05-18 13:40:42 +02:00
if # args < 2 then
2019-08-07 05:19:30 +02:00
minetest.chat_send_player ( player , S ( " Usage: <x|y|z> <number> " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Usage: <x|y|z> <number> " ) , 0xFFFFFF )
end
2016-05-18 13:40:42 +02:00
return false
end
if not tonumber ( args [ 2 ] ) then
2019-12-02 02:11:07 +01:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Not a number! " ) , 0xFFFFFF )
end
2019-07-25 23:07:39 +02:00
return false , S ( " Not a number! " )
2016-05-18 13:40:42 +02:00
end
-- Initially generate the target coords from the player's current position (since it's relative) and then perform the math.
2019-07-25 21:53:20 +02:00
target_coords = minetest.get_player_by_name ( player ) : get_pos ( )
2016-05-18 13:40:42 +02:00
if args [ 1 ] == " x " then
target_coords [ " x " ] = target_coords [ " x " ] + tonumber ( args [ 2 ] )
elseif args [ 1 ] == " y " then
target_coords [ " y " ] = target_coords [ " y " ] + tonumber ( args [ 2 ] )
elseif args [ 1 ] == " z " then
target_coords [ " z " ] = target_coords [ " z " ] + tonumber ( args [ 2 ] )
else
2019-08-07 05:19:30 +02:00
minetest.chat_send_player ( player , S ( " Not a valid axis. Valid options are X, Y or Z " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Not a valid axis. Valid options are X, Y or Z " ) , 0xFFFFFF )
end
2019-03-24 16:38:32 +01:00
return
end
2019-12-02 02:11:07 +01:00
2019-08-06 06:04:38 +02:00
if tp.can_teleport ( target_coords ) == false then
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( player , S ( " You cannot teleport to a location outside the map! " ) )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " You cannot teleport to a location outside the map! " ) , 0xFFFFFF )
end
2019-03-24 16:38:32 +01:00
return
2016-05-18 13:40:42 +02:00
end
2019-08-06 06:04:38 +02:00
tp.tpc_teleport_player ( player )
2016-05-18 13:40:42 +02:00
end
2016-05-18 13:16:48 +02:00
2016-05-18 21:10:23 +02:00
-- Evade
2019-08-06 06:04:38 +02:00
function tp . tpe ( player )
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " EVADE! " ) , 0xFFFFFF )
end
2019-07-15 20:52:31 +02:00
minetest.chat_send_player ( player , S ( " EVADE! " ) )
2016-05-19 00:59:28 +02:00
local mindistance = 15
local maxdistance = 50
2016-05-19 00:47:49 +02:00
local times = math.random ( 6 , 20 ) -- how many times to jump - minimum,maximum
2016-05-18 23:10:58 +02:00
local negatives = { ' - ' , ' ' } -- either it's this way or that way: the difference between -10 and 10
2016-05-18 22:48:43 +02:00
local options = { ' x ' , ' y ' , ' z ' }
2016-05-18 22:31:08 +02:00
local isnegative = ' '
local distance = 0
local axis = ' '
2016-05-19 00:52:26 +02:00
local iteration = 0
2016-05-18 21:10:23 +02:00
for i = 1 , times do
2016-05-18 22:31:08 +02:00
-- do this every 1 second
2016-05-19 00:47:49 +02:00
minetest.after ( iteration ,
2016-05-18 22:31:08 +02:00
function ( )
2016-05-18 22:48:43 +02:00
isnegative = negatives [ math.random ( 2 ) ] -- choose randomly whether this is this way or that
2016-05-18 22:31:08 +02:00
distance = isnegative .. math.random ( mindistance , maxdistance ) -- the distance to jump
axis = options [ math.random ( 3 ) ]
2016-05-19 00:47:49 +02:00
local command = axis .. " " .. distance
2019-08-06 06:04:38 +02:00
tp.tpj ( player , command )
2016-05-18 22:31:08 +02:00
end
)
2016-05-19 00:47:49 +02:00
iteration = iteration + 0.5
2016-05-18 21:10:23 +02:00
end
end
2020-01-02 03:00:50 +01:00
-- Teleport To Place (TPP) system.
2019-08-06 06:04:38 +02:00
if tp.enable_tpp_command then
2020-01-02 03:00:50 +01:00
function tp . tpp ( player , param )
local pname = minetest.get_player_by_name ( player )
2019-07-18 01:04:52 +02:00
2020-01-02 03:00:50 +01:00
-- Show the available places to the player (taken from shivajiva101's POI mod, thanks!).
if param == " " then
local places = { }
if not tp.available_places then tp.available_places = { } end
for key , value in pairs ( tp.available_places ) do
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , key , 0xFFFFFF )
2019-07-18 01:04:52 +02:00
end
2020-01-02 03:00:50 +01:00
table.insert ( places , key )
end
if # places == 0 then
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " There are no places yet. " ) , 0xFFFFFF )
2019-07-18 01:04:52 +02:00
end
2020-01-02 03:00:50 +01:00
return true , S ( " There are no places yet. " )
end
2019-08-07 05:19:30 +02:00
if minetest.get_modpath ( " chat2 " ) then
2020-01-02 03:00:50 +01:00
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Usage: /tpp <place> " ) , 0xFFFFFF )
2019-12-02 02:11:07 +01:00
end
2020-01-02 03:00:50 +01:00
table.insert ( places , S ( " Usage: /tpp <place> " ) )
return true , table.concat ( places , " \n " )
-- Teleport player to the specified place (taken from shivajiva101's POI mod, thanks!).
elseif tp.available_places [ param ] then
pos = { x = tp.available_places [ param ] . x , y = tp.available_places [ param ] . y , z = tp.available_places [ param ] . z }
tp.tpp_teleport_player ( player )
minetest.chat_send_player ( player , S ( " Teleporting to @1. " , param ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " Teleporting to @1. " , param ) , 0xFFFFFF )
end
2019-12-02 02:11:07 +01:00
2020-01-02 03:00:50 +01:00
-- Check if the place exists.
elseif not tp.available_places [ param ] then
minetest.chat_send_player ( player , S ( " There is no place by that name. Keep in mind this is case-sensitive. " ) )
if minetest.get_modpath ( " chat2 " ) then
chat2.send_message ( minetest.get_player_by_name ( player ) , S ( " There is no place by that name. Keep in mind this is case-sensitive. " ) , 0xFFFFFF )
2019-07-18 01:04:52 +02:00
end
2020-01-02 03:00:50 +01:00
return
end
end
minetest.register_chatcommand ( " tpp " , {
description = S ( " Teleport to a place (i.e., spawn, shop). " ) ,
params = S ( " <place> | leave empty to see available places " ) ,
privs = { } ,
func = tp.tpp
2019-07-18 01:04:52 +02:00
} )
end
2020-01-02 03:00:50 +01:00
-- Register chatcommands
2014-07-26 08:20:32 +02:00
minetest.register_chatcommand ( " tpr " , {
2019-07-15 20:52:31 +02:00
description = S ( " Request teleport to another player " ) ,
2019-07-16 21:26:28 +02:00
params = S ( " <playername> | leave playername empty to see help message " ) ,
2019-07-09 03:23:57 +02:00
privs = { interact = true , tp = true } ,
2019-08-06 06:04:38 +02:00
func = tp.tpr_send
2014-07-26 08:20:32 +02:00
} )
minetest.register_chatcommand ( " tphr " , {
2019-07-15 20:52:31 +02:00
description = S ( " Request player to teleport to you " ) ,
2019-07-16 21:26:28 +02:00
params = S ( " <playername> | leave playername empty to see help message " ) ,
2019-07-09 03:23:57 +02:00
privs = { interact = true , tp = true } ,
2019-08-06 06:04:38 +02:00
func = tp.tphr_send
2014-07-26 08:20:32 +02:00
} )
2016-05-10 17:11:31 +02:00
minetest.register_chatcommand ( " tpc " , {
2019-07-15 20:52:31 +02:00
description = S ( " Teleport to coordinates " ) ,
2019-07-16 21:26:28 +02:00
params = S ( " <coordinates> | leave coordinates empty to see help message " ) ,
2019-07-09 03:30:16 +02:00
privs = { interact = true , tp_tpc = true , tp = true } ,
2019-08-06 06:04:38 +02:00
func = tp.tpc_send
2016-05-10 17:11:31 +02:00
} )
2016-05-18 13:40:42 +02:00
minetest.register_chatcommand ( " tpj " , {
2019-07-15 20:52:31 +02:00
description = S ( " Teleport to relative position " ) ,
2019-07-16 21:26:28 +02:00
params = S ( " <axis> <distance> | leave empty to see help message " ) ,
2019-07-09 03:30:16 +02:00
privs = { interact = true , tp_tpc = true , tp = true } ,
2019-08-06 06:04:38 +02:00
func = tp.tpj
2016-05-18 13:40:42 +02:00
} )
2016-05-18 21:10:23 +02:00
minetest.register_chatcommand ( " tpe " , {
2019-07-15 20:52:31 +02:00
description = S ( " Evade Enemy " ) ,
2019-07-09 03:30:16 +02:00
privs = { interact = true , tp_tpc = true , tp = true } ,
2019-08-06 06:04:38 +02:00
func = tp.tpe
2016-05-18 21:10:23 +02:00
} )
2014-07-26 08:20:32 +02:00
minetest.register_chatcommand ( " tpy " , {
2019-07-15 20:52:31 +02:00
description = S ( " Accept teleport requests from another player " ) ,
2019-07-09 03:23:57 +02:00
privs = { interact = true , tp = true } ,
2019-08-06 06:04:38 +02:00
func = tp.tpr_accept
2014-07-26 08:20:32 +02:00
} )
minetest.register_chatcommand ( " tpn " , {
2019-07-15 20:52:31 +02:00
description = S ( " Deny teleport requests from another player " ) ,
2019-07-09 03:23:57 +02:00
privs = { interact = true , tp = true } ,
2019-08-06 06:04:38 +02:00
func = tp.tpr_deny
2014-07-26 08:20:32 +02:00
} )
2014-07-30 04:30:37 +02:00
2019-07-09 03:23:57 +02:00
-- Log
2019-07-15 20:52:31 +02:00
if minetest.settings : get_bool ( " log_mods " ) then
2019-08-06 06:04:38 +02:00
minetest.log ( " action " , S ( " [Teleport Request] TPS Teleport v@1 Loaded! " , tp.version ) )
2019-07-15 20:52:31 +02:00
end