PDA

View Full Version : UE1 - UT Coding Bot Behavior


Rajada
27th Jul 2008, 03:34 PM
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.


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?

Zur
27th Jul 2008, 06:54 PM
In UT you can do something like this to give a weapon to a bot.

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
27th Jul 2008, 09:16 PM
I tried this:

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

Zur
28th Jul 2008, 07:08 AM
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 :

DeathMatchPlus(Level.Game).GiveWeapon( PlayerPawn(P), "BotPack.SniperRifle" );

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

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;
}
}

Rajada
28th Jul 2008, 01:05 PM
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?

Zur
28th Jul 2008, 11:52 PM
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 (http://forums.beyondunreal.com/showpost.php?p=2162948&postcount=4) Wormbo gave in another topic.

Rajada
29th Jul 2008, 08:06 PM
Wow, that is the most depressing amount of information that I haven't a clue how to sort out.

Zur
29th Jul 2008, 08:36 PM
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.

Rajada
29th Jul 2008, 09:19 PM
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?