CheckFriendlyFireOnTarget(object, float)

Gets how many friendly creatures are within a spherical range of a target object.

int CheckFriendlyFireOnTarget(
    object oTarget,
    float fDistance = 5.0
);

Parameters

oTarget

The object target at the center of sphere to check for friends.

fDistance

The radius of sphere to check for friends. (Default: 5.0)


Description

Returns how many creatures in a sphere of radius fDistance, centered on oTarget, are friendly, and returns the count.



Remarks

Friendly creatures with less than half the hit dice of the caller are not counted.

Used in the Core AI to determine whether or not to use protection talents, enhancement effects, and harmful AOE spells. Prevents henchmen from using indiscriminate harmful AOE spells at all while friends are in the target area.


Requirements

#include "x0_i0_enemy"

Version

1.26

Example

//Have an NPC look around for a concentration of more than 1 enemy, 
//make sure no friendly creatures are within range, then fire off a 
//FireBall spell if they have one.
void main()
{
	oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
	if(GetIsObjectValid(oTarget))
	{
		int nEnemy = CheckEnemyGroupingOnTarget(oTarget);
		int nFriendlies = CheckFriendlyFireOnTarget(oTarget);
		if( nFriendlies <= 0 &&  nEnemy >= 1)
		{
			ActionCastSpellAtObject(SPELL_FIREBALL,oTarget);
		}
	}
}

See Also

functions: AssociateCheck | CheckEnemyGroupingOnTarget | GetAttackTarget | GetAttemptedAttackTarget | GetIsFriend | GetIsReactionTypeFriendly
categories: Combat Functions | Core AI Functions


 author: Iskander Merriman, editor: Charles Feduke