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.

Custom Bot has weapon but won't use it?

Discussion in 'Programming' started by Call me Erdrik, Oct 14, 2004.

  1. Call me Erdrik

    Call me Erdrik Arch Mage

    Joined:
    Nov 24, 1999
    Messages:
    334
    Likes Received:
    0
    I have an actor that spawns Bots seperatly from the GameType.
    Everything works fine except that the bot can't use any weapons.
    I used 'behindview 0' and found that the bot has the weapon but it seems to be stuck abit into the bringup animation. The weapon is pointing down and can barly be seen. Also there is no 3rd person weapon attachment. The bot uses default weaponry, so the weapons aren't at fault. I tried setting the animation settings from xPawn. As well as manually ordering the bot to switch weapons. Neither worked, And I haven't a clue how to fix this.
    I have a completly seperate mod that uses custom bot, that can use both default and custom weaponry. but I can seem any difference between that mod's bots and this ones...

    If anyone even has the slightest hint or suggestion as to what the problem is I would most appreciate it. :D thnx in adv
     
    Last edited: Oct 14, 2004
  2. Call me Erdrik

    Call me Erdrik Arch Mage

    Joined:
    Nov 24, 1999
    Messages:
    334
    Likes Received:
    0
  3. Call me Erdrik

    Call me Erdrik Arch Mage

    Joined:
    Nov 24, 1999
    Messages:
    334
    Likes Received:
    0
    No one is responding and I doubt its becuase they are jerks, so maybe I haven't posted enough info ( Or maybe I'm an impatiant loser lol )

    Well here is the Actor that spawns the bots:
    Code:
    class NPCSpawnPoint extends Actor
    	placeable;
    
    Var()	byte Team;
    Var()	class<NPCPawn> NPCPawnClass;
    Var	Pawn NPCPawn;
    
    Function PostBeginPlay()
    {
    	SetTimer(20,True);
    }
    
    Simulated function Timer()
    {
    	local Weapon newWeapon;
    
    	NPCPawn = Spawn(NPCPawnClass,,,);
    	NPCPawn.Controller = Spawn(NPCPawn.ControllerClass,,,);
    
    	// Spawn default weapon.
    	newWeapon = Spawn(class'AssaultRifle',,,NPCPawn.Location);
    	if( newWeapon != None )
    	{
    		//log("Give Weapon:"$newWeapon);
    		newWeapon.GiveTo(NPCPawn);
    		newWeapon.bCanThrow = false; // don't allow default weapon to be thrown out
    		NPCPawn.Weapon = newWeapon;
    		//log("Got Weapon:"$NPCPawn.Weapon);
    		NPCPawn.Controller.ClientSwitchToBestWeapon();
    	}
    
    	Bot(NPCPawn.Controller).Squad = spawn(class'ASCSquadAI');
    	NPCPawn.Controller.PlayerReplicationInfo.Team = ASCGame(Level.Game).Teams[Team];
    	NPCPawn.Controller.Pawn = NPCPawn;
    
    	//ASCGame(Level.Game).RestartPlayer( Bot(NPCPawn.Controller) );
    	NPCPawn.SetPhysics(PHYS_Falling);
    	Bot(NPCPawn.Controller).SetOrders('Attack', NPCPawn.Controller);
    	Bot(NPCPawn.Controller).PreviousPawnClass = Class'NPCPawn';
    	Level.Game.SetPlayerDefaults(NPCPawn);
    
    }
    
    defaultproperties
    {
         NPCPawnClass=AirShipCommand.NPCPawn
         bHidden=True
    }
    
    and this is The pawns default properties ( I added no new functions ):
    Code:
    defaultproperties
    {
         bCanDodgeDoubleJump=False
         ShieldStrengthMax=50.000000
         MultiJumpRemaining=0
         MaxMultiJump=0
         MultiJumpBoost=0
         PlacedCharacterName="Soldier"
         PlacedFemaleCharacterName="Soldier"
         bCanWallDodge=False
         GroundSpeed=400.000000
         AirSpeed=400.000000
         JumpZ=300.000000
         ControllerClass=Class'XGame.xBot'
    }
    
    the only other thing that effects it is the SquadAI, which I've attached.
     

    Attached Files:

  4. porkmanii

    porkmanii New Member

    Joined:
    Sep 9, 2004
    Messages:
    129
    Likes Received:
    0
    I think your problem lies in setting the pawn's weapon. Have a look at Controller.SwitchToBestWeapon, which is called by ClientSwitchToBestWeapon. I've added some comments:
    Code:
    exec function SwitchToBestWeapon()
    {
    	local float rating;
    
    	if ( Pawn == None || Pawn.Inventory == None )
    		return;
    
        // in this case self is an AIController...
        if ( (Pawn.PendingWeapon == None) || (AIController(self) != None) )
        {
    	    // RecommendWeapon would probably return the AssaultRifle if ..
    	    // that is all the pawn has
    	    Pawn.PendingWeapon = Pawn.Inventory.RecommendWeapon(rating);
    	    // because you have set Weapon to the weapon you gave them, 
    	    // and PendingWeapon is (probably) the same weapon...
    	    if ( Pawn.PendingWeapon == Pawn.Weapon )
    		    Pawn.PendingWeapon = None;
    	    // PendingWeapon has (probably) been set to None...
    	    if ( Pawn.PendingWeapon == None )
        		return;
    	    // ...and the rest of the code is not executed
    	    // that could cause problems
        }
    
    	StopFiring();
    
    	// ChangedWeapon eventually calls Weapon.BringUp
    	// if this is not called, that would explain why the weapon is ..
    	// "stuck abit into the bringup animation"
    	if ( Pawn.Weapon == None )
    		Pawn.ChangedWeapon();
    
    	else if ( Pawn.Weapon != Pawn.PendingWeapon )
        {
    		Pawn.Weapon.PutDown();
        }
    }
    So, the conclusion I have come to is that you should try commenting out the line that sets the pawn's weapon to the newly spawned AssaultRifle.
     
    Last edited: Oct 16, 2004
  5. Call me Erdrik

    Call me Erdrik Arch Mage

    Joined:
    Nov 24, 1999
    Messages:
    334
    Likes Received:
    0
    thnx Ill try that ^_^

    Yay! it worked! and I officialy feel stupid for trying tomanually set weapon! :eek:

    Anywho thnx a bunch!
     
    Last edited: Oct 16, 2004
  6. Call me Erdrik

    Call me Erdrik Arch Mage

    Joined:
    Nov 24, 1999
    Messages:
    334
    Likes Received:
    0
    k, they got guns and they shoot things, now the problem is they are shooting teammates, and normal bot controlled teammates shoot them.
    They have replicationInfo, and as you can see above their teaminfo is set, so why are they attacking each other? :(
     
  7. porkmanii

    porkmanii New Member

    Joined:
    Sep 9, 2004
    Messages:
    129
    Likes Received:
    0
    First of all check your log file for any warnings relating to any of your classes (such as "accessed none" and "accessed array 'arrayname' out of bounds"). If you find any, try to track down the cause and fix it. Things like "accessed none"s generally cause undesired behaviour, if only making the log file bigger.

    Secondly, are you sure they have a PlayerReplicationInfo? If they don't you should see something like "Warning: NPCSpawnPoint DM-Antalus.NPCSpawnPoint (Function myPackage.NPCSpawnPoint.Timer:0000) Accessed None 'PlayerReplicationInfo'" in the log file. If their PlayerReplicationInfo is none, the TeamAI would see them as an enemy.

    Also, I think SquadAI is team specific, so you might have to add the freshly spawned SquadAI to the NPC's team (if you haven't already solved the problem). If you weren't using a custom SquadAI, I'd have recommended calling the NPC's Team's AI's PutOnDefense, PutOnOffense or PutOnFreelance as they would spawn and add a squad for the Bot (they take a Bot as a parameter). AI is a variable of UnrealTeamInfo, so you'd have to cast the team to that to access it. For example, I made a mutator that lets players change a bots team using a mutate command, but found that the game would remove them from their old squad and not give them a new one. To fix this, I recorded the bot's Orders before I changed their team, and then called PutOnOffense, PutOnDefense or PutOnFreelance depending on what their orders were, to assign them to a squad.
    Code:
    // if "c" is a Bot, OldOrders == the bot's orders before their team was changed
    if (OldOrders == 'Defend')
      UnrealTeamInfo(c.PlayerReplicationInfo.Team).AI.PutOnDefense(Bot(c));
    else if (OldOrders == 'Attack')
      UnrealTeamInfo(c.PlayerReplicationInfo.Team).AI.PutOnOffense(Bot(c));
    else
      UnrealTeamInfo(c.PlayerReplicationInfo.Team).AI.PutOnFreelance(Bot(c));
    
    Have a look at the PutOn* functions (in TeamAI) to see how a SquadAI is initialized.
     
    Last edited: Oct 17, 2004
  8. Call me Erdrik

    Call me Erdrik Arch Mage

    Joined:
    Nov 24, 1999
    Messages:
    334
    Likes Received:
    0
    No access nones. thats the first thing i look for.

    I check for this already as well PlayerReplicationInfo = xPlayerReplicationInfo

    This I did not know about. so when I call the PutOn* functions this will create a 'squad' for them?
    I will look into this thank you! ^_^
     
  9. Call me Erdrik

    Call me Erdrik Arch Mage

    Joined:
    Nov 24, 1999
    Messages:
    334
    Likes Received:
    0
    the PutOn*'s didn't work.

    I have redone my code abit with the thought of using default spawning code in the gametypes, ... but at best I could only get it to work just as good as it was already working. Everything is fine except the NPC's shoot each other when on the same team, how do I stop this?

    Here is the new code:
    Code:
    //=============================================================================
    // ASCGame.
    //=============================================================================
    class NPCSpawnPoint extends Actor
    	placeable;
    
    Var()	byte Team;
    Var()	class<NPCPawn> NPCPawnClass;
    
    #exec OBJ LOAD FILE=..\Textures\DemoPlayerSkins.utx
    
    Function PostBeginPlay()
    {
    	SetTimer(20,True);
    }
    
    Simulated function Timer()
    {
    	local Weapon newWeapon;
    	local xBot Bot;
    	local class<xBot> BotClass;
    	local UnrealTeamInfo BotTeam;
    	local RosterEntry Chosen;
    
    	BotTeam = ASCGame(Level.Game).Teams[Team];
    	Chosen = BotTeam.ChooseBotClass("Soldier");
    	BotClass = class'xBot';
    	Bot = Spawn(BotClass,,,);
    	Bot.Pawn = Spawn(NPCPawnClass,,,);
    	Bot.Squad = spawn(class'ASCSquadAI');
    	//ASCGame(Level.Game).Teams[Team].AddToTeam(Bot);
    	iF ( Bot.Pawn != None )
    	{
    		Bot.Pawn.Controller = Bot;
    		ASCGame(Level.Game).InitializeBot(Bot,BotTeam,Chosen);
    		Bot.PreviousPawnClass = Class'NPCPawn';
    		newWeapon = Spawn(class'AssaultRifle',,,Bot.Pawn.Location);
    		Bot.Pawn.SetPhysics(PHYS_Falling);
    		Level.Game.SetPlayerDefaults(Bot.Pawn);
    		if( newWeapon != None )
    		{
    			newWeapon.GiveTo(Bot.Pawn);
    			newWeapon.bCanThrow = false; // don't allow default weapon to be thrown out
    			Bot.ClientSwitchToBestWeapon();
    		}
    		If ( Bot.PlayerReplicationInfo.Team == ASCGame(Level.Game).Teams[0] )
    		{
    			Bot.Pawn.Skins[0] = Texture'DemoPlayerSkins.Jakob_Body_0';
    		} Else If ( Bot.PlayerReplicationInfo.Team == ASCGame(Level.Game).Teams[1] )
    		{
    			Bot.Pawn.Skins[0] = Texture'DemoPlayerSkins.Jakob_Body_1';
    		}
    		Bot.PlayerReplicationInfo.PlayerName = "Soldier";
    		log("PawnClass: "$Bot.Pawn);
    		log("PrePawnClass: "$Bot.PreviousPawnClass);
    		log(Team$": BotTeam: "$Bot.PlayerReplicationInfo.Team.TeamIndex);
    	} Else Bot.Destroy();
    
    }
    
    defaultproperties
    {
         NPCPawnClass=AirShipCommand.NPCPawn
         bHidden=True
    }
    
     
  10. porkmanii

    porkmanii New Member

    Joined:
    Sep 9, 2004
    Messages:
    129
    Likes Received:
    0
    You spawned a new SquadAI, but did you initialize it's settings? If you didn't, it's "Team" would equal None, and so FriendlyToward would return false.
    Code:
    function bool FriendlyToward(Pawn Other)
    {
    	if ( Team == None ) // <== look here
    		return false;
    	return Team.AI.FriendlyToward(Other);
    }
    To see how a SquadAI is initialized, have a look at TeamAI.AddSquadWithLeader():
    Code:
    function SquadAI AddSquadWithLeader(Controller C, GameObjective O)
    {
    	local SquadAI S;
    
    	S = spawn(SquadType);
    	S.Initialize(Team,O,C);
    	S.NextSquad = Squads;
    	Squads = S;
    	return S;
    }
    and SquadAI.Initialize
    Code:
    function Initialize(UnrealTeamInfo T, GameObjective O, Controller C)
    {
    	Team = T;
    	SetLeader(C);
    	SetObjective(O,false);
    }
    Also, instead of setting the Bot's Squad, you should spawn the ASCSquadAI and then call it's SetLeader function, which in turn calls AddBot(). In AddBot(), the Bot's Squad is set and the Bot is added to the linked list of squad members, and the Squad member of the Bot's TeamPlayerReplicationInfo is also set.

    There's probably more, but my brain has taken about as much as it can hold for now :).
     

Share This Page