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.

UE1 - UT Coding Bot Behavior

Discussion in 'Programming' started by Rajada, Jul 27, 2008.

  1. Rajada

    Rajada Member

    Joined:
    Jan 21, 2008
    Messages:
    213
    Likes Received:
    0
    Well I am in the midst of creating a project for a UT engine based game, and I realized I was getting stuck on the same issue.

    Unreal's "Monsters" all use "Ranged Attacks", therefore never holding a weapon. I need to force my new Bot (a subclass of bot) to have a default weapon that I select via some code. So I tried this:

    BTW, "Whomper" is a built in weapon that came with the game, so there is no problems with the weapon itself.

    Code:
    function PostBeginPlay()
    {
    
    EquipPlayer(self);
    
    }
    function EquipPlayer( pawn Player )
    {
    
    	local Whomper s;
    
    if ( Player.FindInventoryType(class'Whomper') == None )
        {
        	//spawn a depositor weapon and attach it to bots inventory
        	s = Spawn(class'Whomper',,, Location);
        	if (s != None)
        	{
        		s.bHeldItem = true;
        		s.GiveTo( Player );
        		s.pickupammocount = 999;
        	}
    
    
    }
    }
    He recieves the weapon, but is unable to fire it! When I kill him, I can pick it up and it does in fact have 999 ammo like I coded it. Is there an easier way to do this? Or am I just doing something completely wrong?
     
    Last edited: Jul 27, 2008
  2. Zur

    Zur surrealistic mad cow

    Joined:
    Jul 8, 2002
    Messages:
    11,717
    Likes Received:
    4
    In UT you can do something like this to give a weapon to a bot.

    PHP:
    function GivePickupPawn Pstring ItemClass )
    {
        
    local class<TournamentPickupPUClass;
        
    local Pickup PU;

        
    PUClass = class<TournamentPickup>(DynamicLoadObject(ItemClass, class'Class'));

        
    PU SpawnPUClass );

        if( 
    PU != none )
        {
            
    PU.Touch); // Touch player
            
    PU.Destroy();
        }
    }
     
  3. Rajada

    Rajada Member

    Joined:
    Jan 21, 2008
    Messages:
    213
    Likes Received:
    0
    I tried this:

    Code:
    function GivePickup( Pawn P, string ItemClass )
    {
        local class<NerfWeapon> PUClass;
        local Weapon PU;
    
        PUClass = class<NerfWeapon>(DynamicLoadObject(ItemClass, class'Whomper'));
    
        PU = Spawn( PUClass );
    
        if( PU != none )
        {
            PU.Touch( P ); // Touch player
            PU.Destroy();
        }
    }  

    But he does not recieve the weapon.
    Whomper is located in this way:

    As you can see it is not a subclass of "Pickup"


    Inventory > Weapon > NerfWeapon > Whomper
    > PickUp
     
    Last edited: Jul 27, 2008
  4. Zur

    Zur surrealistic mad cow

    Joined:
    Jul 8, 2002
    Messages:
    11,717
    Likes Received:
    4
    Oops, that should work for pickups but I don't know if it will work for weapons. Try looking up what the name of the pickup class is in the game you're modifying. This should replace TournamentPickup. class'Class' should remain as it is. One question remains is whether your game supports dynamic loading. Note that in UT Pickup extends Inventory.

    I've had a look at LMS and the usual way to give weapons seems to be this :

    PHP:
    DeathMatchPlus(Level.Game).GiveWeaponPlayerPawn(P), "BotPack.SniperRifle" );
    Here's the GiveWeapon function from DeathMatchPlus (similar to the one above) :

    PHP:
    function GiveWeapon(Pawn PlayerPawnstring aClassName )
    {
        
    local class<WeaponWeaponClass;
        
    local Weapon NewWeapon;

        
    WeaponClass = class<Weapon>(DynamicLoadObject(aClassName, class'Class'));

        if( 
    PlayerPawn.FindInventoryType(WeaponClass) != None )
            return;
        
    newWeapon Spawn(WeaponClass);
        if( 
    newWeapon != None )
        {
            
    newWeapon.RespawnTime 0.0;
            
    newWeapon.GiveTo(PlayerPawn);
            
    newWeapon.bHeldItem true;
            
    newWeapon.GiveAmmo(PlayerPawn);
            
    newWeapon.SetSwitchPriority(PlayerPawn);
            
    newWeapon.WeaponSet(PlayerPawn);
            
    newWeapon.AmbientGlow 0;
            if ( 
    PlayerPawn.IsA('PlayerPawn') )
                
    newWeapon.SetHand(PlayerPawn(PlayerPawn).Handedness);
            else
                
    newWeapon.GotoState('Idle');
            
    PlayerPawn.Weapon.GotoState('DownWeapon');
            
    PlayerPawn.PendingWeapon None;
            
    PlayerPawn.Weapon newWeapon;
        }
    }
     
    Last edited: Jul 28, 2008
  5. Rajada

    Rajada Member

    Joined:
    Jan 21, 2008
    Messages:
    213
    Likes Received:
    0
    Thank you, with a little modification for different class names, I got that working. I do have one more question. I want this pawn to ba able to roam around a level, but I do not want him to be able to pick up other weapons, pickups or ammo. Is there an easy way to cover all three of those? If not, the important one is weapons, he can't be able to get new weapons.

    I tried a function where once he touched a new weapon, it set the lifespan of that weapon to 1, deleting it. But that would also affect the above code, and delete the Whomper I just forced him to have. Any ideas?
     
    Last edited: Jul 28, 2008
  6. Zur

    Zur surrealistic mad cow

    Joined:
    Jul 8, 2002
    Messages:
    11,717
    Likes Received:
    4
    Any object lying around on a map that can be taken by a player is in pickup state.

    As for what happens when a player touches a pickup, it looks like the logic handling this is inside Pickup or Inventory (see function Touch inside Pickup state). You could rewrite these classes but it would mean having to rewrite all the children classes (same problem as when you replace playerpawns). Perhaps someone knows of a clever way to achieve the same result.

    What you try doing is to have your code ignore the weapon if it's owned by a player or bot. See this reply Wormbo gave in another topic.
     
    Last edited: Jul 28, 2008
  7. Rajada

    Rajada Member

    Joined:
    Jan 21, 2008
    Messages:
    213
    Likes Received:
    0
    Wow, that is the most depressing amount of information that I haven't a clue how to sort out.
     
    Last edited: Jul 29, 2008
  8. Zur

    Zur surrealistic mad cow

    Joined:
    Jul 8, 2002
    Messages:
    11,717
    Likes Received:
    4
    Just concentrate on the last phrase. If you skip a weapon that's being held by a player that should do the trick.

    The problem with replacing a parent class is that unrealscript doesn't support multiple inheritance (C++) or interfaces (Java) which is fiddly anyway. In short, this means that if you modify a tree root you will also have to modify all of it's branches.
     

    Attached Files:

    Last edited: Jul 29, 2008
  9. Rajada

    Rajada Member

    Joined:
    Jan 21, 2008
    Messages:
    213
    Likes Received:
    0
    Yes, I do have enough of an understanding to know that modifying a parent class requires that you change it's child classes, however, I have tried several ways to make them "Skip a weapon" but have failed so far. I will try to dig up some of the old code I used to show you what I mean.

    Hmmm...here's a thought... the weapon I plan on forcing to them will have infinite ammo, is there a way to make this weapon so desireable that they never switch to any other?
     
    Last edited: Jul 29, 2008

Share This Page