xmagicx60

tpr

Jan 15th, 2013
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Configuration values:
  2. --Use these to customize this mod
  3. timeout_delay = 30
  4. teleport_delay = 5
  5.  
  6. --DO NOT CHANGE:
  7.  
  8. sender = nil
  9. receiver = nil
  10.  
  11. print ("[Teleport Request] Teleport Request v0.1a Loaded.")
  12.  
  13. --Teleport Request System
  14.  
  15. local function tpr_send(name, param)
  16.  
  17.     --Register variables
  18.  
  19.         sender = name
  20.         receiver = param
  21.     --Check for empty parameter
  22.  
  23.         if receiver == "" then
  24.             minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
  25.             return
  26.         end
  27.  
  28.     --If paremeter is valid, Send teleport message and set the table.
  29.  
  30.         if minetest.env:get_player_by_name(receiver) then
  31.             minetest.chat_send_player(receiver, sender ..' is requesting to teleport to you. /tpy to accept.')
  32.         minetest.chat_send_player(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
  33.    
  34.     --Write name values to list and clear old values.
  35.             tpr_list[receiver] = nil
  36.             tpr_list[receiver] = sender
  37.         --Teleport timeout delay
  38.         minetest.after(timeout_delay, reset_request)
  39.     end
  40. end
  41.  
  42. --Reset after configured delay.
  43.  
  44. function reset_request(name)
  45.  
  46.     --A check to prevent crashing
  47.  
  48.     if tpr_list[receiver] ~= nil then
  49.             tpr_list[receiver] = nil
  50.  
  51.     end
  52.  
  53. end
  54.  
  55. -- Teleport Deny System
  56.  
  57. function tpr_deny(name)
  58.  
  59.     sender = tpr_list[receiver]
  60.  
  61.     if tpr_list[receiver] ~= nil then
  62.             tpr_list[receiver] = nil
  63.         minetest.chat_send_player(sender, 'Teleport request denied :C')
  64.         minetest.chat_send_player(receiver, 'Teleport request denied.')
  65.  
  66.  
  67.     end
  68.  
  69. end
  70.  
  71. --Teleport Accept System
  72.  
  73. local function tpr_accept(name, param)
  74.  
  75.     --Register name variables.
  76.  
  77.     receiver = name
  78.     sender = tpr_list[name]
  79.    
  80.     --Check to prevent constant teleporting.   
  81.  
  82.     if tpr_list[name] == nil then
  83.             minetest.chat_send_player(name, "Usage: /tpy allows you to accept teleport requests sent to you by other players")
  84.  
  85.         return
  86.     end
  87.  
  88.     --Check to ensure name is valid, then send appropriate chat messages
  89.  
  90.     if tpr_list[name] then
  91.         minetest.chat_send_player(tpr_list[receiver], "Request Accepted!")
  92.         minetest.chat_send_player(receiver, sender..' is teleporting to you.')
  93.  
  94.     --Code here copied from Celeron-55's /teleport command. Thanks Celeron!
  95.  
  96.         local function find_free_position_near(pos)
  97.             local tries = {
  98.                 {x=1,y=0,z=0},
  99.                 {x=-1,y=0,z=0},
  100.                 {x=0,y=0,z=1},
  101.                 {x=0,y=0,z=-1},
  102.             }
  103.             for _, d in ipairs(tries) do
  104.                 local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
  105.                 local n = minetest.env:get_node(p)
  106.                 if not minetest.registered_nodes[n.name].walkable then
  107.                     return p, true
  108.                 end
  109.             end
  110.             return pos, false
  111.         end
  112.  
  113.         --Get names from variables and set position.
  114.  
  115.         local requester = minetest.env:get_player_by_name(sender)
  116.         local accepter = minetest.env:get_player_by_name(name)
  117.         local position = nil
  118.  
  119.         position = accepter:getpos()
  120.         position = find_free_position_near(position)
  121.  
  122.         -- Check for a delay, if so, teleport player after specified delay, else, just teleport the player
  123.  
  124.         if teleport_delay ~= 0 then
  125.             minetest.after(teleport_delay, teleport_player, position)
  126.             return
  127.         end
  128.  
  129.         if teleport_delay == 0 then
  130.  
  131.             requester:setpos(p)
  132.             tpr_list[name] = nil
  133.  
  134.         end
  135.  
  136.         -- Set name values to nil to prevent re-teleporting on the same request.
  137.  
  138.     end
  139. end
  140.  
  141. --This is where the problem happens
  142.  
  143. function teleport_player(param)
  144.     requester = tpr_list[receiver]
  145.         print(requester)
  146.         print(param)
  147.         requester:setpos(param)
  148. end
  149.  
  150. --Initalize Table.
  151.  
  152. tpr_list = {}
  153.  
  154. --Initalize Permissions.
  155.  
  156. minetest.register_privilege("tpr", {
  157.     description = "Permission to request teleport to other players.",
  158.     give_to_singleplayer = true
  159. })
  160.  
  161. minetest.register_privilege("tpr_admin", {
  162.     description = "Permission to override teleport to other players. UNFINISHED",
  163.     give_to_singleplayer = true
  164. })
  165.  
  166. --Initalize Commands.
  167.  
  168. minetest.register_chatcommand("tpr", {
  169.     description = "Request teleport to another player",
  170.     params = "<playername> | leave playername empty to see help message",
  171.     privs = {tpr=true},
  172.     func = tpr_send
  173.  
  174. })
  175.  
  176. minetest.register_chatcommand("tpy", {
  177.     description = "Accept teleport requests from another player",
  178.     func = tpr_accept
  179. })
  180.  
  181. minetest.register_chatcommand("tpn", {
  182.     description = "Deny teleport requests from another player",
  183.     func = tpr_deny
  184. })
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×