[CSM] Jump Sound [ll_csm_jumpsound]

Post Reply
User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

[CSM] Jump Sound [ll_csm_jumpsound]

by jas » Post

Put play_play in the world (server) somewhere (mod), and send "jump_ack" on your named mod channel after receiving "jump_enable" to utilize positional sound on the server.

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)
jumpsound.zip 21.32KiB
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
Last edited by jas on Sat May 09, 2020 10:40, edited 3 times in total.

User avatar
Lone_Wolf
Member
Posts: 2578
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by Lone_Wolf » Post

If you put a sound in minetest/sounds/ (minetest/textures/ but for sounds) I think you can play it with CSM
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by jas » Post

Thank you, I will test and see. It won't help me package the mod, however, as the user would still need to manually place the file.

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by jas » Post

Updated to work with new CSM.

update: here's a video
https://www.youtube.com/watch?v=RNTCulOfkLM

User avatar
Wuzzy
Member
Posts: 4803
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by Wuzzy » Post

FYI: I added a simple server-side jump sound to Minetest 5.3.0-dev. Just put “player_jump.ogg” into any mod's “sounds” folder.

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by jas » Post

Oh, thank you very much. I have to ask, though, does it play the sound for other players so they can hear that you're jumping around them? I kinda doubt it, thought I'll have to test.

Also, will you please add mouse binds? I still can't right click to jump.

User avatar
Wuzzy
Member
Posts: 4803
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by Wuzzy » Post

No and no.

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by jas » Post

Well thank you, again, for the information, but it's no solution and so if you have any other ideas, let me know.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests