AI Ignore Player

From The DarkMod Wiki
Jump to navigationJump to search

Sometimes there's no reason for AI to attack the player on sight. Public places, like taverns or city streets, should often be safe for the player unless they do something wrong.

Here is one possible script:

void crime_watch_entity(string name)
{

/********************************************************************************
*                                                                               *
*       This is the AI relations script for NHAT 2/3: A Night Out on the Town.  *
*                                                                               *
* General guards, like the citywatch, all are all set to team 2: citywatch.     *
* a atdm:team_relations entity changes their regular relation to the player     *
* to neutral ("rel 2,0" "0").                                                   *                                                           
*                                                                               *
* They are still neutral to builders and other commoners etc (team 5)           *
* seen on the streets. The only significant difference between them and the     *                                                                                       
* commoners is that they are allied to builders (assaulting a builder will      *
* get you busted) and it is not against objectives to kill these guys.          *
*                                                                               *
* When the script is run, AI check to see if they've "seen any evidence" of     *
* crime, such as corpses, stolen goods, weapons (including arrows that the      *
* player may have shot).                                                        *
*                                                                               *
* If they've seen any evidence (or have generally been pissed off) they'll      *
* alert any nearby buddies (citywatch, commoners, beggars).                     *
*                                                                               *
* The AI and his buddies will check to see if the player is in sight.           *
* If he can see the player, and he's pissed off JUST ENOUGH, the AI will be     *
* set to "hostile". If he cannot see the player, or he's not pissed off         *
* enough, no relation change will occur, and he will stay neutral.              *
*                                                                               *
*                Tl;dr?                                                         *
* Don't be caught at the scene of any crime.                                    *
* Come back later, when the AI have cooled down.                                *
* Then you should be safe to walk around.                                       *
********************************************************************************/

   // You must cast the entity before we can access the script floats.

   ai theAI = sys.getEntity(name);
   if ( theAI.getHealth() >= 0 ) // Is this AI dead? Dead men tell no tales.
   {
       // If not ...

       if ( theAI.hasSeenEvidence() && ( theAI.AI_AlertLevel > 11 ) ) // Have you seen evidence, and are you pissed off?
       {
           // If so ...

           ai theAIbuddy = theAI.findFriendlyAI(-1); // See if you can find any buddy near to you
           if ( theAIbuddy != $null_entity )
           {
               theAIbuddy.setAlertLevel(theAI.AI_AlertLevel); // You found him. Warn him and piss him off, too.
               sys.println(theAI.getName() + ": Evidence of a crime! Or I was just informed of a crime!\n"); // Print to the console.
           }
       }
       if ( theAI.canSeeExt($player1,1,1) && ( theAI.AI_AlertLevel > 17 ) ) // Are you REALLY pissed off? AND can you see the player?
       {
           // If so ...

           theAI.lookAt($player1,3); //Look at that nasty jerk player.
           theAI.setEntityRelation($player1,-1); // He is now your enemy! Go get 'em!
           sys.println(theAI.getName() + ": I've just seen the player at a crime scene! I'm gonna kill him!\n"); // Print to the console!
       }
   }
}