Looping bullet fire

KalabalanaKalabalana Join Date: 2003-11-14 Member: 22859Members
When running the test, firing the rifle either plays the fire sounds twice, or it doesn't shut off.

I've been searching through the lua files, but I can't find the call to the rifle firing sound. Does anyone know where it is?

Comments

  • PrivatePrivate Join Date: 2007-06-10 Member: 61204Members, Constellation
    <!--quoteo(post=1772867:date=May 30 2010, 08:47 PM:name=Viper_two_nine_A)--><div class='quotetop'>QUOTE (Viper_two_nine_A @ May 30 2010, 08:47 PM) <a href="index.php?act=findpost&pid=1772867"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->i just had a first look at the ns lua source because i wondered how it would fit my needs to build a mod.

    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.
  • alibialibi Join Date: 2009-11-20 Member: 69445Members
    if it helps.. once the sound is looping, even if you turn the in game volume slider down... it continues to loop until you fire the weapon again.
  • KalabalanaKalabalana Join Date: 2003-11-14 Member: 22859Members
    edited June 2010
    Fix does not work. Also, I'm finding that I'm doubling up my sounds, apparently the firing code is executed once by the client, and once by the server. Odd.


    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.
  • Viper_two_nine_AViper_two_nine_A Join Date: 2004-09-29 Member: 31989Members
    edited June 2010
    <!--quoteo(post=1773200:date=Jun 3 2010, 01:00 PM:name=Kalabalana)--><div class='quotetop'>QUOTE (Kalabalana @ Jun 3 2010, 01:00 PM) <a href="index.php?act=findpost&pid=1773200"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Fix does not work. Also, I'm finding that I'm doubling up my sounds, apparently the firing code is executed once by the client, and once by the server. Odd.


    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 ;)
  • KalabalanaKalabalana Join Date: 2003-11-14 Member: 22859Members
    <!--quoteo(post=1773668:date=Jun 6 2010, 10:22 PM:name=Viper_two_nine_A)--><div class='quotetop'>QUOTE (Viper_two_nine_A @ Jun 6 2010, 10:22 PM) <a href="index.php?act=findpost&pid=1773668"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->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 ;)<!--QuoteEnd--></div><!--QuoteEEnd-->

    No, I've found all respective code, waiting on latest update to address problem.
  • Viper_two_nine_AViper_two_nine_A Join Date: 2004-09-29 Member: 31989Members
    ok strange. that workaround works at my machine ... i didnt really have any problems influencing the game code that is being run.
  • RobBRobB TUBES OF THE INTERWEB Join Date: 2003-08-11 Member: 19423Members, Constellation, Reinforced - Shadow
    Check Lines 205 to 207.
    <!--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.
  • Viper_two_nine_AViper_two_nine_A Join Date: 2004-09-29 Member: 31989Members
    edited June 2010
    it is reset in function Rifle:StopPrimaryAttack(player)

    did you try the workaround after all?
  • RobBRobB TUBES OF THE INTERWEB Join Date: 2003-08-11 Member: 19423Members, Constellation, Reinforced - Shadow
    No, I can't run the engine properly. After a few seconds it just stops.
  • Viper_two_nine_AViper_two_nine_A Join Date: 2004-09-29 Member: 31989Members
  • MeepsauceMeepsauce Join Date: 2010-07-14 Member: 72370Members
    edited July 2010
    Well, after looking around the forums this is a known bug and I feel silly for even posting a temporary solution with the alpha so close.
    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.
Sign In or Register to comment.