If no acknowledgement is received from the server, the sound is played locally and other players are unable to hear it.
Code: Select all
-- Jump! (CSM)
-- Copyright 2020 James Stevenson
-- GPL 3+
local del = minetest.get_us_time()
local touching = false
local in_water = false
local jumping = false
local p1, p2, ack
local floor = math.floor
local insert = table.insert
local sp = minetest.sound_play
local a = minetest.after
local jump = function(player)
del = minetest.get_us_time()
p2 = player:get_pos()
print(p2.y - p1.y)
a(0, sp, "jump_jump", {
object = player,
})
end
local function poll(player)
player = player or minetest.localplayer
if player then
local j = player:get_control().jump
p1 = player:get_pos()
touching = player:is_touching_ground()
in_water = player:is_in_liquid()
local m = minetest.mod_channel_join(player:get_name())
if not ack then
m:send_all("jump_enable")
end
if j and not touching and not jumping and
not in_water and
minetest.get_us_time() - del > 250000 then
jumping = true
if ack == "disabled" then
jump(player)
else
m:send_all("jump")
end
elseif touching then
jumping = false
end
end
a(0, function()
poll(player)
end)
end
poll()
minetest.register_on_modchannel_message(function(channel_name, sender, message)
if sender == "" and message == "jump_ack" then
ack = "enabled"
end
end)
Spoiler
This will play "jump_jump" when you jump, if it exists. I can't include it with the CSM script, because minetest.sound_play in CSM only works for sounds on the server. Additionally sounds played with minetest.sound_play in CSM only play for the client. This may seem obvious, but it still surprised me.
So next I will add channels to play the jump sound for other connected clients. https://github.com/jastevenson303/ll_csm_jumpsound
Here's a video: https://www.youtube.com/watch?v=xsgc8zjaIzU
So next I will add channels to play the jump sound for other connected clients. https://github.com/jastevenson303/ll_csm_jumpsound
Here's a video: https://www.youtube.com/watch?v=xsgc8zjaIzU