2014-11-09 19:20:46 +00:00
|
|
|
|
2015-11-05 09:24:54 +00:00
|
|
|
--= Teleport Potion mod 0.5 by TenPlus1
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- Create teleport potion or pad, place then right-click to enter coords
|
|
|
|
-- and step onto pad or walk into the blue portal light, portal closes after
|
2015-11-05 09:24:54 +00:00
|
|
|
-- 10 seconds, pad remains, potions are throwable... SFX are license Free...
|
2014-11-09 19:20:46 +00:00
|
|
|
|
|
|
|
teleport = {}
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- teleport portal recipe
|
2014-11-09 19:20:46 +00:00
|
|
|
minetest.register_craft({
|
2015-11-05 09:24:54 +00:00
|
|
|
output = 'teleport_potion:potion',
|
|
|
|
recipe = {
|
|
|
|
{"", "default:diamond", ""},
|
|
|
|
{"default:diamond", "vessels:glass_bottle", "default:diamond"},
|
|
|
|
{"", "default:diamond", ""},
|
|
|
|
},
|
2014-11-09 19:20:46 +00:00
|
|
|
})
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- teleport pad recipe
|
2014-11-09 19:20:46 +00:00
|
|
|
minetest.register_craft({
|
|
|
|
output = 'teleport_potion:pad',
|
|
|
|
recipe = {
|
|
|
|
{"teleport_potion:potion", 'default:glass', "teleport_potion:potion"},
|
|
|
|
{"default:glass", "default:mese", "default:glass"},
|
|
|
|
{"teleport_potion:potion", "default:glass", "teleport_potion:potion"}
|
|
|
|
}
|
2015-05-25 13:32:50 +01:00
|
|
|
})
|
2015-05-12 18:08:01 +01:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- default coords (from static spawnpoint or default values at end)
|
|
|
|
teleport.default = (minetest.setting_get_pos("static_spawnpoint") or {x = 0, y = 2, z = 0})
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- teleport portal
|
2014-11-09 19:20:46 +00:00
|
|
|
minetest.register_node("teleport_potion:portal", {
|
|
|
|
drawtype = "plantlike",
|
2015-07-05 16:47:35 +01:00
|
|
|
tiles = {
|
|
|
|
{name="portal.png",
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 16,
|
|
|
|
aspect_h = 16,
|
|
|
|
length = 1.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-11-18 10:10:03 +00:00
|
|
|
light_source = 13,
|
2014-11-09 19:20:46 +00:00
|
|
|
walkable = false,
|
2015-05-12 18:08:01 +01:00
|
|
|
paramtype = "light",
|
2014-11-09 19:20:46 +00:00
|
|
|
pointable = false,
|
|
|
|
buildable_to = true,
|
|
|
|
waving = 1,
|
|
|
|
sunlight_propagates = true,
|
2015-09-08 16:56:22 +01:00
|
|
|
damage_per_second = 1, -- walking into portal also hurts player
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- start timer when portal appears
|
2014-11-09 19:20:46 +00:00
|
|
|
on_construct = function(pos)
|
2015-03-07 09:23:06 +00:00
|
|
|
minetest.get_node_timer(pos):start(10)
|
2014-11-09 19:20:46 +00:00
|
|
|
end,
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- remove portal after 10 seconds
|
2014-11-09 19:20:46 +00:00
|
|
|
on_timer = function(pos)
|
2015-11-18 10:10:03 +00:00
|
|
|
|
2015-07-05 16:47:35 +01:00
|
|
|
minetest.sound_play("portal_close", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 10
|
|
|
|
})
|
2015-11-18 10:10:03 +00:00
|
|
|
|
2015-07-05 16:47:35 +01:00
|
|
|
minetest.set_node(pos, {name = "air"})
|
2014-11-09 19:20:46 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- teleport potion
|
2014-11-09 19:20:46 +00:00
|
|
|
minetest.register_node("teleport_potion:potion", {
|
2015-10-16 11:29:25 +01:00
|
|
|
tiles = {"pad.png"},
|
2014-11-09 19:20:46 +00:00
|
|
|
drawtype = "signlike",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "wallmounted",
|
|
|
|
walkable = false,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
description="Teleport Potion (place and right-click to enchant location)",
|
|
|
|
inventory_image = "potion.png",
|
|
|
|
wield_image = "potion.png",
|
2015-07-05 16:47:35 +01:00
|
|
|
groups = {snappy = 3, dig_immediate = 3},
|
|
|
|
selection_box = {type = "wallmounted"},
|
2014-11-09 19:20:46 +00:00
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
|
2015-03-07 09:23:06 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- text entry formspec
|
2014-11-09 19:20:46 +00:00
|
|
|
meta:set_string("formspec", "field[text;;${text}]")
|
|
|
|
meta:set_string("infotext", "Enter teleport coords (e.g 200,20,-200)")
|
|
|
|
meta:set_string("text", teleport.default.x..","..teleport.default.y..","..teleport.default.z)
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- set default coords
|
2014-11-09 19:20:46 +00:00
|
|
|
meta:set_float("x", teleport.default.x)
|
|
|
|
meta:set_float("y", teleport.default.y)
|
|
|
|
meta:set_float("z", teleport.default.z)
|
|
|
|
end,
|
|
|
|
|
2015-11-18 10:10:03 +00:00
|
|
|
-- throw potion when used like tool
|
2015-11-05 09:24:54 +00:00
|
|
|
on_use = function(itemstack, user)
|
2015-11-04 19:34:58 +00:00
|
|
|
|
2015-11-05 09:24:54 +00:00
|
|
|
throw_potion(itemstack, user)
|
2015-11-04 19:34:58 +00:00
|
|
|
|
2015-11-05 09:24:54 +00:00
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
itemstack:take_item()
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
end,
|
2015-11-04 19:34:58 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- check if coords ok then open portal, otherwise return potion
|
2014-11-09 19:20:46 +00:00
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
|
|
|
|
local coords = teleport.coordinates(fields.text)
|
2015-03-07 09:23:06 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-11-09 19:20:46 +00:00
|
|
|
local name = sender:get_player_name()
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
if coords then
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-16 14:55:33 +01:00
|
|
|
minetest.set_node(pos, {name = "teleport_potion:portal"})
|
2014-11-09 19:20:46 +00:00
|
|
|
|
|
|
|
local newmeta = minetest.get_meta(pos)
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- set portal destination
|
2014-11-09 19:20:46 +00:00
|
|
|
newmeta:set_float("x", coords.x)
|
|
|
|
newmeta:set_float("y", coords.y)
|
|
|
|
newmeta:set_float("z", coords.z)
|
|
|
|
newmeta:set_string("text", fields.text)
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- portal open effect and sound
|
2015-09-11 21:20:30 +01:00
|
|
|
tp_effect(pos)
|
2015-09-08 16:56:22 +01:00
|
|
|
|
2015-07-05 16:47:35 +01:00
|
|
|
minetest.sound_play("portal_open", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 10
|
|
|
|
})
|
2014-11-09 19:20:46 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, 'Potion failed!')
|
2015-07-05 16:47:35 +01:00
|
|
|
minetest.set_node(pos, {name = "air"})
|
2015-03-07 09:23:06 +00:00
|
|
|
minetest.add_item(pos, 'teleport_potion:potion')
|
2014-11-09 19:20:46 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- teleport pad
|
2014-11-09 19:20:46 +00:00
|
|
|
minetest.register_node("teleport_potion:pad", {
|
2015-10-16 11:29:25 +01:00
|
|
|
tiles = {"padd.png"},
|
2014-11-09 19:20:46 +00:00
|
|
|
drawtype = 'nodebox',
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "wallmounted",
|
2015-11-23 11:46:34 +00:00
|
|
|
legacy_wallmounted = true,
|
2014-11-09 19:20:46 +00:00
|
|
|
walkable = true,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
description="Teleport Pad (place and right-click to enchant location)",
|
|
|
|
inventory_image = "padd.png",
|
|
|
|
wield_image = "padd.png",
|
|
|
|
light_source = 5,
|
2015-09-08 16:56:22 +01:00
|
|
|
groups = {snappy = 3},
|
2014-11-09 19:20:46 +00:00
|
|
|
node_box = {
|
|
|
|
type = "wallmounted",
|
|
|
|
wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
|
|
|
|
wall_bottom = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5},
|
|
|
|
wall_side = {-0.5, -0.5, -0.5, -0.4375, 0.5, 0.5},
|
|
|
|
},
|
|
|
|
selection_box = {type = "wallmounted"},
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
|
2015-03-07 09:23:06 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- text entry formspec
|
2014-11-09 19:20:46 +00:00
|
|
|
meta:set_string("formspec", "field[text;;${text}]")
|
|
|
|
meta:set_string("infotext", "Enter teleport coords (e.g 200,20,-200)")
|
2015-11-18 10:10:03 +00:00
|
|
|
meta:set_string("text", teleport.default.x
|
|
|
|
.. "," .. teleport.default.y
|
|
|
|
.. "," .. teleport.default.z)
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- set default coords
|
2014-11-09 19:20:46 +00:00
|
|
|
meta:set_float("x", teleport.default.x)
|
|
|
|
meta:set_float("y", teleport.default.y)
|
|
|
|
meta:set_float("z", teleport.default.z)
|
|
|
|
end,
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- right-click to enter new coords
|
2014-11-09 19:20:46 +00:00
|
|
|
on_right_click = function(pos, placer)
|
2015-03-07 09:23:06 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-11-09 19:20:46 +00:00
|
|
|
end,
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- once entered, check coords, if ok then return potion
|
2014-11-09 19:20:46 +00:00
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
|
|
|
|
local coords = teleport.coordinates(fields.text)
|
2015-03-07 09:23:06 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-11-09 19:20:46 +00:00
|
|
|
local name = sender:get_player_name()
|
|
|
|
|
|
|
|
if minetest.is_protected(pos, name) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
if coords then
|
2014-11-09 19:20:46 +00:00
|
|
|
|
|
|
|
local newmeta = minetest.get_meta(pos)
|
|
|
|
|
|
|
|
newmeta:set_float("x", coords.x)
|
|
|
|
newmeta:set_float("y", coords.y)
|
|
|
|
newmeta:set_float("z", coords.z)
|
|
|
|
newmeta:set_string("text", fields.text)
|
|
|
|
|
|
|
|
meta:set_string("infotext", "Pad Active ("..coords.x..","..coords.y..","..coords.z..")")
|
2015-07-05 16:47:35 +01:00
|
|
|
minetest.sound_play("portal_open", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 10
|
|
|
|
})
|
2014-11-09 19:20:46 +00:00
|
|
|
|
|
|
|
else
|
2015-07-05 16:47:35 +01:00
|
|
|
minetest.chat_send_player(name, 'Teleport Pad coordinates failed!')
|
2014-11-09 19:20:46 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
teleport.coordinates = function(str)
|
|
|
|
|
2015-11-18 10:10:03 +00:00
|
|
|
if not str or str == "" then
|
|
|
|
return nil
|
|
|
|
end
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- get coords from string
|
2015-07-05 16:47:35 +01:00
|
|
|
local x, y, z = string.match(str, "^(-?%d+),(-?%d+),(-?%d+)")
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- check coords
|
2015-07-05 16:47:35 +01:00
|
|
|
if x == nil or string.len(x) > 6
|
|
|
|
or y == nil or string.len(y) > 6
|
|
|
|
or z == nil or string.len(z) > 6 then
|
2014-11-09 19:20:46 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- convert string coords to numbers
|
|
|
|
x = tonumber(x)
|
|
|
|
y = tonumber(y)
|
|
|
|
z = tonumber(z)
|
2014-11-09 19:20:46 +00:00
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- are coords in map range ?
|
2014-11-09 19:20:46 +00:00
|
|
|
if x > 30900 or x < -30900
|
|
|
|
or y > 30900 or y < -30900
|
|
|
|
or z > 30900 or z < -30900 then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- return ok coords
|
2015-07-05 16:47:35 +01:00
|
|
|
return {x = x, y = y, z = z}
|
2014-11-09 19:20:46 +00:00
|
|
|
end
|
|
|
|
|
2015-09-08 16:56:22 +01:00
|
|
|
-- particle effects
|
2015-09-11 21:20:30 +01:00
|
|
|
function tp_effect(pos)
|
2015-09-08 16:56:22 +01:00
|
|
|
minetest.add_particlespawner({
|
|
|
|
amount = 20,
|
|
|
|
time = 0.25,
|
|
|
|
minpos = pos,
|
|
|
|
maxpos = pos,
|
|
|
|
minvel = {x = -2, y = -2, z = -2},
|
|
|
|
maxvel = {x = 2, y = 2, z = 2},
|
|
|
|
minacc = {x = -4, y = -4, z = -4},
|
|
|
|
maxacc = {x = 4, y = 4, z = 4},
|
|
|
|
minexptime = 0.1,
|
|
|
|
maxexptime = 1,
|
|
|
|
minsize = 0.5,
|
|
|
|
maxsize = 1,
|
|
|
|
texture = "particle.png",
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- check pad and teleport objects on top
|
2014-11-09 19:20:46 +00:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"teleport_potion:portal", "teleport_potion:pad"},
|
2015-09-08 16:56:22 +01:00
|
|
|
interval = 1,
|
2014-11-09 19:20:46 +00:00
|
|
|
chance = 1,
|
2015-11-07 20:54:57 +00:00
|
|
|
catch_up = false,
|
2014-11-09 19:20:46 +00:00
|
|
|
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2015-09-08 16:56:22 +01:00
|
|
|
|
|
|
|
-- check objects inside pad/portal
|
2015-03-07 09:23:06 +00:00
|
|
|
local objs = minetest.get_objects_inside_radius(pos, 1)
|
2015-11-18 10:10:03 +00:00
|
|
|
|
|
|
|
if #objs == 0 then
|
|
|
|
return
|
|
|
|
end
|
2015-09-08 16:56:22 +01:00
|
|
|
|
|
|
|
-- get coords from pad/portal
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local target_coords = {
|
|
|
|
x = meta:get_float("x"),
|
|
|
|
y = meta:get_float("y"),
|
|
|
|
z = meta:get_float("z")
|
|
|
|
}
|
|
|
|
|
2014-11-09 19:20:46 +00:00
|
|
|
for k, player in pairs(objs) do
|
2015-09-08 16:56:22 +01:00
|
|
|
if player:get_player_name() then
|
|
|
|
|
|
|
|
-- play sound on portal end
|
2015-07-05 16:47:35 +01:00
|
|
|
minetest.sound_play("portal_close", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 5
|
|
|
|
})
|
2015-09-08 16:56:22 +01:00
|
|
|
|
|
|
|
-- move player/object
|
2014-11-09 19:20:46 +00:00
|
|
|
player:moveto(target_coords, false)
|
2015-09-08 16:56:22 +01:00
|
|
|
|
|
|
|
-- paricle effects on arrival
|
2015-09-11 21:20:30 +01:00
|
|
|
tp_effect(target_coords)
|
2015-09-08 16:56:22 +01:00
|
|
|
|
|
|
|
-- play sound on destination end
|
2015-07-05 16:47:35 +01:00
|
|
|
minetest.sound_play("portal_close", {
|
|
|
|
pos = target_coords,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 5
|
|
|
|
})
|
2014-11-09 19:20:46 +00:00
|
|
|
end
|
|
|
|
end
|
2015-09-08 16:56:22 +01:00
|
|
|
end
|
2015-11-04 19:34:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Throwable potions
|
|
|
|
|
|
|
|
local potion_entity = {
|
2015-11-05 09:24:54 +00:00
|
|
|
physical = true,
|
2015-11-04 19:34:58 +00:00
|
|
|
visual = "sprite",
|
|
|
|
visual_size = {x = 1.0, y = 1.0},
|
|
|
|
textures = {"potion.png"},
|
|
|
|
collisionbox = {0,0,0,0,0,0},
|
|
|
|
lastpos = {},
|
|
|
|
player = "",
|
|
|
|
}
|
|
|
|
|
|
|
|
potion_entity.on_step = function(self, dtime)
|
|
|
|
|
|
|
|
if not self.player then
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local pos = self.object:getpos()
|
|
|
|
|
|
|
|
if self.lastpos.x ~= nil then
|
|
|
|
|
2015-11-05 09:24:54 +00:00
|
|
|
local vel = self.object:getvelocity()
|
|
|
|
|
|
|
|
-- only when potion hits something physical
|
|
|
|
if vel.x == 0
|
|
|
|
or vel.y == 0
|
|
|
|
or vel.z == 0 then
|
2015-11-04 19:34:58 +00:00
|
|
|
|
|
|
|
if self.player ~= "" then
|
2015-11-05 09:24:54 +00:00
|
|
|
|
|
|
|
-- round up coords to fix glitching through doors
|
|
|
|
self.lastpos = vector.round(self.lastpos)
|
|
|
|
|
2015-11-04 19:34:58 +00:00
|
|
|
self.player:setpos(self.lastpos)
|
|
|
|
|
|
|
|
minetest.sound_play("portal_close", {
|
|
|
|
pos = self.lastpos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 5
|
|
|
|
})
|
|
|
|
|
|
|
|
tp_effect(self.lastpos)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.lastpos = pos
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_entity("teleport_potion:potion_entity", potion_entity)
|
|
|
|
|
|
|
|
function throw_potion(itemstack, player)
|
|
|
|
|
|
|
|
local playerpos = player:getpos()
|
|
|
|
|
|
|
|
local obj = minetest.add_entity({
|
|
|
|
x = playerpos.x,
|
|
|
|
y = playerpos.y + 1.5,
|
|
|
|
z = playerpos.z
|
|
|
|
}, "teleport_potion:potion_entity")
|
|
|
|
|
|
|
|
local dir = player:get_look_dir()
|
|
|
|
local velocity = 20
|
|
|
|
|
|
|
|
obj:setvelocity({
|
|
|
|
x = dir.x * velocity,
|
|
|
|
y = dir.y * velocity,
|
|
|
|
z = dir.z * velocity
|
|
|
|
})
|
|
|
|
|
|
|
|
obj:setacceleration({
|
|
|
|
x = dir.x * -3,
|
|
|
|
y = -9.5,
|
|
|
|
z = dir.z * -3
|
|
|
|
})
|
|
|
|
|
|
|
|
obj:setyaw(player:get_look_yaw() + math.pi)
|
|
|
|
obj:get_luaentity().player = player
|
|
|
|
|
|
|
|
end
|