BloodRayne@Posted: Sun Oct 01, 2006 11:25 am :
Hey all,

I'm trying to find the AI_PAIN event for monsters via script. I've tried printing a testline to the console in a couple of different events in the ai_monster_base.script but I can't put my finger on which routine is called everytime an enemy experiences pain.

I thought that the state_combat was a pretty good place to start but the testline gets printed only occasionally. I've added an if statement to the state_combat loop and test that in a map. When I spawn an imp and shoot at it, the line doesn't get printed (ie the code isn't called). When I wait a while and run around it and then shoot it, it sometimes gets called.

I want to insert some code at the point where a monster experiences pain. Anybody know which place would be best for that in script? Can I do it in the monster_base script, saving me the headacke of having to edit each specific monster script?

code:
Code:
/*
=====================
monster_base::state_Combat
=====================
*/
void monster_base::state_Combat() {
   float attack_flags;

   eachFrame {
      faceEnemy();
      if ( AI_PAIN ) {
         sys.print( "Having pain now, thank you\n" );
      }

      if ( AI_ENEMY_IN_FOV ) {
         lookAtEnemy( 1 );
      }

      if ( sys.influenceActive() ) {
         waitFrame();
         continue;
      }

      if ( AI_ENEMY_DEAD ) {
         enemy_dead();
      }

      attack_flags = check_attacks();
      if ( attack_flags ) {
         do_attack( attack_flags );
         continue;
      }

      if ( !combat_chase() ) {
         locateEnemy();
         if ( !combat_chase() ) {
            combat_lost();
         }
      }

      waitFrame();
   }
}



The Happy Friar@Posted: Sun Oct 01, 2006 4:38 pm :
it looks like ai_pain may be in the sdk code. I can't find anything but true/false checks/assign for it in the scripts.



jcdenton22@Posted: Thu Oct 05, 2006 11:22 am :
BloodRayne wrote:
I can't put my finger on which routine is called everytime an enemy experiences pain.


AI_PAIN is the script variable that is set to true everytime an AI entity recieves any sort of damage, so dont need to look at anything else.

BloodRayne wrote:
I thought that the state_combat was a pretty good place to start but the testline gets printed only occasionally. I've added an if statement to the state_combat loop and test that in a map. When I spawn an imp and shoot at it, the line doesn't get printed (ie the code isn't called). When I wait a while and run around it and then shoot it, it sometimes gets called.


Monster's states are always changing and there's only one state function running at a time, so there's no guarantee that state_combat will always be called every-time you shoot a monster. All you need to do now is run constant check on AI_PAIN's state and to do that try these steps:

1.write a member function, say checkDamage() for instance, for ai_monster_base. In this function check AI_PAIN's state.

2.start the thread called checkDamage from within monster_base::init().

3.Additionally, you'll need to kill the thread as soon as monster is dead or the game will try to execute the thread even after the monster is dead which would ultimately lead to map shutdown. You can kill the thread from within monster_base::state_kill