Scripting Moderators ds1-e Posted January 21, 2019 Scripting Moderators Share Posted January 21, 2019 Hi. I have some questions about sounds. Which are important in my server, because they are playing often. 1. Is the .ogg format better than .wav? I noticed that .ogg have better quality, and weight it's much less than .wav, f.e: - .wav weapon sound: 140 kb - .ogg weapon sound: 10 kb 2. I saw somewhere on forum, that sound created by playSound3D doesn't disappear, and it need to be destroyed manually, or i am wrong? 3. How can i reduce frequency of playing weapon sounds, if a lot of players shoot in one time, it decrease performance. I tried to reduce them with using and comparing: getTickCount() But server started to lagging on 30 + players. 4. How can i create some kind of a sound system which: - will check if there's for example 4-5 weapon sounds playing. - if yes, then not all of them will be hearable, but your own weapon sound will plays without any delays. Link to comment
Moderators IIYAMA Posted January 21, 2019 Moderators Share Posted January 21, 2019 1. wav is an uncompressed format ogg is a compressed format. Before a compressed format can be played, your computer has to uncompress it first. A This cost time and memory. There are two very well known ways of compressing. The first one is removing information, which results in quality loss. A The second one is restructuring the data and removing spaces in between. But by doing this the format can't be read directly by the media player. It has to be restored to it's original state before it can be played. When playing audio repeatedly (for example while firing your weapon), your computer will be uncompressing a ogg file repeatedly, which can cause a bit of lag if your computer can't handle it. 2. You only have to destroy it, when your audio element doesn't stop by itself. For example when looped or streamed. element playSound3D ( string soundPath, float x, float y, float z, [ bool looped = false ] ) 3. local nextShootingTime = 0 -- on top of the script. --- in your function --- local timeNow = getTickCount() if timeNow > nextShootingTime then nextShootingTime = timeNow + 20 -- play audio end 4. You need to learn tables for that... 1 Link to comment
Scripting Moderators ds1-e Posted January 21, 2019 Author Scripting Moderators Share Posted January 21, 2019 (edited) -- outside the function local checkSound = getTickCount() -- inside the function local lastShot = getTickCount() if lastShot > checkSound then -- playsound checkSound = lastShot + 20 end Thank you for the answer , this is the similar function which i used, and it was causing huge lags. About tables. I used them already, in some ways. However i don't have idea how can i make a sound system like this. Inserting in table, iterate weapon sounds in table - through loop 'for' , check if it's more than x sounds? Can you guide me a bit more? Edited January 21, 2019 by majqq Link to comment
Moderators IIYAMA Posted January 21, 2019 Moderators Share Posted January 21, 2019 (edited) @majqq hmm, maybe another way of making it would be easier for you to build it and it doesn't require any tables. It simply uses the element tree: https://wiki.multitheftauto.com/wiki/Element_tree -- on top local soundContainer = createElement("soundContainer") -- in your function if getElementChildrenCount (soundContainer) < 5 then local sound = [[ ... ]] setElementParent(sound, soundContainer) end If we would visualise this: <soundContainer> <sound></sound> <sound></sound> <sound></sound> <sound></sound> </soundContainer> And the cool thing about it, is that there is nothing you have to clean from a table. Edited January 21, 2019 by IIYAMA 1 Link to comment
Scripting Moderators ds1-e Posted January 21, 2019 Author Scripting Moderators Share Posted January 21, 2019 6 minutes ago, IIYAMA said: @majqq hmm, maybe another way of making it would be easier for you to build it and it doesn't require any tables. It simply uses the element tree: https://wiki.multitheftauto.com/wiki/Element_tree -- on top local soundContainer = createElement("soundContainer") -- in your function if getElementChildrenCount (soundContainer) < 5 then local sound = [[ ... ]] setElementParent(sound, soundContainer) end If we would visualise this: <soundContainer> <sound></sound> <sound></sound> <sound></sound> <sound></sound> </soundContainer> And the cool thing about it, is that there is nothing you have to clean from a table. I don't understand element tree for now, so as far i understand this, it will store sounds, after sound will end, it will disappear from this. This should avoid playing more than 5 sounds in one time, i am right? If not, sorry, i'm new to this. But what if want "give" an immunited for a sound that is created by me, so it will not count to it? Thanks anyway. 1 Link to comment
Moderators IIYAMA Posted January 21, 2019 Moderators Share Posted January 21, 2019 4 minutes ago, majqq said: I don't understand element tree for now, so as far i understand this, it will store sounds, after sound will end, it will disappear from this. This should avoid playing more than 5 sounds in one time, i am right? If not, sorry, i'm new to this. But what if want "give" an immunited for a sound that is created by me, so it will not count to it? Thanks anyway. You for 99% correct. But there is nothing `extra` to be stored, we only moved things around. 8 minutes ago, majqq said: But what if want "give" an immunited for a sound that is created by me, so it will not count to it? If you do not set it's parent to soundContainer, it will not count. If we do nothing: (everything is parallel) <sound></sound> <sound></sound> <sound></sound> <sound></sound> <soundContainer> <!-- no children so we count 0 --> </soundContainer> If we use setElementParent: <soundContainer> <!-- 4 children, so we count 4 --> <sound></sound> <sound></sound> <sound></sound> <sound></sound> </soundContainer> 1 Link to comment
Scripting Moderators ds1-e Posted January 21, 2019 Author Scripting Moderators Share Posted January 21, 2019 (edited) 49 minutes ago, IIYAMA said: You for 99% correct. But there is nothing `extra` to be stored, we only moved things around. If you do not set it's parent to soundContainer, it will not count. If we do nothing: (everything is parallel) <sound></sound> <sound></sound> <sound></sound> <sound></sound> <soundContainer> <!-- no children so we count 0 --> </soundContainer> If we use setElementParent: <soundContainer> <!-- 4 children, so we count 4 --> <sound></sound> <sound></sound> <sound></sound> <sound></sound> </soundContainer> So if i don't want count sound to it i need just add a condition, like this? Because i think there is no other way. Or this will not work? I just wanna be sure. function onClientPlayerWeaponFire(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) if source == getLocalPlayer() then -- don't count sound else -- count sound? end end addEventHandler("onClientPlayerWeaponFire", getRootElement(), onClientPlayerWeaponFire) Edited January 21, 2019 by majqq Link to comment
Moderators IIYAMA Posted January 21, 2019 Moderators Share Posted January 21, 2019 3 minutes ago, majqq said: So if i don't want count sound to it i need just add a statement, like this? Because i think there is no other way. Or this will not work? I just wanna be sure. function onClientPlayerWeaponFire(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) if source == getLocalPlayer() then -- do not count sound else -- count sound? outputChatBox("source ~= getLocalPlayer()") end end addEventHandler("onClientPlayerWeaponFire", getRootElement(), onClientPlayerWeaponFire) Yea that should be fine as far as I can see. 1 Link to comment
Scripting Moderators ds1-e Posted January 21, 2019 Author Scripting Moderators Share Posted January 21, 2019 4 minutes ago, IIYAMA said: Yea that should be fine as far as I can see. I'm very grateful, thank you for help. I will test out it asap, and if something will be wrong i will inform you 1 Link to comment
KillerX Posted January 21, 2019 Share Posted January 21, 2019 10 hours ago, IIYAMA said: Yea You are a respected and experienced man 1 Link to comment
Moderators IIYAMA Posted January 21, 2019 Moderators Share Posted January 21, 2019 11 minutes ago, KillerX said: You are a respected and experienced man I feel deeply honoured when you say that. But even so, I am somebody with limits as well. I get the feeling that you are the same on your language section. 1 Link to comment
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