Announcement

Collapse
No announcement yet.

Alternating driver weapons with a vehicle

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Alternating driver weapons with a vehicle

    I have a wheeled vehicle with two driver weapons attached to two seperate bones on the vehicle. The two weapons fire alternately, set by alternating the ActiveWeapon variable between 0 and 1 and calling SetActiveWeapon(ActiveWeapon) within a Timer function in the Vehicle class. The weapons use the same code as found in the Onslaught.ONSTankSecondaryTurret (the goliaths passenger weapon). This weapon has Tracer Fire when shot.

    Now this all works very nicely on a standalone or listen server and the tracer fire can be seen to alternate between the two weapons as expected.

    The problem I am finding is that the weapons do not alternate on a client machine attached to either a dedicated or listen server.

    I've used the DrawHUD function (set in the vehicle class) to display onscreen and verify that the ActiveWeapon and Weapons(ActiveWeapon).bActive values are being set correctly, which they are.

    I have also logged (in the Weapon class'es Fire function and UpdateTracer function) the AttachmentBone to see exactly which weapon is currently firing. This does not alternate at all.

    My thoughts were that setting the ActiveWeapon should work as that variable is replicated (and as the DrawHUD is verifying that the variable is indeed being updated). What I would like is some suggestions as to where else I should be looking to get this to work on a client machine.

    If anymore info is needed or code from my classes, I will be more than happy to post it up here.

    Thanks for any help/ideas anyone can throw into the pot.

    #2
    The only thing I can see is that you are calling SetActiveWeapon in a non replicated function, being able to see the code is th only way I can possibly help sorry...


    though a dirty fix would be to add the follwing to your replication block (if I'm guessing right)
    Code:
    replication
    {
        reliable if ( Role<ROLE_Authority)
            SetActiveWeapon;
    }

    Comment


      #3
      Yeah, I did notice that myself. But the logs were reporting that the weapons were being alternated nonetheless.

      I tried to put the SetActiveWeapon within the replication block, but that gave me an error (maybe because that function isn't actually defined in my vehicle class - it's defined in ONSVehicle)?

      Anyway, what I did try though was to have the same code that was in the SetActiveWeapon function actually within my Timer function.

      Code:
      Weapons[ActiveWeapon].bActive = false;
      ActiveWeapon = (ActiveWeapon + 1) % 2;
      Weapons[ActiveWeapon].bActive = true;
      This is all set in the vehicle class and displays as expected in the logs and via the DrawHUD function.

      I also added another log in the weapon class which simply reported the AttachmentBone variable. At first I thought this didn't alternate between the 2 attachment bones. But then I found that sometimes it did and sometimes it didn't, which puzzled me even more :bulb:

      Comment


        #4
        Have you checked out the Leviathan (OnslaughtFull.ONSMobileAssaultStation)? It does pretty much the same thing when deploying, switching the driver from the missile launcher to the singularity cannon.

        Comment


          #5
          It's the setactiveweapon funciton that does that Xyx...

          The problem he has is that he seems to be calling it form a non replicated function so it's not happeing on the server...

          It'd be great to see the function you're calling it from Spam Savior

          Comment


            #6
            OK, apologies for not getting back to this until now but here we are.

            In my vehicle class, I have a Timer function which is called every 0.1 seconds, as follows:

            Code:
            simulated function Timer()
            {
                ActiveWeapon = (ActiveWeapon + 1) % 2;
                SetActiveWeapon(ActiveWeapon);
            }
            I've also tried this:

            Code:
            simulated function Timer()
            {
                Weapons[ActiveWeapon].bActive = false;
                ActiveWeapon = (ActiveWeapon + 1) % 2;
                Weapons[ActiveWeapon].bActive = true;
            }
            This reports on both the server and client that the ActiveWeapon is in fact alternating and it's bActive property is also alternating between True and False.

            Also, in my weapon class, I added a log in the function which displays the tracer fire. This entire class is copied from the Goliaths passenger weapon class.

            Code:
            simulated function UpdateTracer()
            {
                log("Weapon being fired: "$self.AttachmentBone);
            
            ...
            }
            On the server this shows that the Attachment bone is alternating between the two weapons (ie, left and right). On the client this is showing that only one weapon is being fired. This can change depending on when you start firing (as the ActiveWeapon is alternating).

            Comment


              #7
              Where do you call the timer?

              Comment


                #8
                Timer is called from simulated function PostBeginPlay().

                Edit:

                OK another update. I've managed to get the Tracer Fire to alternate between the two driver weapons on a client machine, (but only sometimes). I did this by adding an UpdateTracer function in the Weapon class into the replication block. A problem still exists however, in that when you move your aim while still firing only one of the weapons' tracer fire updates it's position, the other weapons' tracer fire stays where it was initially.

                I really need to re-read that Replication Deobfuscation document again and see if any more of it will sink in, hehe.

                Anyway, I'm getting closer with it!

                Hsoolien:

                You mentioned in an earlier post about adding the SetActiveWeapon function to the replication block. I had problems with this as that function had already been defined in ONSVehicle. Is it not possible to add a pre-defined function to the replication block? and only functions with the particular class can be added?

                Thanks.

                Comment


                  #9
                  If it's already been declared that's probably your problem, it's also probably declared native.


                  Any function that is not alreayd replicated can be...

                  Comment

                  Working...
                  X