Advertisement
PastebinnerMKII

Perception Script

Oct 18th, 2019
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. //:://////////////////////////////////////////////////
  2. //:: NW_C2_DEFAULT2
  3. /*
  4. Default OnPerception event handler for NPCs.
  5.  
  6. Handles behavior when perceiving a creature for the
  7. first time.
  8. */
  9. //:://////////////////////////////////////////////////
  10.  
  11. #include "nw_i0_generic"
  12.  
  13. void main()
  14. {
  15. // * if not runnning normal or better Ai then exit for performance reasons
  16. // * if not runnning normal or better Ai then exit for performance reasons
  17. if (GetAILevel() == AI_LEVEL_VERY_LOW) return;
  18.  
  19. object oPercep = GetLastPerceived();
  20. int bSeen = GetLastPerceptionSeen();
  21. int bHeard = GetLastPerceptionHeard();
  22. if (bHeard == FALSE)
  23. {
  24. // Has someone vanished in front of me?
  25. bHeard = GetLastPerceptionVanished();
  26. }
  27.  
  28. // This will cause the NPC to speak their one-liner
  29. // conversation on perception even if they are already
  30. // in combat.
  31. if(GetSpawnInCondition(NW_FLAG_SPECIAL_COMBAT_CONVERSATION)
  32. && GetIsPC(oPercep)
  33. && bSeen)
  34. {
  35. SpeakOneLinerConversation();
  36. }
  37.  
  38. // March 5 2003 Brent
  39. // Had to add this section back in, since modifications were not taking this specific
  40. // example into account -- it made invisibility basically useless.
  41. //If the last perception event was hearing based or if someone vanished then go to search mode
  42. if ((GetLastPerceptionVanished()) && GetIsEnemy(GetLastPerceived()))
  43. {
  44. object oGone = GetLastPerceived();
  45. if((GetAttemptedAttackTarget() == GetLastPerceived() ||
  46. GetAttemptedSpellTarget() == GetLastPerceived() ||
  47. GetAttackTarget() == GetLastPerceived()) && GetArea(GetLastPerceived()) != GetArea(OBJECT_SELF))
  48. {
  49. ClearAllActions();
  50. DetermineCombatRound();
  51. }
  52. }
  53.  
  54. // This section has been heavily revised while keeping the
  55. // pre-existing behavior:
  56. // - If we're in combat, keep fighting.
  57. // - If not and we've perceived an enemy, start to fight.
  58. // Even if the perception event was a 'vanish', that's
  59. // still what we do anyway, since that will keep us
  60. // fighting any visible targets.
  61. // - If we're not in combat and haven't perceived an enemy,
  62. // see if the perception target is a PC and if we should
  63. // speak our attention-getting one-liner.
  64. if (GetIsInCombat(OBJECT_SELF))
  65. {
  66. // don't do anything else, we're busy
  67. //MyPrintString("GetIsFighting: TRUE");
  68.  
  69. }
  70. // * BK FEB 2003 Only fight if you can see them. DO NOT RELY ON HEARING FOR ENEMY DETECTION
  71. else if (GetIsEnemy(oPercep) && bSeen)
  72. { // SpawnScriptDebugger();
  73. //MyPrintString("GetIsEnemy: TRUE");
  74. // We spotted an enemy and we're not already fighting
  75. if(!GetHasEffect(EFFECT_TYPE_SLEEP)) {
  76. if(GetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL))
  77. {
  78. //MyPrintString("DetermineSpecialBehavior");
  79. DetermineSpecialBehavior();
  80. } else
  81. {
  82. //MyPrintString("DetermineCombatRound");
  83. SetFacingPoint(GetPosition(oPercep));
  84. SpeakString("NW_I_WAS_ATTACKED", TALKVOLUME_SILENT_TALK);
  85. DetermineCombatRound();
  86. }
  87. }
  88. }
  89. else
  90. {
  91. if (bSeen)
  92. {
  93. //MyPrintString("GetLastPerceptionSeen: TRUE");
  94. if(GetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL)) {
  95. DetermineSpecialBehavior();
  96. } else if (GetSpawnInCondition(NW_FLAG_SPECIAL_CONVERSATION)
  97. && GetIsPC(oPercep))
  98. {
  99. // The NPC will speak their one-liner conversation
  100. // This should probably be:
  101. // SpeakOneLinerConversation(oPercep);
  102. // instead, but leaving it as is for now.
  103. ActionStartConversation(OBJECT_SELF);
  104. }
  105. }
  106. else
  107. // * July 14 2003: Some minor reactions based on invisible creatures being nearby
  108. if (bHeard && GetIsEnemy(oPercep))
  109. {
  110. // SpeakString("vanished");
  111. // * don't want creatures wandering too far after noises
  112. if (GetDistanceToObject(oPercep) <= 7.0)
  113. {
  114. // if (GetHasSpell(SPELL_TRUE_SEEING) == TRUE)
  115. if (GetHasSpell(SPELL_TRUE_SEEING))
  116. {
  117. ActionCastSpellAtObject(SPELL_TRUE_SEEING, OBJECT_SELF);
  118. }
  119. else
  120. // if (GetHasSpell(SPELL_SEE_INVISIBILITY) == TRUE)
  121. if (GetHasSpell(SPELL_SEE_INVISIBILITY))
  122. {
  123. ActionCastSpellAtObject(SPELL_SEE_INVISIBILITY, OBJECT_SELF);
  124. }
  125. else
  126. // if (GetHasSpell(SPELL_INVISIBILITY_PURGE) == TRUE)
  127. if (GetHasSpell(SPELL_INVISIBILITY_PURGE))
  128. {
  129. ActionCastSpellAtObject(SPELL_INVISIBILITY_PURGE, OBJECT_SELF);
  130. }
  131. else
  132. {
  133. ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_LEFT, 0.5);
  134. ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_RIGHT, 0.5);
  135. ActionPlayAnimation(ANIMATION_FIREFORGET_PAUSE_SCRATCH_HEAD, 0.5);
  136. }
  137. }
  138. }
  139.  
  140. // activate ambient animations or walk waypoints if appropriate
  141. if (!IsInConversation(OBJECT_SELF)) {
  142. if (GetIsPostOrWalking()) {
  143. WalkWayPoints();
  144. } else if (GetIsPC(oPercep) &&
  145. (GetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS)
  146. || GetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS_AVIAN)
  147. || GetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS)
  148. || GetIsEncounterCreature()))
  149. {
  150. SetAnimationCondition(NW_ANIM_FLAG_IS_ACTIVE);
  151. }
  152. }
  153. }
  154.  
  155. // Send the user-defined event if appropriate
  156. if(GetSpawnInCondition(NW_FLAG_PERCIEVE_EVENT) && GetLastPerceptionSeen())
  157. {
  158. SignalEvent(OBJECT_SELF, EventUserDefined(EVENT_PERCEIVE));
  159. }
  160.  
  161. ////////////////////////////////////////////////
  162. if(!GetIsEnemy(oPercep, OBJECT_SELF)
  163. {
  164. object oPC = GetFirstPC();
  165. if(GetIsEnemy(oPC, oPercep)
  166. {
  167. AdjustReputation(oPercep, OBJECT_SELF, -100);
  168. AdjustReputation(OBJECT_SELF, oPercep, -100);
  169. }
  170. }
  171. ////////////////////////////////////////////////
  172.  
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement