Looping bullet fire
Kalabalana
Join Date: 2003-11-14 Member: 22859Members
in Modding
Comments
for those of you that got annoyed by the sound loop bug (like me :)) here is a quick workaround. it does not use the riflefiring sound loop file (as proposed by the comment) anymore but it keeps soundoutput from going crazy.
in \Steam\steamapps\common\natural selection 2\ns2\lua\Rifle.lua
line 201 ff replace
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->elseif (self.firingState == 1) then
player:PlaySound(self.fireLoopSound)
end<!--c2--></div><!--ec2-->
with
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->elseif (self.firingState > 0) then
player:PlaySound(self.fireSound)
end<!--c2--></div><!--ec2--><!--QuoteEnd--></div><!--QuoteEEnd-->
I haven't tried it, don't know if it's valid or what you are after.
I'm guessing the on mouse release call is not stopping the looping sound. Looking into it now.
Can LUA handle mouse release? It obviously handles mouse press.
I'm guessing the on mouse release call is not stopping the looping sound. Looking into it now.
Can LUA handle mouse release? It obviously handles mouse press.<!--QuoteEnd--></div><!--QuoteEEnd-->
did you restart your ns2 client?
and - as i have written before - this is not really a fix but a workaround as i was not able to fix it properly as it was suggested by the comments ("play start fire sound, then loop long fire sound"). instead the workaround is just looping the initial sound.
apart from that - i think the rifle.lua is the file that you want to look at ;)
and - as i have written before - this is not really a fix but a workaround as i was not able to fix it properly as it was suggested by the comments ("play start fire sound, then loop long fire sound"). instead the workaround is just looping the initial sound.
apart from that - i think the rifle.lua is the file that you want to look at ;)<!--QuoteEnd--></div><!--QuoteEEnd-->
No, I've found all respective code, waiting on latest update to address problem.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if (self.firingState < 2) then
self.firingState = self.firingState + 1
end<!--c2--></div><!--ec2-->
When you shoot, the state is set to 1.
as it is less than two, its increased by 1.
but i cant find anything that resets it to zero or one.
did you try the workaround after all?
But for anyone that wants to see a pretty close solution:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Rifle:StopPrimaryAttack(player)
if (self.firingState > 0) then
self:Idle(player)
if (self.firingState > 1) then
player:StopSound(self.fireLoopSound)
player:PlaySound(self.fireEndSound)
end
self.firingState = 0
end
end<!--c2--></div><!--ec2-->
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if (self.firingState == 0) then
player:PlaySound(self.fireSound)
self.firingState = self.firingState + 1
elseif (self.firingState == 1) then
player:PlaySound(self.fireLoopSound)
self.firingState = self.firingState + 1
if (self.firingState == 2) then
player:StopSound(self.fireLoopSound)
end
end<!--c2--></div><!--ec2-->
I think I have a pretty good theory on why this bug occured in the first place (which is too long to mention), <b>and I would absolutely love to know the real reason behind this bug.</b>
This "fix" isn't perfect, if you let go of the mouse about 2 seconds into firing you hear the looping sound play and not stop. I think this is because the firing function has not reached the looping sound line yet because it has more lines to deal with effects animations and brass projection, whereas the stop firing function is shorter and tries to stop a sound that isn't created yet. Thus giving you a sound playing that can't be stopped because the next time you remove the looping sound you're only removing the newest one and not the previous one.