Announcement

Collapse
No announcement yet.

A quick question: how to make "if" require multiple conditions to be met?

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

    A quick question: how to make "if" require multiple conditions to be met?

    Let's say that I want to check each weapon locker for a shock rifle in the weapon slots 0, 1, 2 and 3:
    Code:
    function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
    {
    	local WeaponLocker L;
    
    	bSuperRelevant = 0;
    
    	if ( WeaponLocker(Other) != None )
    	{
    		L = WeaponLocker(Other);
    			if (L.Weapons[0].WeaponClass != class'ShockRifle')
    Now, I reached the place where I use "if" to check whether there is a shock rifle on the locker's slot 0. However, I want "if" to require slots 1, 2 and 3 not to have a shock rifle as well. How to do this?

    #2
    Could do something like this:

    Code:
    function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
    {
    	local WeaponLocker L;
            local bool bShockIsPresent;
            local int i;
    
    	bSuperRelevant = 0;
    
    	if ( WeaponLocker(Other) != None )
    	{
    		L = WeaponLocker(Other);
                    for(i=0;i<L.Weapons.length;i++)
                    {
    		        if (L.Weapons[i].WeaponClass != class'ShockRifle')
                                    bShockIsPresent = true;
                    }
    
                    if(!bShockIsPresent)
                            DoSomeStuff();
            }
    }

    Comment


      #3
      Thanks.
      What I'm working on is a mut that checks each weapon locker for a shock, a link, and an AVRiL. If any of those are missing, it would change the weapon locker's contents to Shock, Link, AVRiL, and Flak. In theory it should work, but it doesn't sometimes it replaces all lockers' contents, even if they had shock, link and AVRiL, sometimes it doesn't replace anything at all, sometimes it does other wacky stuff. Does any1 know what could be wrong? Here's the whole script:

      Code:
      class MutWeaponLockerControl extends Mutator;
      
      function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
      {
      	local int i;
      	local WeaponLocker L;
      	local bool bShockIsPresent;
      	local bool bAvrilIsPresent;
      	local bool bLinkIsPresent;
      	local bool bLockerIsFine;
      
      	bSuperRelevant = 0;
      
      	if ( WeaponLocker(Other) != None )
      	{
      		L = WeaponLocker(Other);
      		for(i=0; i<L.Weapons.Length; i++)
      		{
      			if(L.Weapons[i].WeaponClass == class'ShockRifle')
      				bShockIsPresent = true;
      		}
      		
      		L = WeaponLocker(Other);
      		for(i=0; i<L.Weapons.Length; i++)
      		{
      			if(L.Weapons[i].WeaponClass == class'ONSAvril')
      				bAvrilIsPresent = true;
      		}
      
      		L = WeaponLocker(Other);
      		for(i=0; i<L.Weapons.Length; i++)
      		{
      			if(L.Weapons[i].WeaponClass == class'LinkGun')
      				bLinkIsPresent = true;
      		}
      
      		if(bShockIsPresent)
      		{
      			if(bAvrilIsPresent)
      			{
      				if(bLinkIsPresent)
      				{
      					bLockerIsFine = true;
      				}
      			}
      		}
      
      		if(!bLockerIsFine)
      				L.Weapons[0].WeaponClass = class'LinkGun';
      				L.Weapons[0].ExtraAmmo = 40;
      				L.Weapons[1].WeaponClass = class'ShockRifle';
      				L.Weapons[1].ExtraAmmo = 20;
      				L.Weapons[2].WeaponClass = class'FlakCannon';
      				L.Weapons[2].ExtraAmmo = 10;
      				L.Weapons[3].WeaponClass = class'ONSAvril';
      				L.Weapons[3].ExtraAmmo = 0;
      				L.Weapons[4].WeaponClass = None;
      				L.Weapons[4].ExtraAmmo = 0;
      				L.Weapons[5].WeaponClass = None;
      				L.Weapons[5].ExtraAmmo = 0;
      				L.Weapons[6].WeaponClass = None;
      				L.Weapons[6].ExtraAmmo = 0;
      				L.Weapons[7].WeaponClass = None;
      				L.Weapons[7].ExtraAmmo = 0;
      				L.Weapons[8].WeaponClass = None;
      				L.Weapons[8].ExtraAmmo = 0;
      				L.Weapons[9].WeaponClass = None;
      				L.Weapons[9].ExtraAmmo = 0;
      				L.Weapons[10].WeaponClass = None;
      				L.Weapons[10].ExtraAmmo = 0;
      				L.Weapons[11].WeaponClass = None;
      				L.Weapons[11].ExtraAmmo = 0;
      				L.Weapons[12].WeaponClass = None;
      				L.Weapons[12].ExtraAmmo = 0;
      
      
      
      
      
      		return true;
      
      	}
      	else
      		return true;
      	return false;
      }
      
      defaultproperties
      {
          IconMaterialName="MutatorArt.nosym"
          GroupName="Arena"
          FriendlyName="Weapon Locker Control"
          Description="Ensures that every weapon locker in the map has a link gun, a shock rifle and an AVRiL."
      }

      Comment


        #4
        In case you're wondering about boolean operators (&& and ||)... here's a few quick examples:
        Code:
        // Checking if at least one condition is met:
        if(a || b || c) DoStuff(); // Do stuff if any of a, b or c is true.
        
        // Checking if all conditions are met:
        if(a && b && c) DoStuff(); // Do stuff if a, b and c are all true.
        
        // A combination of the above:
        if(a && !(b || c)) DoStuff(); // Do stuff if a is true but b and c are not.

        Comment


          #5
          WOW, that certainly helps! Thanks Xyx!!

          Comment


            #6
            You probably dont need any more knowledge on operators than what Xyx mentioned, but in case you do, go to UnrealWiki. If you need to figure something out, you'll most likely find it there. Best way to use it is to download the offline version of UnrealWiki and use Windows' Search to find keywords inside the files

            Comment

            Working...
            X