Nebula Posted March 30, 2020 Share Posted March 30, 2020 I start playing sound ... local obj = getSoundManager():PlaySound("1",false,1); getSoundManager():PlayAsMusic("1",obj,false,1); How do I get his position in seconds? sound_position = getSoundManager():getMusicPosition():PrepareMusic("1"); I will try this way, but I get an error. Tell me the right way. Link to comment Share on other sites More sharing options...
ATPHHe Posted March 30, 2020 Share Posted March 30, 2020 (edited) You can use "getSoundManager():getMusicPosition()". You can also test and play around with "getSoundManager():getPosition()". Both functions "getMusicPosition()" and "getPosition()" return only floats. To be exact, they both return Time Elapsed in milliseconds (ms). To get seconds, you need to divide the music position by 1000. local sound_position = getSoundManager():getMusicPosition() local totalSeconds = sound_position / 1000 I created a function that prints the time of the music being played in many various forms. You can choose which time formats you'd like from this, or you can edit or reference this code. -- Prints in various forms, the current elapsed time of the music that is currently playing. function printCurrentMusicTime(isoPlayer) local sound_position = getSoundManager():getMusicPosition() print(string.format("Current Music Time Elapsed (ms): %.2f", sound_position)) local totalHours = sound_position / 1000 / 60 / 60 local totalMinutes = sound_position / 1000 / 60 local totalSeconds = sound_position / 1000 print(string.format("Current Music Time Elapsed (hours): %.1f", totalHours)) print(string.format("Current Music Time Elapsed (minutes): %.1f", totalMinutes)) print(string.format("Current Music Time Elapsed (seconds): %.1f", totalSeconds)) local totalHoursRounded = math.floor(sound_position / 1000 / 60 / 60) local totalMinutesRounded = math.floor(sound_position / 1000 / 60) local totalSecondsRounded = math.floor(sound_position / 1000) print(string.format("Current Music Time Elapsed (hoursRounded): %.1f", totalHoursRounded)) print(string.format("Current Music Time Elapsed (minutesRounded): %.1f", totalMinutesRounded)) print(string.format("Current Music Time Elapsed (secondsRounded): %.1f", totalSecondsRounded)) local music_clock = millisecondsToClock(sound_position) print(string.format("Music Clock: %s", music_clock)) end -- Returns a clock as a String in "hh:mm:ss" format. function millisecondsToClock(ms) local sec = tonumber(ms)/1000 if sec <= 0 then return "00:00:00"; else local hours = string.format("%02.f", math.floor(sec/3600)); local minutes = string.format("%02.f", math.floor(sec/60 - (hours*60))); local seconds = string.format("%02.f", math.floor(sec - hours*3600 - minutes*60)); return string.format("%s:%s:%s", hours, minutes, seconds) end end Events.OnRenderTick.Add(printCurrentMusicTime) When this function "printCurrentMusicTime" is called, it prints the various time formats on console. Here's the actual SoundManager functions. I hope this all helps. Enjoy MusicTimePrinter.lua Edited March 30, 2020 by ATPHHe small edit to lua code Maris, Nebula and ZombiesLoveBrainiacs 3 Link to comment Share on other sites More sharing options...
Nebula Posted March 30, 2020 Author Share Posted March 30, 2020 To go nuts! Thank you very much for your help! 🥰 ATPHHe 1 Link to comment Share on other sites More sharing options...
Nebula Posted March 30, 2020 Author Share Posted March 30, 2020 (edited) OK. But this only works with music from the Zomboid itself, but how can I do this for the sound that I launch? local obj = getSoundManager():PlaySound("1",false,1); getSoundManager():PlayAsMusic("1",obj,false,1); And by the way, it doesn’t overlap the music built into the zomboid for me ... How can I turn it off while my track is playing? Edited March 30, 2020 by Nebula Link to comment Share on other sites More sharing options...
ATPHHe Posted March 30, 2020 Share Posted March 30, 2020 (edited) Ah, I took a closer look at "PlayAsMusic()" and I guess the function "getSoundManager():PlayAsMusic("1", obj, false, 1)" has not been implemented/finished yet. There's no getSoundPosition for sounds that I could find in the Decompiler yet. You can stop music with "getSoundManager():StopMusic()" You can try calling "playMusic()", then printing out the time. I used the parameter String "1". getSoundManager():playMusic("1") Edited March 30, 2020 by ATPHHe Link to comment Share on other sites More sharing options...
ATPHHe Posted March 30, 2020 Share Posted March 30, 2020 (edited) I looked all over the SoundManager class and could not find a way to get the timeline position of Sounds. The devs may have to add the function or feature for sounds, or the function "PlayAsMusic" would need to be finished. Edited March 30, 2020 by ATPHHe Link to comment Share on other sites More sharing options...
Nebula Posted March 30, 2020 Author Share Posted March 30, 2020 (edited) 8 hours ago, ATPHHe said: I looked all over the SoundManager class and could not find a way to get the timeline position of Sounds. The devs may have to add the function or feature for sounds, or the function "PlayAsMusic" would need to be finished. This could be a good suggestion to ask the devs for. I also tried everything .... I did not achieve a result. by getSoundManager (): StopMusic () - the current vanilla track stops, and the next one starts playing immediately. In any case, thanks for the help! You have clarified. Edited March 30, 2020 by Nebula Link to comment Share on other sites More sharing options...
ATPHHe Posted March 30, 2020 Share Posted March 30, 2020 (edited) You're welcome. Glad to try and help out. Hopefully this function will be added sometime in an update. Edited March 30, 2020 by ATPHHe Link to comment Share on other sites More sharing options...
Nebula Posted March 30, 2020 Author Share Posted March 30, 2020 (edited) 1 minute ago, ATPHHe said: You're welcome. Glad to try and help out. float getPosition() Return the current playing position in the sound Returns: The current position in seconds. Hm. I just don’t understand how to adapt this to my sound? Edited March 30, 2020 by Nebula Link to comment Share on other sites More sharing options...
Nebula Posted March 30, 2020 Author Share Posted March 30, 2020 getSoundManager():getPosition() Gives an error Link to comment Share on other sites More sharing options...
ATPHHe Posted March 30, 2020 Share Posted March 30, 2020 Ah, getPosition() doesn't work now that I have tested it. It's only mean't for "Music" objects and doesn't work with the "SoundManager" object. Link to comment Share on other sites More sharing options...
ATPHHe Posted March 30, 2020 Share Posted March 30, 2020 (edited) Here you go, you can stop all music that is forced to play by muting like this. -- Mute Music getSoundManager():setMusicVolume(0.0); -- Unmute Music getSoundManager():setMusicVolume(getCore().getOptionMusicVolume() / 10.0); Edited March 30, 2020 by ATPHHe Link to comment Share on other sites More sharing options...
Nebula Posted March 30, 2020 Author Share Posted March 30, 2020 It is unlikely that they will add this feature ... I get the impression that they do not give a damn about us, they are only interested in selling the game. Link to comment Share on other sites More sharing options...
Nebula Posted March 30, 2020 Author Share Posted March 30, 2020 Good. Why I tried to use PlaySound () ... The fact is that when I use playMusic (), then the music plays in the world in the coordinates of the map where it was launched. When using PlaySound () - this does not happen, and the music follows the character ... How can playMusic () be attached to the player? Link to comment Share on other sites More sharing options...
EnigmaGrey Posted March 30, 2020 Share Posted March 30, 2020 2 hours ago, Nebula said: It is unlikely that they will add this feature ... I get the impression that they do not give a damn about us, they are only interested in selling the game. I see someone answering your post with helpful information, what's here that I need "give a damn" about? Is the problem that music objects don't have a world position, since they don't use a sound emitter on the game map? Link to comment Share on other sites More sharing options...
Nebula Posted March 30, 2020 Author Share Posted March 30, 2020 (edited) How then to get getPosition () for PlaySound ()? I need to get ... Return the current playing position in the sound I tried to use PlayAsMusic () for this but nothing came of it. Edited March 30, 2020 by Nebula Link to comment Share on other sites More sharing options...
EnigmaGrey Posted March 30, 2020 Share Posted March 30, 2020 I wouldn't think you can? You'd want to get the emitter that produces the sound and set its position instead of trying to use PlaySound directly? A quick search through the Lua files shows examples like ... function ISRevolverWeapon:reloadPerform(char, square) local weapon = char:getPrimaryHandItem(); char:playSound(self.insertRoundSound) ... ATPHHe and Nebula 1 1 Link to comment Share on other sites More sharing options...
Nebula Posted March 31, 2020 Author Share Posted March 31, 2020 When using the emitter, the sound jumps (twitches) when the character moves How to win this? Link to comment Share on other sites More sharing options...
EasyPickins Posted March 31, 2020 Share Posted March 31, 2020 Try using a mono sound instead of stereo sound. You could also add "is3D = false," to the sound definition in sounds.txt. Nebula 1 Link to comment Share on other sites More sharing options...
Nebula Posted March 31, 2020 Author Share Posted March 31, 2020 Mono sound tried already. Does not help. It would be great if we added to getSoundManager () the ability for us to change the sound volume - in an already running (playing) track - through PlaySound (..., ...), as well as get the current playback position and the ability to start the sound from the desired seconds .... But anyway, thanks for the answer. Link to comment Share on other sites More sharing options...
ZombiesLoveBrainiacs Posted April 2, 2020 Share Posted April 2, 2020 On 3/31/2020 at 9:36 PM, EasyPickins said: Try using a mono sound instead of stereo sound. You could also add "is3D = false," to the sound definition in sounds.txt. Didn't work for me either. Mono makes no difference, music is still played with 3d on and still twitches when using the player's emitter. I tried to duplicate the sound definition with "is3D = false", but now i get an error "couldn't find an FMOD event or .ogg or .wav file". It seems duplicates are simply ignored if they reference the same .ogg Having more access to emitters & FMOD would be nice. Not sure what Nebula is working on, but I'm trying to make devices play audio. Link to comment Share on other sites More sharing options...
ZombiesLoveBrainiacs Posted April 2, 2020 Share Posted April 2, 2020 The last thing I tried is this: emitter = IsoWorld.instance:getFreeEmitter() emitter:setPos( getPlayer():getX(), getPlayer():getY(), getPlayer():getZ() ) emitter:playSound("Test") emitter:tick() Can't hear the sound. No idea why. Link to comment Share on other sites More sharing options...
ZombiesLoveBrainiacs Posted April 2, 2020 Share Posted April 2, 2020 (edited) Ok, so the above version doesn't work because the sound won't get registered. This version works: local sound = "test" local gameSound = GameSounds.getSound(sound) local gameSoundClip = gameSound:getRandomClip() local emitter = IsoWorld.instance:getFreeEmitter() local id = emitter:playClip(gameSoundClip, nil) emitter:set3D(id, false) emitter:tick() Edited April 2, 2020 by ZombiesLoveBrainiacs Link to comment Share on other sites More sharing options...
EasyPickins Posted April 2, 2020 Share Posted April 2, 2020 Setting distanceMax=0 forces the sound to be 2D. sound TEST { category = Player, clip { file = media/sound/ambientOutsideRainWindThunder.ogg, distanceMax = 0, } } ZombiesLoveBrainiacs 1 Link to comment Share on other sites More sharing options...
iBrRus Posted May 17, 2020 Share Posted May 17, 2020 On 4/3/2020 at 2:58 AM, EasyPickins said: Setting distanceMax=0 forces the sound to be 2D. sound TEST { category = Player, clip { file = media/sound/ambientOutsideRainWindThunder.ogg, distanceMax = 0, } } But then this music sounds all over the map. The question of how to eliminate sound twitches when the character moves remains open (distanceMax must be maintained). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now