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
58
init.lua
58
init.lua
|
@ -29,8 +29,17 @@ teleport.default = {x=0, y=0, z=0}
|
|||
-- Portal
|
||||
minetest.register_node("teleport_potion:portal", {
|
||||
drawtype = "plantlike",
|
||||
tiles = {{name="portal.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=1.0}},},
|
||||
light_source = 12,
|
||||
tiles = {
|
||||
{name="portal.png",
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
length = 1.0
|
||||
}
|
||||
}
|
||||
},
|
||||
light_source = default.LIGHT_MAX - 2,
|
||||
walkable = false,
|
||||
paramtype = "light",
|
||||
pointable = false,
|
||||
|
@ -46,7 +55,11 @@ minetest.register_node("teleport_potion:portal", {
|
|||
|
||||
-- Remove portal after 10 seconds
|
||||
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"})
|
||||
end,
|
||||
})
|
||||
|
@ -64,7 +77,7 @@ minetest.register_node("teleport_potion:potion", {
|
|||
wield_image = "potion.png",
|
||||
metadata_name = "sign",
|
||||
groups = {snappy = 3, dig_immediate = 3},
|
||||
selection_box = {type = "wallmounted",},
|
||||
selection_box = {type = "wallmounted"},
|
||||
|
||||
on_construct = function(pos)
|
||||
|
||||
|
@ -105,7 +118,11 @@ minetest.register_node("teleport_potion:potion", {
|
|||
newmeta:set_float("z", coords.z)
|
||||
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
|
||||
minetest.chat_send_player(name, 'Potion failed!')
|
||||
|
@ -180,11 +197,14 @@ minetest.register_node("teleport_potion:pad", {
|
|||
newmeta:set_string("text", fields.text)
|
||||
|
||||
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
|
||||
minetest.chat_send_player(name, 'Teleport Pad Coordinates failed!')
|
||||
|
||||
minetest.chat_send_player(name, 'Teleport Pad coordinates failed!')
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@ -205,7 +225,9 @@ teleport.coordinates = function(str)
|
|||
end
|
||||
|
||||
-- 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 ?
|
||||
if x > 30900 or x < -30900
|
||||
|
@ -230,10 +252,22 @@ minetest.register_abm({
|
|||
for k, player in pairs(objs) do
|
||||
if player:get_player_name() then
|
||||
meta = minetest.get_meta(pos)
|
||||
target_coords={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,})
|
||||
target_coords={
|
||||
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)
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue