1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

UE3 - UT3 Random weapons respawn Mutator

Discussion in 'Programming' started by LLIAXTEP, Sep 21, 2018.

  1. LLIAXTEP

    LLIAXTEP New Member

    Joined:
    Jun 4, 2018
    Messages:
    4
    Likes Received:
    0
    This code perfectly run on server and in singleplayer, but all clients which connected to the server will crash after a few minutes.
    Code:
    function ReplaceWeaponPickup (UTWeaponPickupFactory WeaponPickup, int SwapIndex)
    {
        if (WeaponSwaps[SwapIndex].CurrentIndex > -1 &&
            WeaponSwaps[SwapIndex].NewWeaponNames.length > WeaponSwaps[SwapIndex].CurrentIndex &&
            WeaponSwaps[SwapIndex].NewWeaponNames[WeaponSwaps[SwapIndex].CurrentIndex]!="")
        {
            WeaponPickup.WeaponPickupClass = class<UTWeapon>(DynamicLoadObject(WeaponSwaps[SwapIndex].NewWeaponNames[WeaponSwaps[SwapIndex].CurrentIndex], class'Class'));
            WeaponPickup.InitializePickup();
            WeaponPickup.Customers.length = 0;
        }
    }
    
    function ReplaceAmmoPickup (UTAmmoPickupFactory AmmoPickup, int SwapIndex)
    {
        local class <UTAmmoPickupFactory> NewAmmoClass;
    
        // Change it now
        if (WeaponSwaps[SwapIndex].CurrentIndex > -1 &&
            WeaponSwaps[SwapIndex].NewAmmoNames.length > WeaponSwaps[SwapIndex].CurrentIndex &&
            WeaponSwaps[SwapIndex].NewAmmoNames[WeaponSwaps[SwapIndex].CurrentIndex]!="")
        {
            NewAmmoClass = class<UTAmmoPickupFactory>(DynamicLoadObject(WeaponSwaps[SwapIndex].NewAmmoNames[WeaponSwaps[SwapIndex].CurrentIndex], class'Class'));
            if (NewAmmoClass != None)
            {
                // transform the current ammo into the desired class
                AmmoPickup.TransformAmmoType(NewAmmoClass);
            }
        }
    }
    
    // Randomly swap all factories to different weapons
    
    function WeaponChangeTimer()
    {
        local int i, j, r, Index;
    
        // Run through all swaps
        for (i=0; i<WeaponSwaps.length; i++)
        {
            // Only bother if it has more than 1 new possibility
            if (WeaponSwaps[i].NewWeaponNames.length > 1)
            {
                // Try pick a new random index
                r = Rand(WeaponSwaps[i].NewWeaponNames.length);
                if (r == WeaponSwaps[i].CurrentIndex)
                {
                    r++;
                    if (r >= WeaponSwaps[i].NewWeaponNames.length)
                        r=0;
                }
                WeaponSwaps[i].CurrentIndex = r;
    
                // Replace all weapon pickups
                for (j=0; j<WeaponSwaps[i].WeaponFactories.length; j++)
                {
                    if (WeaponSwaps[i].WeaponFactories[j].Factory != None &&
                        WorldInfo.TimeSeconds >= WeaponSwaps[i].WeaponFactories[j].NextChangeTime &&
                        (WeaponSwaps[i].WeaponFactories[j].Factory.bPickupHidden || !WeaponSwaps[i].WeaponFactories[j].Factory.PlayerCanSeeMe()))
                    {
                        ReplaceWeaponPickup(WeaponSwaps[i].WeaponFactories[j].Factory, i);
                        WeaponSwaps[i].WeaponFactories[j].NextChangeTime = WorldInfo.TimeSeconds + SwapInterval;
                    }
                }
    
                // Replace all ammo pickups
                for (j=0; j<WeaponSwaps[i].AmmoFactories.length; j++)
                {
                    if (WeaponSwaps[i].AmmoFactories[j].Factory != None &&
                        WorldInfo.TimeSeconds >= WeaponSwaps[i].AmmoFactories[j].NextChangeTime &&
                        (WeaponSwaps[i].AmmoFactories[j].Factory.bPickupHidden || !WeaponSwaps[i].AmmoFactories[j].Factory.PlayerCanSeeMe()))
                    {
                        ReplaceAmmoPickup(WeaponSwaps[i].AmmoFactories[j].Factory, i);
                        WeaponSwaps[i].AmmoFactories[j].NextChangeTime = WorldInfo.TimeSeconds + SwapInterval;
                    }
                }
            }
        }
        for (i=0; i<Lockers.length; i++)
        {
            if ( Lockers[i].Locker != None &&
                 WorldInfo.TimeSeconds >= WeaponSwaps[i].AmmoFactories[j].NextChangeTime &&
                 !Lockers[i].Locker.PlayerCanSeeMe() )
            {
                for (j = 0; j < Lockers[i].Locker.Weapons.length; j++)
                {
                    if (Lockers[i].Locker.Weapons[j].WeaponClass != None)
                    {
                        Index = WeaponSwaps.Find( 'OldWeaponName', Lockers[i].Locker.Weapons[j].WeaponClass.Name);
                        if (Index != INDEX_NONE &&
                            WeaponSwaps[Index].CurrentIndex > -1 &&
                            WeaponSwaps[Index].NewWeaponNames.length > WeaponSwaps[Index].CurrentIndex &&
                            WeaponSwaps[Index].NewWeaponNames[WeaponSwaps[Index].CurrentIndex]!="")
                        {
                            Lockers[i].Locker.ReplaceWeapon(j, class<UTWeapon>(DynamicLoadObject(WeaponSwaps[Index].NewWeaponNames[WeaponSwaps[Index].CurrentIndex], class'Class')));
                        }
                    }
    //                else
    //                    break;
                }
            }
        }
    }
    
    // Check for item replacement.
    function bool CheckReplacement(Actor Other)
    {
        local UTAmmoPickupFactory AmmoPickup;
        local UTWeaponPickupFactory WeaponPickup;
    //    local class <UTAmmoPickupFactory> NewAmmoClass;
        local UTWeaponLocker Locker;
        local int i, Index;
    
        // Got a weapon pickup factory
        WeaponPickup = UTWeaponPickupFactory(Other);
        if (WeaponPickup != None)
        {
            if (WeaponPickup.WeaponPickupClass != None)
            {
                // Check if this WPF is to be replaced
                Index = WeaponSwaps.Find( 'OldWeaponName', WeaponPickup.WeaponPickupClass.Name);
                if (Index != INDEX_NONE)
                {
                    // Remember this WPF. We will need to mess with it later
                    WeaponSwaps[Index].WeaponFactories.length = WeaponSwaps[Index].WeaponFactories.length + 1;
                    WeaponSwaps[Index].WeaponFactories[WeaponSwaps[Index].WeaponFactories.length-1].Factory = WeaponPickup;
    
                    // Change it now
                    ReplaceWeaponPickup(WeaponPickup, Index);
                    WeaponSwaps[Index].WeaponFactories[WeaponSwaps[Index].WeaponFactories.length-1].NextChangeTime = WorldInfo.TimeSeconds + SwapInterval;
                }
            }
        }
        // Got a locker
        else
        {
            Locker = UTWeaponLocker(Other);
            if (Locker != None)
            {
    //            Bookmark the locker so we can easily mess with it later!
                Lockers.length = Lockers.length + 1;
                Lockers[Lockers.length-1].Locker = Locker;
                Lockers[Lockers.length-1].NextChangeTime = WorldInfo.TimeSeconds + SwapInterval;
                for (i = 0; i < Locker.Weapons.length; i++)
                {
                    if (Locker.Weapons[i].WeaponClass != None)
                    {
                        Index = WeaponSwaps.Find( 'OldWeaponName', Locker.Weapons[i].WeaponClass.Name);
                        if (Index != INDEX_NONE &&
                            WeaponSwaps[Index].CurrentIndex > -1 &&
                            WeaponSwaps[Index].NewWeaponNames.length > WeaponSwaps[Index].CurrentIndex &&
                            WeaponSwaps[Index].NewWeaponNames[WeaponSwaps[Index].CurrentIndex]!="")
                        {
                            Locker.ReplaceWeapon(i, class<UTWeapon>(DynamicLoadObject(WeaponSwaps[Index].NewWeaponNames[WeaponSwaps[Index].CurrentIndex], class'Class')));
                        }
                    }
    //                else
    //                    break;
                }
            }
            // Got ammo
            else
            {
                AmmoPickup = UTAmmoPickupFactory(Other);
                if (AmmoPickup != None)
                {
                    // Check if this APF is to be replaced
                    Index = WeaponSwaps.Find( 'OldAmmoName', AmmoPickup.class.Name);
                    if (Index != INDEX_NONE)
                    {
                        // Remember this APF. We will need to mess with it later
                        WeaponSwaps[Index].AmmoFactories.length = WeaponSwaps[Index].AmmoFactories.length + 1;
                        WeaponSwaps[Index].AmmoFactories[WeaponSwaps[Index].AmmoFactories.length-1].Factory = AmmoPickup;
    
                        // Change it now
                        ReplaceAmmoPickup(AmmoPickup, Index);
                        WeaponSwaps[Index].AmmoFactories[WeaponSwaps[Index].AmmoFactories.length-1].NextChangeTime = WorldInfo.TimeSeconds + SwapInterval;
                    }
                }
            }
        }
        LastReplaceTime = WorldInfo.TimeSeconds;
        return true;
    }
    What's the problem and how to fix it? Any suggestions?
    I think this is some sort of pickups duplication, or maybe not. I tried many things, but nothing helped. I don't know what to do...
     

Share This Page