Announcement

Collapse
No announcement yet.

Random Start Weapon

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

    Random Start Weapon

    I made a mutator some years ago called Random Start Weapon. It was working. Now I've reinstalled UT3 but I don't have the mutator. However, I've found the code online in this thread: https://forums.epicgames.com/archive.../t-748404.html (Stormrider was my old nickname). I've compiled it now with no errors but there are not results in the game when I enable the mutator. Can you please take a look at it? Thanx a lot.


    Code:
    // Based on UTMutator_Instagib.uc
    class Mutator_RSW extends UTMutator;
    
    // @TODO: Add config declarations
    var array< String > WeaponsList;
    var() int WeaponCount;
    
    function InitMutator(string Options, out string ErrorMessage)
    {
    if ( UTGame(WorldInfo.Game) != None )
    {
    /* Clear default inventory */
    UTGame(WorldInfo.Game).DefaultInventory.Length = 0;
    UTGame(WorldInfo.Game).DefaultInventory[UTGame(WorldInfo.Game).DefaultInventory.Length] = class'UTGame.UTWeap_ImpactHammer';
    }
    
    Super.InitMutator(Options, ErrorMessage);
    }
    
    function ModifyPlayer(Pawn Other)
    {
    `Log("### ModifyPlayer:"@Other);
    
    GiveRandomWeapon(Other);
    
    Super.ModifyPlayer(Other);
    }
    
    function GiveRandomWeapon(Pawn Other)
    {
    local int i,weapIndex;
    local array< String > templist;
    local UTPawn UTP;
    local class< Inventory > randWeapon;
    
    UTP = UTPawn(Other);
    if ( UTP == None )
    {
    `Log("### cannot cast '"$Other$"' to UTPawn");
    return;
    }
    
    // @TODO: Check if allocation ByRef or ByValue (Update: done, its ByValue)
    templist = WeaponsList;
    
    for( i=0; i<WeaponCount; i++ ) {
    `Log("### Adding weapon #"$i);
    
    weapIndex = Rand(templist.Length-1);
    randWeapon = class<Inventory>(DynamicLoadObject(templist[weapIndex], class'Class'));;
    `Log("### Random weapon:"@randWeapon);
    
    // Ensure we don't give duplicate items
    if (UTP.FindInventoryType( randWeapon ) == None)
    {
    UTP.CreateInventory(randWeapon);
    } else {
    `Log("### Player already has the weapon '"$randWeapon$"'");
    }
    
    // Remove the weapon in any cases, cause the player already has an additional weapon
    // arrayreference.Remove(index, count);
    templist.Remove(weapIndex, 1);
    }
    
    }
    
    defaultproperties
    {
    WeaponCount=8
    
    WeaponsList.Empty
    
    WeaponsList(0)="UTGame.UTWeap_FlakCannon"
    WeaponsList(1)="UTGame.UTWeap_LinkGun"
    WeaponsList(2)="UTGame.UTWeap_RocketLauncher"
    WeaponsList(3)="UTGame.UTWeap_ShockRifle"
    WeaponsList(4)="UTGame.UTWeap_SniperRifle"
    WeaponsList(5)="UTGame.UTWeap_Stinger"
    WeaponsList(6)="UTGameContent.UTWeap_BioRifle_Content"
    WeaponsList(7)="UTGame.UTWeap_Enforcer"
    
    //WeaponsList(8)="Ripper.UTWeap_Ripper"
    //WeaponsList(9)="RipperLite.UTWeap_RipperLite"
    
    //WeaponsList(8)="UTGameContent.UTWeap_Translocator_Content"
    //WeaponsList(9)="UTGameContent.UTWeap_Redeemer_Content"
    //WeaponsList(10)="UTGameContent.UTWeap_Avril_Content"
    //WeaponsList(11)="UTGame.UTWeap_ImpactHammer"
    //WeaponsList(12)="UTGame.UTWeap_InstaGibRifle"
    }

    #2
    Compiled and tested in instant action in DM. The mutator started my pawn with the impact hammer selected as weapon 0 from line 14 this code, and added the 8 weapons to my inventory , and in a random order, just as you have iterated.

    ScriptLog: ### ModifyPlayer: UTPawn_0
    ScriptLog: ### Adding weapon #0
    ScriptLog: ### Random weapon: UTWeap_ShockRifle
    ScriptLog: ### Adding weapon #1
    ScriptLog: ### Random weapon: UTWeap_LinkGun
    ScriptLog: ### Adding weapon #2
    ScriptLog: ### Random weapon: UTWeap_Stinger
    ScriptLog: ### Adding weapon #3
    ScriptLog: ### Random weapon: UTWeap_FlakCannon
    ScriptLog: ### Adding weapon #4
    ScriptLog: ### Random weapon: UTWeap_BioRifle_Content
    ScriptLog: ### Adding weapon #5
    ScriptLog: ### Random weapon: UTWeap_SniperRifle
    ScriptLog: ### Adding weapon #6
    ScriptLog: ### Random weapon: UTWeap_RocketLauncher
    ScriptLog: ### Adding weapon #7
    ScriptLog: ### Random weapon: UTWeap_Enforcer

    If it does nothing at all, you can check your launch log to see if it loaded at all. If the mod shows to have loaded, but you do not get your scriptlogs, you may need to clear old non-working builds from your cooked script directory, cache, configs, etc.

    Comment


      #3
      But the script should not give you all the weapons. The idea is that you start with one primary and one secondary weapon only, the first one chosen randomly from the list. So, everytime you spawn, you may start with a flak cannot + the impact hammer, or with the linkgun + the impact hammer, or the sniper rifle + the impact hammer, or with a custom weapon + scarab grenades (my replacement for the impact hammer). I don't remember well, but I think I got this working like this some years ago.

      Comment


        #4
        bleah. You can correct this by iterating your array first, then do the UTP.CreateInventory(randWeapon). It can be made more efficient by iterating the array in order once to set index for your dynamic ones, then just giving the weapon to random index on the modify player, so you don't iterate each time.

        Comment


          #5
          Thanx NickG, but I have no idea of programming. I just copied the code from other script and with the help of the guys in the forum it was modified until I got something that worked as I wanted. Can you please be so kind to edit this code for me?

          Comment


            #6
            OK, looks like I misunderstood some of this earlier, so my last post was not accurate.
            I added to RattleSn4kes mutator.
            You may now start your pawns with default weapon(s) of your choosing, such as your grenades, by adding DefaultWeapons= lines to the RSW.ini, and setting DefaultCount to the amount you wish.
            You may now start your pawns with amount of random weapons specified by WeaponsList= lines in the RSW.ini, and setting the WeaponCount to the amount of random weapons you wish.
            For your example before, you would config ini like this, or replace hammer reference with the scarab grenade path:

            [RSW.UTMutator_RSW]
            DefaultCount=1
            DefaultWeapons=UTGame.UTWeap_ImpactHammer

            WeaponCount=1
            WeaponsList=UTGame.UTWeap_FlakCannon
            WeaponsList=UTGame.UTWeap_LinkGun
            WeaponsList=UTGame.UTWeap_RocketLauncher
            WeaponsList=UTGame.UTWeap_ShockRifle
            WeaponsList=UTGame.UTWeap_SniperRifle
            WeaponsList=UTGame.UTWeap_Stinger
            WeaponsList=UTGameContent.UTWeap_BioRifle_Content
            WeaponsList=UTGame.UTWeap_Enforcer

            For static loadouts only, uncomment any my DefaultWeapons lines already in ini, and add your third-party weapons lines directly instead of using weaponreplacement mutator, increase DefaultCount, set WeaponCount=0
            For randoms only, set DefaultCount=0, add thirdparty references, comment out with semicolon or remove ones you don't like, set DefaultCount=0
            Be warned, you probably get some funny behavior if DefaultCount+WeaponCount exceeds weapon slots, and some weapons do not show correct on hud.

            rename to RSW.zip and this should contain .u file and .ini file
            RSW.zip.txt

            Comment


              #7
              Thanx a lot man. I'm eager to try this when I arrive home tonight.

              Comment


                #8
                At this moment, I would also rewrite that mutator . One thing which should be added is to ensure always adding at least the amount of weapons specified by WeaponCount. Otherwise weapons which are added to the config file and might not be properly installed won't be created. A player might end up having only 1 weapon even if 2 weapons should be created. That mutator from that referenced thread was written within minutes on this forum editor without even compiling it. Such mutator could also need a config UI scene.

                NickG's modification should work in general (judging from the code).

                Comment


                  #9
                  Sounds like an awesome mutator. How good are you at coding?


                  Sent from my iPhone using Tapatalkpp

                  Comment


                    #10
                    If you are talking to me..pretty darn good.
                    If you are talking to Rattle, just multiply the pretty or the darn a few times.

                    Comment


                      #11
                      I'm tanking to all of you, because I need coders for sl2


                      Sent from my iPhone using Tapatalkpp

                      Comment


                        #12
                        Such a role is probably beyond my ability and/or amount of free time...

                        Comment


                          #13
                          If I didn't mess up the link again (or get deleted?), here is a temporary upload of the same file from post #6 with properly named file extension, for convenience:
                          http://www.gamefront.com/files/24366921/RSW.zip

                          Comment

                          Working...
                          X