mirror of
https://codeberg.org/tenplus1/teleport_potion.git
synced 2025-04-30 10:31:41 -04:00
Tweaked and Tidied code
This commit is contained in:
parent
d3363dc728
commit
4ed639de55
1 changed files with 58 additions and 24 deletions
82
init.lua
82
init.lua
|
@ -24,13 +24,22 @@ minetest.register_craft({
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Default coords
|
-- Default coords
|
||||||
teleport.default = {x=0, y=0, z=0}
|
teleport.default = {x = 0, y = 0, z = 0}
|
||||||
|
|
||||||
-- Portal
|
-- Portal
|
||||||
minetest.register_node("teleport_potion:portal", {
|
minetest.register_node("teleport_potion:portal", {
|
||||||
drawtype = "plantlike",
|
drawtype = "plantlike",
|
||||||
tiles = {{name="portal.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=1.0}},},
|
tiles = {
|
||||||
light_source = 12,
|
{name="portal.png",
|
||||||
|
animation = {
|
||||||
|
type = "vertical_frames",
|
||||||
|
aspect_w = 16,
|
||||||
|
aspect_h = 16,
|
||||||
|
length = 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
light_source = default.LIGHT_MAX - 2,
|
||||||
walkable = false,
|
walkable = false,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
pointable = false,
|
pointable = false,
|
||||||
|
@ -46,8 +55,12 @@ minetest.register_node("teleport_potion:portal", {
|
||||||
|
|
||||||
-- Remove portal after 10 seconds
|
-- Remove portal after 10 seconds
|
||||||
on_timer = function(pos)
|
on_timer = function(pos)
|
||||||
minetest.sound_play("portal_close", {pos = pos, gain = 1.0, max_hear_distance = 10,})
|
minetest.sound_play("portal_close", {
|
||||||
minetest.set_node(pos, {name="air"})
|
pos = pos,
|
||||||
|
gain = 1.0,
|
||||||
|
max_hear_distance = 10
|
||||||
|
})
|
||||||
|
minetest.set_node(pos, {name = "air"})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -63,8 +76,8 @@ minetest.register_node("teleport_potion:potion", {
|
||||||
inventory_image = "potion.png",
|
inventory_image = "potion.png",
|
||||||
wield_image = "potion.png",
|
wield_image = "potion.png",
|
||||||
metadata_name = "sign",
|
metadata_name = "sign",
|
||||||
groups = {snappy=3, dig_immediate=3},
|
groups = {snappy = 3, dig_immediate = 3},
|
||||||
selection_box = {type = "wallmounted",},
|
selection_box = {type = "wallmounted"},
|
||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
|
|
||||||
|
@ -96,7 +109,7 @@ minetest.register_node("teleport_potion:potion", {
|
||||||
|
|
||||||
if coords then
|
if coords then
|
||||||
|
|
||||||
minetest.add_node(pos, {name="teleport_potion:portal"})
|
minetest.add_node(pos, {name = "teleport_potion:portal"})
|
||||||
|
|
||||||
local newmeta = minetest.get_meta(pos)
|
local newmeta = minetest.get_meta(pos)
|
||||||
|
|
||||||
|
@ -105,11 +118,15 @@ minetest.register_node("teleport_potion:potion", {
|
||||||
newmeta:set_float("z", coords.z)
|
newmeta:set_float("z", coords.z)
|
||||||
newmeta:set_string("text", fields.text)
|
newmeta:set_string("text", fields.text)
|
||||||
|
|
||||||
minetest.sound_play("portal_open", {pos = pos, gain = 1.0, max_hear_distance = 10,})
|
minetest.sound_play("portal_open", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1.0,
|
||||||
|
max_hear_distance = 10
|
||||||
|
})
|
||||||
|
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, 'Potion failed!')
|
minetest.chat_send_player(name, 'Potion failed!')
|
||||||
minetest.set_node(pos, {name="air"})
|
minetest.set_node(pos, {name = "air"})
|
||||||
minetest.add_item(pos, 'teleport_potion:potion')
|
minetest.add_item(pos, 'teleport_potion:potion')
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -128,7 +145,7 @@ minetest.register_node("teleport_potion:pad", {
|
||||||
wield_image = "padd.png",
|
wield_image = "padd.png",
|
||||||
metadata_name = "sign",
|
metadata_name = "sign",
|
||||||
light_source = 5,
|
light_source = 5,
|
||||||
groups = {snappy=3, dig_immediate=3},
|
groups = {snappy = 3, dig_immediate = 3},
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "wallmounted",
|
type = "wallmounted",
|
||||||
wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
|
wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
|
||||||
|
@ -180,11 +197,14 @@ minetest.register_node("teleport_potion:pad", {
|
||||||
newmeta:set_string("text", fields.text)
|
newmeta:set_string("text", fields.text)
|
||||||
|
|
||||||
meta:set_string("infotext", "Pad Active ("..coords.x..","..coords.y..","..coords.z..")")
|
meta:set_string("infotext", "Pad Active ("..coords.x..","..coords.y..","..coords.z..")")
|
||||||
minetest.sound_play("portal_open", {pos = pos, gain = 1.0, max_hear_distance = 10,})
|
minetest.sound_play("portal_open", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1.0,
|
||||||
|
max_hear_distance = 10
|
||||||
|
})
|
||||||
|
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, 'Teleport Pad Coordinates failed!')
|
minetest.chat_send_player(name, 'Teleport Pad coordinates failed!')
|
||||||
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -195,17 +215,19 @@ teleport.coordinates = function(str)
|
||||||
if not str or str == "" then return nil end
|
if not str or str == "" then return nil end
|
||||||
|
|
||||||
-- Get coords from string
|
-- Get coords from string
|
||||||
local x,y,z = string.match(str, "^(-?%d+),(-?%d+),(-?%d+)")
|
local x, y, z = string.match(str, "^(-?%d+),(-?%d+),(-?%d+)")
|
||||||
|
|
||||||
-- Check coords
|
-- Check coords
|
||||||
if x==nil or string.len(x) > 6
|
if x == nil or string.len(x) > 6
|
||||||
or y==nil or string.len(y) > 6
|
or y == nil or string.len(y) > 6
|
||||||
or z==nil or string.len(z) > 6 then
|
or z == nil or string.len(z) > 6 then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Convert string coords to numbers
|
-- Convert string coords to numbers
|
||||||
x = x + 0.0; y = y + 0.0; z = z + 0.0
|
x = x + 0.0
|
||||||
|
y = y + 0.0
|
||||||
|
z = z + 0.0
|
||||||
|
|
||||||
-- Are coords in map range ?
|
-- Are coords in map range ?
|
||||||
if x > 30900 or x < -30900
|
if x > 30900 or x < -30900
|
||||||
|
@ -215,7 +237,7 @@ teleport.coordinates = function(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return ok coords
|
-- Return ok coords
|
||||||
return {x=x, y=y, z=z}
|
return {x = x, y = y, z = z}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Has player walked inside portal
|
-- Has player walked inside portal
|
||||||
|
@ -230,11 +252,23 @@ minetest.register_abm({
|
||||||
for k, player in pairs(objs) do
|
for k, player in pairs(objs) do
|
||||||
if player:get_player_name() then
|
if player:get_player_name() then
|
||||||
meta = minetest.get_meta(pos)
|
meta = minetest.get_meta(pos)
|
||||||
target_coords={x=meta:get_float("x"), y=meta:get_float("y"), z=meta:get_float("z")}
|
target_coords={
|
||||||
minetest.sound_play("portal_close", {pos = pos, gain = 1.0, max_hear_distance = 5,})
|
x=meta:get_float("x"),
|
||||||
|
y=meta:get_float("y"),
|
||||||
|
z=meta:get_float("z")
|
||||||
|
}
|
||||||
|
minetest.sound_play("portal_close", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1.0,
|
||||||
|
max_hear_distance = 5
|
||||||
|
})
|
||||||
player:moveto(target_coords, false)
|
player:moveto(target_coords, false)
|
||||||
minetest.sound_play("portal_close", {pos = target_coords, gain = 1.0, max_hear_distance = 5,})
|
minetest.sound_play("portal_close", {
|
||||||
|
pos = target_coords,
|
||||||
|
gain = 1.0,
|
||||||
|
max_hear_distance = 5
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
Loading…
Add table
Reference in a new issue