News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 27th Jul 2008, 03:34 PM   #1
Rajada
Registered User
 
Join Date: Jan. 21st, 2008
Posts: 210
Coding Bot Behavior

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?
__________________
How to play NAB


Last edited by Rajada; 27th Jul 2008 at 03:36 PM.
Rajada is offline   Reply With Quote
Old 27th Jul 2008, 06:54 PM   #2
Zur
surrealistic mad cow
 
Zur's Avatar
 
Join Date: Jul. 8th, 2002
Posts: 11,682
In UT you can do something like this to give a weapon to a bot.

PHP Code:
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();
    }

__________________

Zur is offline   Reply With Quote
Old 27th Jul 2008, 09:16 PM   #3
Rajada
Registered User
 
Join Date: Jan. 21st, 2008
Posts: 210
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
__________________
How to play NAB


Last edited by Rajada; 27th Jul 2008 at 09:17 PM.
Rajada is offline   Reply With Quote
Old 28th Jul 2008, 07:08 AM   #4
Zur
surrealistic mad cow
 
Zur's Avatar
 
Join Date: Jul. 8th, 2002
Posts: 11,682
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 Code:
DeathMatchPlus(Level.Game).GiveWeaponPlayerPawn(P), "BotPack.SniperRifle" ); 
Here's the GiveWeapon function from DeathMatchPlus (similar to the one above) :

PHP Code:
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 by Zur; 28th Jul 2008 at 07:12 AM.
Zur is offline   Reply With Quote
Old 28th Jul 2008, 01:05 PM   #5
Rajada
Registered User
 
Join Date: Jan. 21st, 2008
Posts: 210
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?
__________________
How to play NAB


Last edited by Rajada; 28th Jul 2008 at 01:19 PM.
Rajada is offline   Reply With Quote
Old 28th Jul 2008, 11:52 PM   #6
Zur
surrealistic mad cow
 
Zur's Avatar
 
Join Date: Jul. 8th, 2002
Posts: 11,682
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.

Quote:
Originally Posted by Rajada View Post
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 by Zur; 28th Jul 2008 at 11:57 PM.
Zur is offline   Reply With Quote
Old 29th Jul 2008, 08:06 PM   #7
Rajada
Registered User
 
Join Date: Jan. 21st, 2008
Posts: 210
Wow, that is the most depressing amount of information that I haven't a clue how to sort out.
__________________
How to play NAB


Last edited by Rajada; 29th Jul 2008 at 08:08 PM.
Rajada is offline   Reply With Quote
Old 29th Jul 2008, 08:36 PM   #8
Zur
surrealistic mad cow
 
Zur's Avatar
 
Join Date: Jul. 8th, 2002
Posts: 11,682
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 Thumbnails
Click image for larger version

Name:	object_problem.png
Views:	3
Size:	15.7 KB
ID:	96189  
__________________


Last edited by Zur; 29th Jul 2008 at 08:43 PM.
Zur is offline   Reply With Quote
Old 29th Jul 2008, 09:19 PM   #9
Rajada
Registered User
 
Join Date: Jan. 21st, 2008
Posts: 210
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?
__________________
How to play NAB


Last edited by Rajada; 29th Jul 2008 at 09:40 PM.
Rajada is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:15 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer