• several different sounds for primary shot of a swep?
    8 replies, posted
Hello, I'd like to have different sounds play for the swep sound. So SWEP.Primary.Sound = Sound("firing_sound") is the typical way of doing it, but I'd like to have multiple different firing sounds play in a sequence. I tried creating a table but it said I couldn't do that (lua error expected a string). Anyone know if this is possible? Thanks, Brendon
While I personally never utilized the SWEP.Primary.Sound enumeration for my SWEPs, I did cook up a very simple system for pulling a random sound out of a set pool of sound files for whenever the SWEP was considered fired: Firstly, I defined a "soundpool" as an array of strings: https://files.facepunch.com/forum/upload/321820/5a45a4d7-97ea-4619-913b-14496294b3aa/image.png Asssume that n is the amount of strings contained within the aforementioned array. That let's me do the following: https://files.facepunch.com/forum/upload/321820/df50ce75-54e6-4528-abc9-81e97fbfe747/image.png ...with EmitSound()⑴; where it'll find and emit the sound-file corresponding to the pre-defined names given in the string-array. EmitSound is heard from different clients depending on wherefrom you keep the code; be it clientside or else. Suggestively, unless your SWEP is intended to be fired in a predictable way, as far as the code is laid out, you probably shouldn't give up on using SWEP.Primary.Sound anyway; although if it does just take the name of the sound-file as an argument, you might be able to utilize the same pick-random-from-array-method as I posted above. (1) Entity/EmitSound
you can do this self:EmitSound("npc/combine_gunship/ping_patrol.wav", 75, 120, 1, CHAN_WEAPON) self:EmitSound("weapons/m249/m249-1.wav", 75, 120, 1, CHAN_WEAPON + 1) self:EmitSound("weapons/m4a1/m4a1_unsil-1.wav", 75, 120, 1, CHAN_WEAPON + 2) self:EmitSound("weapons/ar2/fire1.wav", 75, 120, 1, CHAN_WEAPON + 3) and it will play all 4 sounds at once dont know if thats what you want
No I wanted it to go in a sequence or randomly but not at the same time. However, nice to know several sounds can be played at once.
oh, You should be able to create with DTs, And you can just set it to 0 when you deploy the weapon. And each time you shoot you can add 1 to the dt int. And for emitting a sound you can play it in a sequence like this. If getdtint == 0 then self:EmitSound("npc/combine_gunship/ping_patrol.wav", 75, 120, 1, CHAN_WEAPON) elseif getdtint == 1 then self:EmitSound("weapons/m249/m249-1.wav", 75, 120, 1, CHAN_WEAPON + 1) elseif getdtint == 2 then self:EmitSound("weapons/m4a1/m4a1_unsil-1.wav", 75, 120, 1, CHAN_WEAPON + 2) elseif getdtint == 3 then self:EmitSound("weapons/ar2/fire1.wav", 75, 120, 1, CHAN_WEAPON + 3) end Probably not the best way of doing that, but it should be able to work that way.
i'm just gonna step in and say to not add numbers to enumerations, that's not at all how you should ever consider doing things, because now you're potentially overriding other sounds playing in that channel. in addition, if you go far enough, you'll start hitting nil values, meaning no channel, meaning who knows what kind of error. and even another thing, you're implicitly using the decimal values of these enums, which is explicitly advised against. anyway to make sure your sounds play in order, in a good-sounding way, independent of lag and other anomalies, i suggest you look at this page: Prediction
1 : well yea if I emit an m4 shot in the same channel on the same gun at the same time that a five seven shot is emitted, of course the latter will take over. I can have 5 different weapons all fire different sounds in the same specific channel and they will all emit. I feel for weapon firing there should be no problem doing it. 2 : If you layer enough sounds to a point where you cant emit sounds anymore, then you are not creating something proper. A good number is 2 - 6 sounds layered, anything more is kind of unnecessary or extra. 3 : Why do you/others think its bad? it seems to work fine for me and others.
i meant other code using those channels, mainly the voice channel, the item channel, or the stream channel. these things are all separate for a reason, you really shouldn't be using the voice channel for weapon sounds. yes it is unnecessary and extra, but if someone in the future comes across this and finds the suggestion of "oh just do CHAN_WEAPON + x as many times as you need sounds," someone out there is gonna eventually wind up maxing out the channel number. timers are bad because, from the page on Prediction: Timers are not reliable at all during prediction, and they wouldn't be restored when the server tells you what’s wrong during a prediction error. Also lag compensation does not work in a timer, so there's another reason why you shouldn't do that.
Ok I understand, I replied this to help with him about a weapon which is what I primarily considered and didnt think of that scenario (someone looking at this and seeing the chan_weapon + x to their desired amount anywhere in any file) And originally it was CHAN_WEAPON + 20, And at first I didnt know why it started at 20 but it makes more sense now because its an empty channel with more empty chans following it. I didnt look at it as chan_weapon just being a number and adding 1 to it made it a different channel. As for the timer part, I didnt ask about the timers. I know timers arent that great and thats why I suggested creating an int and adding to it when you fire and changing the sound based on the int. I was asking about the "and even another thing, you're implicitly using the decimal values of these enums, which is explicitly advised against." and why you and others advise against it.
Sorry, you need to Log In to post a reply to this thread.