Announcement

Collapse
No announcement yet.

[ut2004] random weapon preferences

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

    [ut2004] random weapon preferences

    i saw a request for a mutator that gives pawns preference for one weapon over the others (without regards to the user.ini file). I have started to code this but I'm stuck in a few places. Here is what I have so far-
    Code:
    class CustomWeaponAssignments extends Mutator;
    
    var Weapon W;
    var string WeaponName;
    var byte WeaponPriority;
    var int i;
    var Controller C;
    var int Count;
    var string PawnWeaponCount;
    var bool bHasDesiredWeapon;
    var Inventory inv;
    var array<byte> guns;
    var array<string> gunnames;
    var HudBase HB;
    
    simulated function byte AssignWeaponPriority(Weapon W)
    {
         if (W.Priority != 36)
         {
             W.Priority = 36;
    
             WeaponPriority = W.Priority;
    
             return WeaponPriority;
         }
    }
    
    simulated function AssignClasses()
    {
         for (C = Level.ControllerList; C != None; C = C.NextController)
         {
             GetNumberOfWeapons(C.Pawn);
             i = Rand(Count);
             AssignWeapon(C.Pawn);
         }
    }
    
    simulated function GetNumberOfWeapons(Pawn P)
    {
       for(inv=C.Pawn.Inventory; inv!=none; inv=inv.Inventory )//iterate through pawn's inventory
          {
            if( inv.IsA('Weapon') && (!inv.IsA('TransLauncher')))//check to see if its a weapon
              {
                if((Weapon(inv).AmmoAmount(0) < weapon(inv).MaxAmmo(0)) || (Weapon(inv).AmmoAmount(1) < weapon(inv).MaxAmmo(1)))//make sure the weapon has ammo
                  {
                    Count++;
                  }
              }
          }
    }
    
    simulated function AssignWeapon(Pawn P)
    {
       local Canvas Canvas;
    
       P.SwitchWeapon(guns[i]);
       P.Weapon.Priority = 36;
       bHasDesiredWeapon = true;
       HB.DrawWeaponName(Canvas);
       Canvas.SetPos(0,50);
       Canvas.Font=HB.GetConsoleFont(Canvas);
       Canvas.DrawText("You Are A $gunnames[i]");
    }
    
    simulated function PostAssignments()
    {
       for (C = Level.ControllerList; C != None; C = C.NextController)
       {
           if (bHasDesiredWeapon)
           {
             //something like Handle or OverridePickeupQuery so that the pawn will
             //not pick up any other weapons once it has the desired weapon
           }
       }
    }
    
    defaultproperties
    {
     guns[1]="XWeapons.AssaultRifle"
     guns[2]="XWeapons.BioRifle"
     guns[3]="XWeapons.ShockRifle"
     guns[4]="XWeapons.FlakCannon"
     guns[5]="XWeapons.Minigun";
     guns[6]="XWeapons.RocketLauncher"
     guns[7]="XWeapons.LinkGun"
     guns[8]="ONSWeapon.ONSGrenadeLauncher"
     guns[9]="ONSWeapon.ONSMineLayer"
     guns[10]="UTClassic.ClassicSniperRifle"
     gunnames[1]="Assault Gunner"
     gunnames[2]="Bio Gunner"
     gunnames[3]="Shock Gunner"
     gunnames[4]="Flak Gunner"
     gunnames[5]="MiniGunner"
     gunnames[6]="Rocket Gunner"
     gunnames[7]="LinkGunner"
     gunnames[8]="Grenade Gunner"
     gunnames[9]="Mine Layer"
     gunnames[10]="Sniper"
     FriendlyName="Custom Weapon Assignments"
     Description="Each player has a weapon preference and will use only that weapon whenever possible"
    }
    Please offer some advice and feel free improve my code. Thank you in advance.

    #2
    after playing with the code and adding some logs for debugging, I can tell that something is seriously wrong, as none of my logs showed up in my gamelog after 3 tries.
    here is the revised code
    Code:
    class CustomWeaponAssignments extends Mutator;
    
    var Weapon W;
    var int i;
    var Controller C;
    var int Count;
    var bool bHasDesiredWeapon;
    var array<byte> gun_nums;
    var HudBase HB;
    
    simulated function AssignWeaponPriority(Weapon W)
    {
         local byte WeaponPriority;
    
         if (W.Priority != GetNumberOfWeapons(C.Pawn))
         {
             W.Priority = Count;
    
             WeaponPriority = W.Priority;
         }
    }
    
    simulated function Randomize()
    {
         for (C = Level.ControllerList; C != None; C = C.NextController)
         {
             GetNumberOfWeapons(C.Pawn);
             i = Rand(Count);
             Log("Rand(Count) = " $i);
             AssignWeapon(C.Pawn);
         }
    }
    
    simulated function int GetNumberOfWeapons(Pawn P)
    {
       local Inventory inv;
    
       for(inv=P.Inventory; inv!=none; inv=inv.Inventory )//iterate through pawn's inventory
          {
            if( inv.IsA('Weapon') && (!inv.IsA('TransLauncher')))//check to see if its a weapon
              {
                if((Weapon(inv).AmmoAmount(0) < weapon(inv).MaxAmmo(0)) || (Weapon(inv).AmmoAmount(1) < weapon(inv).MaxAmmo(1)))//make sure the weapon has ammo
                  {
                    Count++;
                    Log("count = " $Count);
                    return Count;
                  }
              }
          }
    }
    
    simulated function AssignWeapon(Pawn P)
    {
       local Canvas Canvas;
       local string CurWeaponName;
    
       P.SwitchWeapon(gun_nums[i]);
       Log("Weapon set to" $i);
       P.Weapon.Priority = GetNumberOfWeapons(C.Pawn);
       bHasDesiredWeapon = true;
    
       Canvas.SetPos(50,50);
       Canvas.Font=HB.GetConsoleFont(Canvas);
       HB.DrawWeaponName(Canvas);
       CurWeaponName=C.Pawn.Weapon.GetHumanReadableName();
       Canvas.DrawText("your weapon is" $CurWeaponName);
    }
    
    defaultproperties
    {
     gun_nums[1]="1"
     gun_nums[2]="2"
     gun_nums[3]="3"
     gun_nums[4]="4"
     gun_nums[5]="5"
     gun_nums[6]="6"
     gun_nums[7]="7"
     gun_nums[8]="7"
     gun_nums[9]="9"
     gun_nums[10]="10"
     FriendlyName="Custom Weapon Assignments"
     Description="Each player has a weapon preference and will use only that weapon whenever possible"
    }

    Comment

    Working...
    X