Announcement

Collapse
No announcement yet.

Make bots shoot a target !

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Make bots shoot a target !

    In my map DM-1on1-TheVeryEndOfYou , there's a trap:

    When we shoot the target, a mover goes down and squishs the players who are under it.
    I want bots to be able to shoot the target to activate the squisher.

    I create a squisher volume (placed under the mover which squish players). When a pawn enter the volume, i search for bots who would like to activate the sqhisher.
    Then I ask him to shoot with shootSpecial(targetSquisher) (in class Pawn).

    Here's the code
    Code:
    //=============================================================================
    // SquisherVolume.
    //=============================================================================
    class SquisherVolume extends PhysicsVolume;
    
    var Pawn PawnInVolume[8];
    var Actor targetSquisher;
    
    //Find the target
    function PostBeginPlay()
    {
    	local mover M;
    
    	ForEach AllActors(class'Mover', M, 'TargetSquisher')
    	targetSquisher = M;
    }
    
    event Touch(Actor Other)
    {
        
    	local Controller P, Killer;
    	local Actor A;
    
    	Super.Touch(Other);
    
    	//Search for bot who would activate the squisher
    	if(Pawn(Other)!=None)
    	{
    		for ( P=Level.ControllerList; P!=None; P=P.NextController )
    			if( P.Pawn.PlayerReplicationInfo.bBot  && shouldSquish(P.Pawn) && P.Pawn.CanAttack(targetSquisher))
    			{
    				log("BOT WILL SHOOT "$targetSquisher$" !!!!!!!!!!!!!!!");
    				A = P.Pawn.ShootSpecial(targetSquisher);
    			}
    	}
    }
    
    //Ask if the Bot should activate the squisher
    function bool shouldSquish(Pawn Bot)
    {
    	local int i;
    
    	updatePawnInVolume();
    	for(i=0;i<8;i++)
    	{
    		//don't kill the bot itself
    		if(Bot == PawnInVolume[i])
    			return false;
    		//don't kill teamate
    		if(Level.Game.bTeamGame && (Bot.PlayerReplicationInfo.Team == PawnInVolume[i].PlayerReplicationInfo.Team))
    			return false;
    	}
    	// Pawn should squish
    	return true;
    }
    
    //Put in an array, all the pawns which are in the volume
    function updatePawnInVolume()
    {
    	local Pawn  P;
    	local int i;
    
    	for(i=0;i<8;i++)
    	PawnInVolume[i] = None;
    	i = 0;
    	forEach TouchingActors(class'Pawn', P)
    	{
    		if( (P.Health > 0) && !P.IsA('Spectator') )
    		{
    			PawnInVolume[i] = P;
    			i++;
    		}
    	}
    }
    but it doesn't function ! The function is called at the right moment but the bot doesn't shoot !
    Could anyone help me.

    Thanks

    #2
    I think i might be able to, i have seen a shottarger fucntion somewhere for them, but right now im at school

    Comment


      #3
      my question might sound stupid and yet i can't really help you... but:

      - are you sure the bots have a line of sight?
      - what bot level are you testing with? High enough? Adept bots are still kinda stupid, i noticed yesterday i had to put it at least to inhuman to only make them perform an easy double jump...

      Comment


        #4
        - are you sure the bots have a line of sight?
        If the bots don't see the targetSquisher, they should move to a better position to fire at the target.

        - what bot level are you testing with? High enough? Adept bots are still kinda stupid, i noticed yesterday i had to put it at least to inhuman to only make them perform an easy double jump...
        I always play with inhuman level. It may not be the problem.

        I tried to change the target of the bot with P.target = targetSquisher but if the bot sees an enemy, the target is reset to the enemy.
        And the bot doesn't have the time to shoot the target.

        Comment


          #5
          i keep forgetting to reply! remind me when i get home

          not sure but i think that there is a shotat(...) command for bots

          Comment


            #6
            Originally posted by Akbalder
            And the bot doesn't have the time to shoot the target. [/B]
            That is kind of what i was about. So as soon as a bot has seen an enemy in the squisher area he would have to ignore everything else until having shot at the target.

            (besides i'm not of any use in this thread, 'cuse me)

            Comment


              #7
              I succeed to make the bots shoot the target !!!
              Every 0.5 seconds, i check if there are pawns in the volume.
              If there are bots in the volume i search for bots who would like to activate the squisher and I give them orders to shoot the target.

              I don't know if checking for pawns in volume every 0.5 seconds slow to much the map ?


              Here's the code if anyone is interrested:

              Code:
              //=============================================================================
              // SquisherVolume.
              //=============================================================================
              class SquisherVolume extends PhysicsVolume;
              
              
              var IASquisher IASquisher ;
              
              simulated function PostBeginPlay()
              {
              	IASquisher = Spawn(class'IASquisher ', SELF);
                  if(IASquisher  != None)
              		IASquisher.A = SELF;
              }
              
              
              function array<Pawn> getPawnInVolume()
              {
              	local Pawn  P;
              	local int i;
              	local array<Pawn> PawnInVolume;
              
              	i = 0;
              	forEach TouchingActors(class'Pawn', P)
              	{
              		 //find 4 pawns max
              		if( (P.Health > 0) && !P.IsA('Spectator'))
              		{
              			PawnInVolume[i] = P;
              			i++;
              		}
              	}
              	return PawnInVolume;
              }
              
              //=============================================================================
              // IASquisher.
              //=============================================================================
              class IASquisher extends VolumeTimer;
              
              var mover targetSquisher;
              
              function PostBeginPlay()
              {
              	local mover M;
              
              	super.PostBeginPlay();
              
              	//Find the target
              	ForEach AllActors(class'Mover', M, 'TargetSquisher')
              			targetSquisher = M;
              
              	//set timer
              	SetTimer(0.5, true);
              	A = Owner;
              }
              
              function Timer()
              {
              	local Controller P;
              	local actor tmp;
              
              	//if(PawnInVolume[0] != None)
              	for ( P=Level.ControllerList; P!=None; P=P.NextController )
              		if( P.Pawn!=None && P.Pawn.PlayerReplicationInfo.bBot  && shouldSquish(P.Pawn) /*&& P.Pawn.CanAttack(targetSquisher)*/)
              			tmp = P.Pawn.ShootSpecial(targetSquisher);
              }
              
              function bool shouldSquish(Pawn P)
              {
              	local int i;
              	local array<Pawn> PawnInVolume;
              	
              	if(squisherVolume(A) != None )
              		PawnInVolume = squisherVolume(A).getPawnInVolume();
              
              	if(PawnInVolume.length<=0) //don't squish no one
              		return false;
              
              	for(i=0;i<PawnInVolume.length;i++)
              	{	
              		//don't kill the bot itself
              		if(P == PawnInVolume[i])
              			return false;
              		//don't kill teamate
              		if(P!=None && Level.Game.bTeamGame && (P.PlayerReplicationInfo.Team == PawnInVolume[i].PlayerReplicationInfo.Team))
              			return false;
              	}
              	// Pawn should squish
              	return true;
              }

              Comment


                #8
                ...congrats. Don't really know about the slowing down, but i think every 0.5 seconds isn't too much, since i think there are other standard functions updating a lot more often...

                Comment

                Working...
                X