Announcement

Collapse
No announcement yet.

How do I code ammunition reloads into a vehicle?

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

    How do I code ammunition reloads into a vehicle?

    I'm working on a couple vehicles for some TC mods, and I'd like to be able to have the weapons on these vehicles stop firing after a set number of rounds, then simulate a reload.

    Basically, it would:

    1) Count how many seconds the weapon has been fired (a variable called "firetime"). Basically, each time the player presses Fire, a timer runs until Fire is released.

    2) Once "firetime" is greater than a set amount ("ammolimit") the weapon stops firing and a "weaponactive" var is set to false.

    3) A new timer runs for a certain amount of seconds ("reloadtime"). I trigger a sound and maybe an animation.

    4) Once the timer reaches "reloadtime", "firetime" is reset to 0, "weaponactive" is set to true, and the weapon resumes firing.

    I haven't coded anything relatively complex in a long time, so I really need some help with this.

    #2
    Well, it sounds like you almost answered your own question. Just make the variables you need, then under the the fire functions, just add some if else statements and you should have it...

    Comment


      #3
      I remember someone posting some code on how to do this. Not sure if reloadable vehicles works the same for weapons. So try this:

      Code:
      class SomeReloadableStuff extends WhatYourTurret extends
      
      var int ammoammount;
      
      state ProjectileFireMode
      {
      function Fire(Controller C)
      {
       if (ammoammount >= 4) //So you cant fire after shooting 4 projectiles and must reload.
       GoToState( 'Reloading' );
      
      SpawnProjectile(ProjectileClass, False); 
      ammoammount += 1;
      }
      }
      
      state Reloading
      {
        Begin:
        Sleep( 3.0 );
        ammoammount = 0;
        GoToState( 'ProjectileFireMode' );
      }
      
      defaultproperties
      {
         ammoammount = 0 //So you start wit full ammo.
      }
      This is not my code, I remember it from a post somewhere.

      Comment


        #4
        Frag.Ops has reloadable vehicle weapons. Decompile our source and look at War_FOVehicleWeapon.uc.

        Comment


          #5
          Originally posted by SquirrelZero
          Frag.Ops has reloadable vehicle weapons. Decompile our source and look at War_FOVehicleWeapon.uc.
          This is why SquirrelZero rocks. "Decompile our source" he says. A fine human being. Everyone raise a glass for this guy.

          Dicky B (I was going to use the enhanced playershadow code in a mod I'm doing, but it is way unnecessary for what it is.. Code is still in there, not active, just in case)

          Comment


            #6
            Heh, mind me asking but how do you decompile source code and get all the default properties ect? Dont take this as a noob question I just never learned how to do that lol.

            Comment


              #7
              ucc batchexport usually does it. if for some reason thats not adequate, UTPT should do the trick.

              Comment


                #8
                Thanks wong! I couldn't get the batch export to work so I used UTPT, works like a charm.

                Comment

                Working...
                X