[CSM] Jump Sound [ll_csm_jumpsound]

User avatar
jas
Member
 
Posts: 464
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

[CSM] Jump Sound [ll_csm_jumpsound]

by jas » Thu Nov 07, 2019 09:44

license: lgpl v2.1+

Code: Select all
local player
local touching = false
local jumping = false
local sp = minetest.sound_play
local a = minetest.after
local floor = math.floor
local insert = table.insert

local jump = function(player)
   a(0, sp, "player_jump", {
      object = player,
   })
end

local function convert(decimal)
   local binary = ""
   while decimal > 0 do
      binary = "" .. (decimal % 2) .. binary
      decimal = floor(decimal / 2)
   end
   local length = binary:len()
   local bits = {}
   for i = length, 1, -1 do
      local bit = tonumber(binary:sub(i, i))
      insert(bits, bit)
   end
   for i = 1, 9 do
      if not bits[i] then
         bits[i] = 0
      end
   end
   return bits
end

local function poll(player)
   if not player then
      player = minetest.localplayer
   end

   if player then
      local j = convert(player:get_key_pressed())[5] == 1
      touching = player:is_touching_ground()

      if j and not touching and not jumping then
         jumping = true
         jump(player)
      elseif touching then
         jumping = false
      end
   end

   a(0, function()
      poll(player)
   end)
end

poll(player)

print("loaded ll_csm_jumpsound")


This will play "player_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
2019-10-14 09:12:51: ACTION[Server]: jas activates
 

User avatar
Lone_Wolf
Member
 
Posts: 2193
Joined: Sun Apr 09, 2017 05:50
Location: Hopefully very far from yours, snoop :P
GitHub: LoneWolfHT
IRC: Lone_Wolf
In-game: Lone_Wolf

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by Lone_Wolf » Fri Nov 08, 2019 03:10

If you put a sound in minetest/sounds/ (minetest/textures/ but for sounds) I think you can play it with CSM
 

User avatar
jas
Member
 
Posts: 464
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

Re: [CSM] Jump Sound [ll_csm_jumpsound]

by jas » Fri Nov 08, 2019 08:36

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.
2019-10-14 09:12:51: ACTION[Server]: jas activates
 


Return to Client-side modding



Who is online

Users browsing this forum: No registered users and 1 guest