Advertisement
Guest User

Light Sensitive Creatures

a guest
Jan 31st, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. //::///////////////////////////////////////////////
  2. //:: Name ag_ai_shyl_hb
  3. /*
  4. Modified OnHeartbeat AI script
  5. Originals x2_def_heartbeat NW_C2_DEFAULT1
  6.  
  7. This script causes NPCs to perform default animations
  8. while not otherwise engaged.
  9.  
  10. Creatures shy of light will move away from sources of light that they perceive
  11. */
  12. //:://////////////////////////////////////////////
  13. //:: Created By: Naomi Novik (12/22/2002)
  14. //:: Modified: The Magus (2011 may 30) special ai for light shy creatures
  15. //:://////////////////////////////////////////////
  16.  
  17. #include "ag_inc_shylight"
  18.  
  19. void main()
  20. {
  21. // * if not runnning normal or better Ai then exit for performance reasons
  22. if (GetAILevel() == AI_LEVEL_VERY_LOW) return;
  23.  
  24. // Buff ourselves up right away if we should
  25. if(GetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY))
  26. {
  27. // This will return TRUE if an enemy was within 40.0 m
  28. // and we buffed ourselves up instantly to respond --
  29. // simulates a spellcaster with protections enabled
  30. // already.
  31. if(TalentAdvancedBuff(40.0))
  32. {
  33. // This is a one-shot deal
  34. SetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY, FALSE);
  35.  
  36. // This return means we skip sending the user-defined
  37. // heartbeat signal in this one case.
  38. return;
  39. }
  40. }
  41.  
  42.  
  43. if(GetHasEffect(EFFECT_TYPE_SLEEP))
  44. {
  45. // If we're asleep and this is the result of sleeping
  46. // at night, apply the floating 'z's visual effect
  47. // every so often
  48.  
  49. if(GetSpawnInCondition(NW_FLAG_SLEEPING_AT_NIGHT))
  50. {
  51. effect eVis = EffectVisualEffect(VFX_IMP_SLEEP);
  52. if(d10() > 6)
  53. {
  54. ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, OBJECT_SELF);
  55. }
  56. }
  57. }
  58.  
  59. // If we have the 'constant' waypoints flag set, walk to the next waypoint.
  60. else if ( GetWalkCondition(NW_WALK_FLAG_CONSTANT) )
  61. {
  62. WalkWayPoints();
  63. }
  64.  
  65. // Check to see if we should be playing default animations
  66. // - make sure we don't have any current targets
  67. else if ( !GetIsObjectValid(GetAttemptedAttackTarget())
  68. && !GetIsObjectValid(GetAttemptedSpellTarget())
  69. // && !GetIsPostOrWalking())
  70. // && !GetIsObjectValid(GetNearestSeenEnemy())
  71. )
  72. {
  73. // Since we aren't doing anything in particular we should be looking out for light sources and enemies
  74. // variables used in identifying the source of the closest pool of light
  75. int bAttack = FALSE;
  76. int nNth = 1;
  77. int iLightBrightness;
  78. int iBrightest;
  79. float fDistToLight = 0.0;
  80. float fDistBrightest;
  81. object oBrightestLight;
  82.  
  83. object oNearest = GetNearestCreature(CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, OBJECT_SELF, nNth);
  84. // loop through seen creatures, looking for sources of light
  85. while ( GetIsObjectValid(oNearest) )
  86. {
  87. iLightBrightness = 0;
  88. iLightBrightness = GetLightBrightness(oNearest);
  89.  
  90. // found a light source
  91. if (iLightBrightness > 0)
  92. {
  93. float fTemp = fDistToLight;
  94. fDistToLight= GetDistanceToObject(oNearest) - IntToFloat(iLightBrightness*5);
  95.  
  96. // compare with previously found lightsources to determine which has the closest pool of light
  97. if ( fTemp == 0.0 )
  98. {
  99. oBrightestLight = oNearest;
  100. fDistBrightest = fDistToLight;
  101. iBrightest = iLightBrightness;
  102. }
  103. else if ( fDistToLight < fDistBrightest )
  104. {
  105. fDistBrightest = fDistToLight;
  106. oBrightestLight = oNearest;
  107. iBrightest = iLightBrightness;
  108. }
  109. else if ( fDistToLight == fDistBrightest && iBrightest < iLightBrightness )
  110. {
  111. fDistBrightest = fDistToLight;
  112. oBrightestLight = oNearest;
  113. iBrightest = iLightBrightness;
  114. }
  115.  
  116. }
  117. else if(GetIsEnemy(oNearest) && !IsInLight(oNearest))
  118. {
  119. bAttack = TRUE;
  120. ClearAllActions();
  121. DetermineCombatRound(oNearest);
  122. break;
  123. }
  124. oNearest = GetNearestCreature(CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, OBJECT_SELF, ++nNth);
  125. }
  126.  
  127. if( GetIsObjectValid(oBrightestLight) && !bAttack)
  128. {
  129. if(GetDistanceToObject(oBrightestLight)<2.1)
  130. {
  131. ClearAllActions();
  132. ActionMoveAwayFromObject(oBrightestLight, TRUE);
  133. }
  134. else
  135. {
  136. ClearAllActions();
  137. ActionMoveAwayFromObject(oBrightestLight, FALSE, IntToFloat(iBrightest*5)+1.0);
  138. }
  139. }
  140. else if (!IsInConversation(OBJECT_SELF) && !bAttack)
  141. {
  142. if (GetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS)
  143. || GetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS_AVIAN)
  144. || GetIsEncounterCreature())
  145. {
  146. PlayMobileAmbientAnimations();
  147. }
  148. else if (GetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS))
  149. {
  150. PlayImmobileAmbientAnimations();
  151. }
  152. }
  153. }
  154.  
  155. // Send the user-defined event signal if specified
  156. if(GetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT))
  157. {
  158. SignalEvent(OBJECT_SELF, EventUserDefined(EVENT_HEARTBEAT));
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement