Page 1 of 1

[Mod] Teleporter Mod [1.07] [teleporter]

PostPosted: Sat Jun 23, 2012 02:46
by Bad_Command_
Hi, announcing the teleporter mod. The mod is on github.

The teleporter mod adds teleporter pads to minetest. The pads allow players to teleport around a minetest world in a controllable manner.

mt1.gameboom.net port 30000 makes extensive use of teleporters: it has a teleportation network. Check it out if you want to see these in action. (Go to 0,0,0 if you are near the spawn.)

Downloads:
Version 1.07
Version 1.06

License:
LGPL 2.1 for code
CC0 for media (textures and sounds)

Creating a teleporter pad
A teleporter pad can be crafted using the following recipe:
Image
The recipe uses copper ingots and a gold block from moreores, a power plant from mesecons, and a glass block. If you don't have moreores and mesecons, this recipe works too:
Image
Once a teleporter pad has been made, it can be placed and configured much like a wall sign.

Configuring a teleporter pad
To configure a teleporter pad, right click on the pad and then enter destination coordinates. You can enter a description after the coordinates as well. The coordinates are entered as text in the following format: X,Y,Z,Description. X,Y,Z are the coordinates of the destination.
Image

Using a teleporter pad
In order to use a teleporter, just step on it. If it is properly configured and enabled, you will teleport to the destination.

Configuration options
The teleporter mod has a few options that can be used to restrict the use of teleporters. These options are specified as settings (variables) in config.lua. The options are as follows:

  • teleport_perms_to_build
    When true, a player has to have the teleport permission to build a teleporter. When false, anyone can build a new teleporter.
  • teleport_perms_to_configure
    When true, a player has to have the teleport permission to configure a teleporter. Players can still build teleporters without this, however the teleporter will be locked to the default location.
  • teleport_requires_pairing
    When true, a teleporter can only be configured to teleport to a location near an existing teleporter. This prevents players from pointing teleporters in to unexplored terrain.
  • teleport_pairing_check_radius
    Specifies the size of the volume to scan when looking for a paired teleporter. Do not set this to a large value; the number of nodes scanned increases by a power of 3.
  • teleport_default_coordinates
    Allows for the default coordinates for new a teleporter to be specified. This is useful when players can build new teleporters, but can't configure them.

PostPosted: Sat Jun 23, 2012 03:03
by SegFault22
Can you release a version that doesn't require the privs stuff? I need to test something, but the code here is too long :P

PostPosted: Sat Jun 23, 2012 17:23
by Calinou
Try to stick to 16x16 textures. :P
Also, use vanilla items in the recipes... not everyone wants to install mesecons and moreores to have this mod.

PostPosted: Sat Jun 23, 2012 17:27
by LolManKuba
Calinou wrote:Try to stick to 16x16 textures. :P
Also, use vanilla items in the recipes... not everyone wants to install mesecons and moreores to have this mod.

Now that is true,

PostPosted: Sat Jun 23, 2012 21:07
by Bad_Command_
Calinou wrote:Try to stick to 16x16 textures. :P
Also, use vanilla items in the recipes... not everyone wants to install mesecons and moreores to have this mod.


Ok Calinou, 16x16 texture and default item recipe added.

PostPosted: Sat Jun 23, 2012 22:22
by SegFault22
I don't get how you go about teleporting someone when they are standing on the teleporter pad - what is your ''secret''? (lol)

PostPosted: Sat Jun 23, 2012 22:47
by Bad_Command_
SegFault22 wrote:I don't get how you go about teleporting someone when they are standing on the teleporter pad - what is your ''secret''? (lol)

