Announcement

Collapse
No announcement yet.

Prevent 0-ammo Weapon Switch

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

    Prevent 0-ammo Weapon Switch

    I'm recreating the Arm Cannon from the Metroid games as part of a University UDK assignment. I have the shot cost of the primary fire (Power Beam) set to 0, and the secondary fire (Missiles) set to 1. However, when I spend all of my missiles and try and fire again, the weapon is un-equipped because the ammo count is now 0. How can I override this behaviour?

    EDIT: I modified my weapon to override WeaponEmpty, which prevents it from switching the weapon out when the ammo count is 0. However, if the player scrolls, the weapon cannot be equipped. I made my own InventoryManager and overrode SwitchWeapon. The line I need to change is:

    Code:
    if ( WeaponList[NewIndex].HasAnyAmmo() || WeaponList[NewIndex] == UTWeap_ArmCannon)
    However, my IDE tells me that WeaponList[NewIndex] and UTWeap_ArmCannon are mismatched, and I'm not sure what I'm supposed to do instead. I've tried 'UTWeap_ArmCannon', class'UTWeap_ArmCannon' UTWeapon(UTWeap_ArmCannon) and Weapon(UTWeap_ArmCannon), but none of these have worked.

    EDIT: WeaponList[NewIndex] == UTWeapon(class'UTWeap_ArmCannon') was what I wanted. However, it doesn't seem to make any difference. Even commenting out the 'if' statement prevents me from switching back to my weapon when it's out of ammo.

    #2
    What you are looking for is the following conditional check (a cast from UTWeapon to UTWeap_ArmCannon):
    Code:
    UTWeap_ArmCannon(WeaponList[NewIndex]) != none
    Instead of modifying the InventoryManager, you should be able to override "HasAnyAmmo" of UTWeap_ArmCannon. This would allow switching back to that weapon.

    Comment


      #3
      make a new function in pbweapon like so

      Code:
      simulated function bool AnyAmmoAtAll()
      {
           // for guns so they will dry fire and not get excluded from weapons list
           return ( AmmoCount >= 0 );
      }

      then in inventory manager around line 130 use that like this. (your line might be a different number as i've edit my file many times)

      Code:
      // now it will switch when at 0 ammo
      if( (!bFilter || Weap.InventoryGroup == GroupFilter) && ( !bNoEmpty || Weap.AnyAmmoAtAll()) )

      hope this helps.
      this will modify all guns in the weapon list to be switchable at 0 ammo.

      Comment


        #4
        Originally posted by RattleSN4K3 View Post
        Instead of modifying the InventoryManager, you should be able to override "HasAnyAmmo" of UTWeap_ArmCannon. This would allow switching back to that weapon.
        Perfect, thank you!

        @nameloc Your help is also greatly appreciated, but I wanted the other weapons to act normally. Only the Arm Cannon needed to prevent the weapon switch.

        You can now switch back to the Arm Cannon after running out of ammo!

        Comment

        Working...
        X