Announcement

Collapse
No announcement yet.

weapon mutator help

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

    #16
    DarkSaber is right - overriding GetInventoryClassOverride is the best way to replace the AR at (player) spawn.

    Seeing as the AssaultRifle class is obviously already in memory when the code executes (because your ARHE class extends it), I think it would be a good idea to compare WeaponType/WeaponClass/Other.Class directly to the desired class (class'XWeapons.AssaultRifle' or class'XWeapons.AssaultRiflePickup'), rather than casting to a string and comparing to its string form. Using the string form is more prone to error.

    For example, instead of:
    Code:
    if ( string( xWeaponBase(Other).WeaponType ) ~= "XWeapons.AssaultRifle" )
    use
    Code:
    if ( xWeaponBase(Other).WeaponType == class'XWeapons.AssaultRifle' )
    (perhaps this is a matter of preference - thoughts anyone?)


    More importantly, if you are using the string form of the class (in GetInventoryClassOverride or for ReplaceWith, for example), you need to specify the package name of the class, not just the class name. i.e. instead of:
    Code:
    ReplaceWith( Other, "ARHEPickup" );
    you need
    Code:
    ReplaceWith( Other, "myPackage.ARHEPickup" );
    (substituting "myPackage" for the name of the package containing the ARHEPickup class.)

    Comment


      #17
      ~= when used with a string, means "Equal if Case is ignored", basically making it a case-insensitive ==. It's a matter of preference, but it does eliminate the possibility of a senseless error (thus, a senseless code stoppage, IMO)

      Comment


        #18
        Originally posted by ghouck
        ~= when used with a string, means "Equal if Case is ignored", basically making it a case-insensitive ==.
        I'm aware of that. Sometimes I wish C# had such a convenient operator . "Approximately equal" (~=) also has an extra meaning when used with floating-point numbers, although I've never used it for that:
        Equality within 0.0001 (numbers)
        (UnrealWiki: Operators)
        It's a matter of preference, but it does eliminate the possibility of a senseless error (thus, a senseless code stoppage, IMO)
        My point exactly.

        One senseless error to look out for when using strings is the use of '=='. For example, this code:
        Code:
        if ( xPawn(Other).RequiredEquipment[1] == "XWeapons.AssaultRifle" )
        would not work if RequiredEquipment[1] was "xweapons.assaultrifle".

        lol, I just noticed why that wouldn't work anyway:
        Code:
        RequiredEquipment(0)="XWeapons.AssaultRifle"
        RequiredEquipment(1)="XWeapons.ShieldGun"
        Those are the default values for RequiredEquipment in xPawn. [1] is the Shield Gun, so you'd either need to check all items in the array, or just the one that is expected to have the AssaultRifle - [0].

        I'd recommend using GetInventoryClassOverride instead, anyway.

        Comment

        Working...
        X