mirror of
https://codeberg.org/tenplus1/teleport_potion.git
synced 2025-04-30 18:41:40 -04:00
Tweaked and Tidied code
This commit is contained in:
parent
d3363dc728
commit
4ed639de55
1 changed files with 58 additions and 24 deletions
58
init.lua
58
init.lua
|
@ -29,8 +29,17 @@ 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,7 +55,11 @@ 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", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1.0,
|
||||||
|
max_hear_distance = 10
|
||||||
|
})
|
||||||
minetest.set_node(pos, {name = "air"})
|
minetest.set_node(pos, {name = "air"})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -64,7 +77,7 @@ minetest.register_node("teleport_potion:potion", {
|
||||||
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)
|
||||||
|
|
||||||
|
@ -105,7 +118,11 @@ 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!')
|
||||||
|
@ -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,
|
||||||
})
|
})
|
||||||
|
@ -205,7 +225,9 @@ teleport.coordinates = function(str)
|
||||||
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
|
||||||
|
@ -230,10 +252,22 @@ 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