Announcement

Collapse
No announcement yet.

Problem with Ammo Replacement for Custom Weapon

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

    Problem with Ammo Replacement for Custom Weapon

    So Im coding this weapon, calling it SLGun and I am having some trouble getting my ammo to show up. Here is the code:

    Code:
    class MutSLGun extends Mutator
        config(user);
    
    //=============================================================================
    function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
    {
        local int i;
        local WeaponLocker L;
    
        bSuperRelevant = 0;
    
        if ( xWeaponBase(Other) != None )
        {
            if ( string( xWeaponBase(Other).WeaponType ) ~= "XWeapons.SniperRifle" )
            {
                xWeaponBase(Other).WeaponType = class'SLGun';
                return false;
            }
        }
        else if ( WeaponPickup(Other) != None )
        {
            if ( string(Other.Class) ~= "XWeapons.SniperRiflePickup" )
            {
                ReplaceWith( Other, "SLGunPickup" );
                return false;
            }
        }
        else if ( WeaponLocker(Other) != None )
        {
            L = WeaponLocker(Other);
    
            for (i = 0; i < L.Weapons.Length; i++)
            {
                if ( string( L.Weapons[i].WeaponClass ) ~= "XWeapons.SniperRifle" )
                    L.Weapons[i].WeaponClass = class'SLGun';
            }
        }
        
    
        else if (Other.IsA('SniperAmmoPickup') )
        {
    		ReplaceWith(Other, "SLGun.SLGunAmmoPickup");
    		return False;
        }
    
        return true;
    }
    //
    //
    //
    //function bool CheckReplacement(Actor Other, out byte bSuperRelevant)
    //{
    //	local int i;
    //	local WeaponLocker L;
    //
    //	if (Other.IsA('SniperAmmoPickup') )
    //	{
    //		ReplaceWith(Other, "SLGun.SLGunAmmoPickup");
    //		return False;
    //	}
    //
    //	return True;
    //}
    
    
    
    //=============================================================================
    defaultproperties
    {
         GroupName="**Elite Super Lightning Gun**"
         FriendlyName="**Elite Super Lightning Gun**"
         Description="This mutator replaces the Lightning Gun with the Elite Super Lightning Gun. The weapon is enhanced and more advanced the the normal Lightning Gun.||This Mutator was created by Charybdis (Aaron Ash).|Some original code by RoseBum."
    }
    When I play with the mutator, the following error report appears after Unreal Crashes:
    Code:
    UT2004 Build UT2004_Build_[2005-11-23_16.22]
    
    OS: Windows XP 5.1 (Build: 2600)
    CPU: AuthenticAMD Unknown processor @ -3997 MHz with 1023MB RAM
    Video: NVIDIA GeForce 6800 GS  (9371)
    
    mutsatoreMonsterPack DM-INV-RedTiles.mutsatoreMonsterPack (Function Engine.Mutator.AlwaysKeep:0000) Infinite script recursion (250 calls) detected
    
    History: FFrame::Serialize <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoPickup) <- UObject::ProcessEvent <- (SLGunAmmoPickup DM-INV-RedTiles.SLGunAmmoPickup, Function Engine.Actor.PreBeginPlay) <- ULevel::SpawnActor <- (SLGunAmmoP
    It appears to be stuck in some kind of infinite loop (Infinite script recursion (250 calls) detected), does anyone see a flaw in my code?

    Thanks for the help,
    Charybdis

    #2
    This is the standard code used to replace weapons and ammo:

    Code:
    function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
    {
        if ( xWeaponBase(Other) != None )
        {
            if ( xWeaponBase(Other).WeaponType == class'SniperRifle' )
                xWeaponBase(Other).WeaponType = class'SLGun.SLGun';
            else
                return true;
        }
    
        else if ( WeaponPickup(Other) != None )
        {
            if ( string(Other.Class) == "xWeapons.SniperRiflePickup" )
                ReplaceWith( Other, "SLGun.SLGunPickup");
            else
                return true;
        }
        else if ( Pickup(Other) != None )
        {
            if ( string(Other.Class) == "XWeapons.SniperAmmoPickup" )
                ReplaceWith( Other, "SLGun.SLGunAmmoPickup");
            else
                return true;
        }
        else
            return true;
    
        return false;
    }
    i've modified it to swap the sniper for yours.

    Also don't forget this line in the default properties to automatically add the mutator to serverpackages.

    Code:
    bAddToServerPackages=True
    also try testing it out on a stock map as the one you are using may have problems.

    Comment


      #3
      Even better:
      Code:
      function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
      {
      	local int i;
      	local WeaponLocker L;
      
      	if ( xWeaponBase(Other)!=None && xWeaponBase(Other).WeaponType==Class'SniperRifle' )
      		xWeaponBase(Other).WeaponType = class'SLGun';
      	else if ( Other.Class==Class'SniperRiflePickup' && ReplaceWith( Other, string(Class'SLGunPickup')) )
      		return false;
      	else if ( WeaponLocker(Other) != None )
      	{
      		L = WeaponLocker(Other);
      		for (i = 0; i < L.Weapons.Length; i++)
      		{
      			if ( L.Weapons[i].WeaponClass==Class'SniperRifle' )
      				L.Weapons[i].WeaponClass = class'SLGun';
      		}
      	}
      	else if ( Other.Class==Class'SniperAmmoPickup' && ReplaceWith(Other, string(Class'SLGunAmmoPickup')) )
      		return False;
      	return true;
      }
      I belive your loop was with ammo replacement IF your SLGunAmmoPickup extends SniperAmmoPickup, then it tried to replace the orginal ammo, then replace the replacement ammo etc...

      Comment


        #4
        thank you very much! I am pretty much a noob at codings so thanks for the help.
        I'll try that out.

        It worked! Thanks

        Comment

        Working...
        X