Nothing secret or hidden in the mod. Take a look at the source code; the code that accomplishes this is neatly contained within the abm. (minetest.register_abm( ... ). Try going through it line-by-line, and understanding what each line does. Remember that the teleporter coordinates are stored in the node metadata.

PostPosted: Sat Jun 23, 2012 23:36
by SegFault22
I have already done that, but I will try again later...
Thank you

PostPosted: Sat Jun 30, 2012 00:51
by RandomBot
well now i can remove the elevators from my space station

PostPosted: Thu Jul 05, 2012 05:52
by Bad_Command_
Version 1.07 released. Contains only minor updates: config options were moved in to config.lua.

PostPosted: Sun Jul 08, 2012 01:44
by Thunder
I fixed up your teleporter a little bit. Things I changed:

added teleporter to creative inventory
allowing destination of default x,y,z
disabled redundant owner message for server
mod tells player where the destination and teleporter are at
mod keeps player off of destination telepad, fixing a very bad glitch

Download the whole thing or replace teleporter/init.lua with this code:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
---
--Teleporter 1.07
--Copyright (C) 2012 Bad_Command
--
--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 program 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 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
----

teleporter = {}
teleporter.version = 1.07

-- config.lua contains configuration parameters
dofile(minetest.get_modpath("teleporter").."/config.lua")

minetest.register_craft({
    output = 'teleporter:teleporter_pad',
    recipe = {
                {'moreores:copper_ingot', 'default:glass', 'moreores:copper_ingot'},
                {'moreores:copper_ingot', 'moreores:gold_block', 'moreores:copper_ingot'},
                {'moreores:copper_ingot', 'mesecons_powerplant:power_plant', 'moreores:copper_ingot'},
        }
})

minetest.register_craft({
    output = 'teleporter:teleporter_pad',
    recipe = {
                {'default:wood', 'default:glass', 'default:wood'},
                {'default:wood', 'default:mese', 'default:wood'},
                {'default:wood', 'default:wood', 'default:wood'},
        }
})

minetest.register_node("teleporter:teleporter_pad", {
    tile_images = {teleporter.tile_image},
    drawtype = "signlike",
    paramtype = "light",
    paramtype2 = "wallmounted",
    walkable = false,
    description="Teleporter Pad",
    inventory_image = teleporter.tile_image,
    metadata_name = "sign",
    --sounds = default.node_sound_defaults(),
    groups = {choppy=2,dig_immediate=2},
    selection_box = {
        type = "wallmounted",
    },
        on_construct = function(pos)
                local meta = minetest.env:get_meta(pos)
                meta:set_string("formspec", "hack:sign_text_input")
                meta:set_string("infotext", ""Teleport to "..teleporter.default_coordinates.desc..""")
        meta:set_string("text", teleporter.default_coordinates.x..","..
            teleporter.default_coordinates.y..","..
            teleporter.default_coordinates.z..","..
            teleporter.default_coordinates.desc)
        meta:set_float("enabled", -1)
        meta:set_float("x", teleporter.default_coordinates.x)
        meta:set_float("y", teleporter.default_coordinates.y)
        meta:set_float("z", teleporter.default_coordinates.z)
        end,
    after_place_node = function(pos, placer)
        local meta = minetest.env:get_meta(pos)
        local name = placer:get_player_name()
        meta:set_string("owner", name)
       
        if teleporter.perms_to_build and not minetest.get_player_privs(name)["teleport"] then
            minetest.chat_send_player(name, 'Teleporter:  Teleport privileges are required to build teleporters.')
            minetest.env:remove_node(pos)
            minetest.env:add_item(pos, 'teleporter:teleporter_pad')
        else
            minetest.chat_send_player(name, 'Teleporter:  My position is '..pos.x..','..pos.y..','..pos.z..'')
            meta:set_float("enabled", 1)
        end

    end,
        on_receive_fields = function(pos, formname, fields, sender)
        local coords = teleporter.coordinates(fields.text)
                local meta = minetest.env:get_meta(pos)
        local name = sender:get_player_name()
        local privs = minetest.get_player_privs(name)

        if name ~= meta:get_string("owner") and not privs["server"] then
            minetest.chat_send_player(name, 'Teleporter:  This is not your teleporter, it belongs to '..meta:get_string("owner"))
            minetest.chat_send_player(name, 'Teleporter:  My position is '..pos.x..','..pos.y..','..pos.z..'')
            return false
        else if name ~= meta:get_string("owner") and privs["server"] then
            minetest.chat_send_player(name, 'Teleporter:  This teleporter belongs to '..meta:get_string("owner"))
        end

        if teleporter.perms_to_configure and not privs["teleport"] then
            minetest.chat_send_player(name, 'Teleporter:  You need teleport privileges to configure a teleporter')
            return
        end

        local infotext = ""
        if coords~=nil then   
            meta:set_float("x", coords.x)
            meta:set_float("y", coords.y)
            meta:set_float("z", coords.z)
            if teleporter.requires_pairing and not teleporter.is_paired(coords) and not privs["server"] then
                minetest.chat_send_player(name, 'Teleporter:  There is no recently-used teleporter pad at the destination!')
                minetest.chat_send_player(name, 'Teleporter:  My position is '..pos.x..','..pos.y..','..pos.z..'')
                        meta:set_string("text", fields.text)
                infotext="Teleporter is Disabled"
                meta:set_float("enabled", -1)
            else
                minetest.chat_send_player(name, 'Teleporter:  Coords set to '..coords.x..','..coords.y..','..coords.z..' from '..pos.x..','..pos.y..','..pos.z..'')
                meta:set_float("enabled", 1)
                if coords.desc~=nil then
                    infotext="Teleport to "..coords.desc
                else
                    infotext="Teleport to "..coords.x..","..coords.y..","..coords.z..""
                end
            end
        else
            minetest.chat_send_player(name, 'Teleporter:  Incorrect coordinates.  Enter them as \'X,Y,Z,Description\' without decimals.')
            meta:set_float("enabled", -1)
            infotext="Teleporter Offline"
        end

                print((sender:get_player_name() or "").." entered ""..fields.text..
                                "" to teleporter at "..minetest.pos_to_string(pos))
                meta:set_string("text", fields.text)
                meta:set_string("infotext", '"'..infotext..'"')
            end
    end,
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos)
        local name = player:get_player_name()
        local privs = minetest.get_player_privs(name)
        if name == meta:get_string("owner") or privs["server"] then
            return true
        end
        return false
    end
})

teleporter.is_paired = function(coords)
    if coords.x==teleporter.default_coordinates.x and coords.y==teleporter.default_coordinates.y and coords.z==teleporter.default_coordinates.z then
        return true
    end
    for dx=-teleporter.pairing_check_radius,teleporter.pairing_check_radius do
        for dy=-teleporter.pairing_check_radius,teleporter.pairing_check_radius do
            for dz=-teleporter.pairing_check_radius,teleporter.pairing_check_radius do
                local node = minetest.env:get_node({x=coords.x + dx, y=coords.y + dy, z=coords.z + dz})
                if node.name == 'teleporter:teleporter_pad' then
                    return true
                end
            end
        end
    end
    return false
end

local function get_nodedef_field(nodename, fieldname)
    if not minetest.registered_nodes[nodename] then
        return nil
    end
    return minetest.registered_nodes[nodename][fieldname]
end

teleporter.get_safe_dest = function(coords)
        local potentialdest=coords
    for dx=-1,1 do
        for dz=-1,1 do
            local p = {x=coords.x + dx, y=coords.y, z=coords.z + dz}
            local node = minetest.env:get_node(p)
            if node.name ~= 'teleporter:teleporter_pad' then
                if get_nodedef_field(node.name, "walkable")==false then
                    return p
                end
                potentialdest=p
            end
        end
    end
    return potentialdest
end

teleporter.coordinates = function(str)
    local x,y,z,desc = string.match(str, "^(-?%d+),(-?%d+),(-?%d+),?(.*)$")
   
    if desc=="" then
        desc = nil
    end

    if x==nil or y==nil or z==nil or
        string.len(x) > 6 or string.len(y) > 6 or string.len(z) > 6 then
            return nil
    end

    x = x + 0.0
    y = y + 0.0
    z = z + 0.0

    if x > 32765 or x < -32765 or y > 32765 or y < -32765 or z > 32765 or z < -32765 then
        return nil
    end

    return {x=x, y=y, z=z, desc=desc}
end


minetest.register_abm(
    {nodenames = {"teleporter:teleporter_pad"},
    interval = 1.0,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        --0.7071 is half of the square root of 2, meaning the inner circle on the telepad
        local objs = minetest.env:get_objects_inside_radius(pos, 0.7071)
        for k, player in pairs(objs) do
            if player:get_player_name()~=nil then
                local meta = minetest.env:get_meta(pos)
                if meta:get_float("enabled") > 0 then
                    local target_coords=teleporter.get_safe_dest({x=meta:get_float("x"), y=meta:get_float("y"), z=meta:get_float("z")})
                    --print('player teleported to '..minetest.pos_to_string(target_coords)..' from '..minetest.pos_to_string(pos))
                    minetest.sound_play("teleporter_teleport", {pos = pos, gain = 1.0, max_hear_distance = 10,})
                    player:moveto(target_coords, false)
                    minetest.sound_play("teleporter_teleport", {pos = target_coords, gain = 1.0, max_hear_distance = 10,})
                end
            end
        end
    end   
})

minetest.add_to_creative_inventory('teleporter:teleporter_pad')

PostPosted: Wed Jul 25, 2012 16:41
by hyudez257
Configuration options
The teleporter mod has a few options that can be used to restrict the use of teleporters. These options are specified as settings (variables) in config.lua. The options are as follows


do you need to configure anything to actually just use the teleporters?

PostPosted: Tue Aug 07, 2012 23:24
by pagliaccio
how i see coord of a point?

PostPosted: Tue Aug 07, 2012 23:26
by jin_xi
press f5

PostPosted: Sun Aug 26, 2012 15:45
by Matsetes
Can you modify it adding name for coordinates? Such as here http://minetest.net/forum/viewtopic.php?id=2321
It's more simple to remember a name than three numbers...

PostPosted: Mon Oct 01, 2012 12:47
by GJH105775
Nice mod.

PostPosted: Sun Oct 21, 2012 16:56
by Actev8
whats you tp

PostPosted: Sat Dec 08, 2012 19:57
by neko259
I have a strange bug with this mod. Sometimes after a teleport I see myself at the same place, but the real coordinates are changed. When I try to go somewhere, I die because in my real (not seen) position I have already teleported and go to a wall or lava.

PostPosted: Mon Dec 31, 2012 20:20
by jojoa1997
can you update this to use the new mese

PostPosted: Mon Dec 31, 2012 23:00
by Zeg9
jojoa1997 wrote:can you update this to use the new mese

It can be crafted with mese blocks if you use the latest minetest_game.
EDIT: Happy new year !

PostPosted: Mon Dec 31, 2012 23:12
by jojoa1997
Zeg9 wrote:
jojoa1997 wrote:can you update this to use the new mese

It can be crafted with mese blocks if you use the latest minetest_game.
EDIT: Happy new year !

i thought it could not with the pictures being so old

Re: [Mod] Teleporter Mod [1.07] [teleporter]

PostPosted: Wed Feb 25, 2015 18:52
by byronarn
What is the center block in the second recipe? The other blocks I have been able to identify as wood and glass. The middle one I am not sure of. Of course, I do use texture packs a lot so that's probably why I cannot identify it...

Help would be appreciated! Thanks.

Re: [Mod] Teleporter Mod [1.07] [teleporter]

PostPosted: Wed Feb 25, 2015 18:55
by Bad_Command_
byronarn wrote:What is the center block in the second recipe? The other blocks I have been able to identify as wood and glass. The middle one I am not sure of. Of course, I do use texture packs a lot so that's probably why I cannot identify it...

Help would be appreciated! Thanks.

It should be mese. I think the texture in the game changed for a little while back when I wrote the mod.

Re: [Mod] Teleporter Mod [1.07] [teleporter]

PostPosted: Wed Feb 25, 2015 19:15
by byronarn
Bad_Command_ wrote:It should be mese. I think the texture in the game changed for a little while back when I wrote the mod.


Thanks for your quick response! Yes, it was Mese. I built the teleporter pad with no problem, but then ran into a problem when I went to set the coordinates. I rightclicked on it, and a grey box showed up, but there was no text entry box. Then it kicked me out of the world and back to the main menu.

Here is what debug.txt says about the incident:
14:11:55: ERROR[main]: ServerError: /home/byron/.minetest/mods/teleporter/init.lua:159: bad argument #1 to 'match' (string expected, got nil)
14:11:55: ERROR[main]: stack traceback:
14:11:55: ERROR[main]: [C]: in function 'match'
14:11:55: ERROR[main]: /home/byron/.minetest/mods/teleporter/init.lua:159: in function 'coordinates'
14:11:55: ERROR[main]: /home/byron/.minetest/mods/teleporter/init.lua:86: in function </home/byron/.minetest/mods/teleporter/init.lua:85>
14:11:55: ACTION[ServerThread]: singleplayer leaves game. List of players:


I tried it a few more times, and each time the same thing happened. What do I have to do to fix this?

Re: [Mod] Teleporter Mod [1.07] [teleporter]

PostPosted: Wed Feb 25, 2015 19:21
by Bad_Command_
It sounds like something has changed in minetest and the teleporter mod needs to updated. It has been a few years since I've played minetest. I'll look in to it more and update the mod it this evening.

Re: [Mod] Teleporter Mod [1.07] [teleporter]

PostPosted: Wed Feb 25, 2015 19:33
by byronarn
Bad_Command_ wrote:It sounds like something has changed in minetest and the teleporter mod needs to updated. It has been a few years since I've played minetest. I'll look in to it more and update the mod it this evening.


Thank you, I would really appreciate it. This mod sounds really interesting and it would be great if we could get it to work with the latest Minetest. :-)

Re: [Mod] Teleporter Mod [1.07] [teleporter]

PostPosted: Thu Feb 26, 2015 08:53
by TenPlus1
Here is a quick fix I did for Clip's server so that BadCommand's Teleporter mod would work on Minetest 0.4.10 and up... Hope it helps...

Re: [Mod] Teleporter Mod [1.07] [teleporter]

PostPosted: Fri Feb 27, 2015 19:59
by byronarn
TenPlus1 wrote:Here is a quick fix I did for Clip's server so that BadCommand's Teleporter mod would work on Minetest 0.4.10 and up... Hope it helps...


Thank you so much. It works. :-)