Fix sounds

master
Wuzzy 2020-09-08 21:18:51 +02:00
parent 8103ef270a
commit c0c4d5f627
3 changed files with 11 additions and 6 deletions

View File

@ -119,15 +119,17 @@ function teleports.teleportate(parameters)
if player and player:is_player() and playername~=teleports.lastplayername then if player and player:is_player() and playername~=teleports.lastplayername then
local pos = player:getpos() local pos = player:getpos()
if vector.distance(pos, {x=pos1.x,y=pos1.y+0.5,z=pos1.z}) < 0.52 then if vector.distance(pos, {x=pos1.x,y=pos1.y+0.5,z=pos1.z}) < 0.52 then
minetest.sound_play({name="teleports_teleport", gain=1.0}, {max_hear_distance=16}, true) local dest
if math.random(1, 100) > 5 then if math.random(1, 100) > 5 then
teleports.lastplayername = playername teleports.lastplayername = playername
player:setpos({x=pos2.x,y=pos2.y+0.5,z=pos2.z}) dest = {x=pos2.x,y=pos2.y+0.5,z=pos2.z}
else else
-- Small chance to "miss" destiation by 1 node horizontally to prevent afk players -- Small chance to "miss" destiation by 1 node horizontally to prevent afk players
-- from teleporting forever -- from teleporting forever
player:setpos({x=pos2.x-2+math.random(1, 3),y=pos2.y+0.5,z=pos2.z-2+math.random(1, 3)}) dest = {x=pos2.x-2+math.random(1, 3),y=pos2.y+0.5,z=pos2.z-2+math.random(1, 3)}
end end
player:setpos(dest)
minetest.sound_play({name="teleports_teleport", gain=1.0}, {pos=dest, max_hear_distance=16}, true)
end end
end end
end end
@ -135,12 +137,15 @@ function teleports.do_teleporting(pos1, pos2, playername, delay)
if not delay then if not delay then
teleports.teleportate({pos1, pos2, playername}) teleports.teleportate({pos1, pos2, playername})
else else
minetest.sound_play({name="teleports_charge", gain=0.5}, {max_hear_distance=8}, true) minetest.sound_play({name="teleports_charge", gain=0.5}, {pos=pos1, max_hear_distance=8}, true)
teleports.animate(pos1, playername) teleports.animate(pos1, playername)
minetest.after(delay, teleports.teleportate, {pos1, pos2, playername}) minetest.after(delay, teleports.teleportate, {pos1, pos2, playername})
end end
end end
teleports.set_formspec = function(pos, shown_teleports) teleports.set_formspec = function(pos, shown_teleports)
if not shown_teleports then
shown_teleports = teleports:find_nearby(pos, TELEPORT_SHOW_MAX)
end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
@ -267,8 +272,7 @@ minetest.register_node("teleports:teleport", {
-- Update formspecs of affected teleports -- Update formspecs of affected teleports
for n=1, #near_teleports do for n=1, #near_teleports do
local pos2 = near_teleports[n].pos local pos2 = near_teleports[n].pos
local near_teleports2 = teleports:find_nearby(pos2, TELEPORT_SHOW_MAX) teleports.set_formspec(pos2)
teleports.set_formspec(pos2, near_teleports2)
end end
end, end,
on_receive_fields = teleports.on_receive_fields, on_receive_fields = teleports.on_receive_fields,
@ -322,3 +326,4 @@ minetest.register_craft({
{"default:diamond","default:diamond","default:diamond"}, {"default:diamond","default:diamond","default:diamond"},
} }
}) })

Binary file not shown.

Binary file not shown.