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.

Infinite Ammunnition Recursion

Discussion in 'Ask a Coder' started by Smoke39, Jan 1, 2004.

  1. Smoke39

    Smoke39 whatever

    Joined:
    Jun 2, 2001
    Messages:
    1,793
    Likes Received:
    0
    Okay, so I'm trying to make it so inflicting pain gets you ammo, so I did this:

    Code:
    function int NetDamage( int OriginalDamage, int Damage, pawn injured, pawn instigatedBy, vector HitLocation, out vector Momentum, class<DamageType> DamageType )
    {
    	local Ammunition Ammo;
    
    	if ( instigatedBy != None )
    	{
    		Ammo = spawn(class'AmmoEnergy',instigatedBy);
    		Ammo.GiveTo(instigatedBy, None);
    		Ammo.AmmoAmount = 1;
    
    		Ammo = spawn(class'AmmoBullet',instigatedBy);
    		Ammo.GiveTo(instigatedBy, None);
    		Ammo.AmmoAmount = 1;
    
    		Ammo = spawn(class'AmmoExplosive',instigatedBy);
    		Ammo.GiveTo(instigatedBy, None);
    		Ammo.AmmoAmount = 1;
    	}
    
    	if ( NextGameRules != None )
    		return NextGameRules.NetDamage( OriginalDamage,Damage,injured,instigatedBy,HitLocation,Momentum,DamageType );
    	return Damage;
    }
    But after playing for a bit, one of those ammo types crashes the game with an infinite recursion error. Is there some other way I should be awarding ammo or something?
     
  2. Postal

    Postal I apear to have lost my pin.

    Joined:
    Nov 14, 1999
    Messages:
    1,388
    Likes Received:
    0
    Look at the ammo pickup code.
     
  3. EvilDrWong

    EvilDrWong Every line of code elevates you

    Joined:
    Jun 16, 2001
    Messages:
    932
    Likes Received:
    0
    whats the crash look like? thats really weird that itd give you a recursion problem in a case like that...

    Try searching for the ammo then adding to it instead of giving them another copy of that ammo class every time.
    Code:
    local Ammunition tAmmo;
    
    tAmmo=Ammunition(InstigatedBy.FindInventoryType(class'Pork'));
    if(tAmmo!=None)
        tAmmo.AddAmmo(1);
    
     
  4. Postal

    Postal I apear to have lost my pin.

    Joined:
    Nov 14, 1999
    Messages:
    1,388
    Likes Received:
    0
    Dont the Assault Rifle check if you got ammo or not, and if not, it gives it to you?
     
  5. Smoke39

    Smoke39 whatever

    Joined:
    Jun 2, 2001
    Messages:
    1,793
    Likes Received:
    0
    New, apparently non-b0rked code:

    Code:
    function int NetDamage( int OriginalDamage, int Damage, pawn injured, pawn instigatedBy, vector HitLocation, out vector Momentum, class<DamageType> DamageType )
    {
    	local Ammunition Ammo;
    
    	if ( instigatedBy != None )
    	{
    		Ammo = Ammunition(instigatedBy.FindInventoryType(class'AmmoEnergy'));
    		if ( Ammo == None )
    		{
    			Ammo = spawn(class'AmmoEnergy',instigatedBy);
    			Ammo.GiveTo(instigatedBy, None);
    			Ammo.AmmoAmount = 1;
    		}
    		else
    			Ammo.AddAmmo(1);
    
    		Ammo = Ammunition(instigatedBy.FindInventoryType(class'AmmoBullet'));
    		if ( Ammo == None )
    		{
    			Ammo = spawn(class'AmmoBullet',instigatedBy);
    			Ammo.GiveTo(instigatedBy, None);
    			Ammo.AmmoAmount = 1;
    		}
    		else
    			Ammo.AddAmmo(1);
    
    		Ammo = Ammunition(instigatedBy.FindInventoryType(class'AmmoExplosive'));
    		if ( Ammo == None )
    		{
    			Ammo = spawn(class'AmmoExplosive',instigatedBy);
    			Ammo.GiveTo(instigatedBy, None);
    			Ammo.AmmoAmount = 1;
    		}
    		else
    			Ammo.AddAmmo(1);
    	}
    
    	if ( NextGameRules != None )
    		return NextGameRules.NetDamage( OriginalDamage,Damage,injured,instigatedBy,HitLocation,Momentum,DamageType );
    	return Damage;
    }
    Now I just need to make a new subclass of DamageType that has ammo reward information for my weapons to use.
     

Share This Page