UE1 - UT Coding Bot Behavior

  • 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.

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
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:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
In UT you can do something like this to give a weapon to a bot.

PHP:
function GivePickup( Pawn P, string ItemClass )
{
	local class<TournamentPickup> PUClass;
	local Pickup PU;

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

	PU = Spawn( PUClass );

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

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
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:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
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).GiveWeapon( PlayerPawn(P), "BotPack.SniperRifle" );

Here's the GiveWeapon function from DeathMatchPlus (similar to the one above) :

PHP:
function GiveWeapon(Pawn PlayerPawn, string aClassName )
{
	local class<Weapon> WeaponClass;
	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:

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
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:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
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.

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?

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:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
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.
 

Attachments

  • object_problem.png
    object_problem.png
    15.7 KB · Views: 4
Last edited:

Rajada

Member
Jan 21, 2008
213
0
16
rajada.tumblr.com
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: