I just did this up quickly, using a shape instead of GetNearest... I changed it around a little from your original script, but kept as much of the structure of the original as I could still. Hopefully it would do the trick for you.
void main()
{
object oPC = GetItemActivator();
object oObject;
string sObject;
effect eVisual = EffectVisualEffect(VFX_FNF_HOWL_MIND);
location lPC = GetLocation (oPC);
// Set friendly durations here, in seconds.
float fDuration = 10.0;
// Set area of effect distance here, in meters.
float fDistance = 8.0;
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVisual, lPC);
PlaySound("as_pl_whistle2");
oObject = GetFirstObjectInShape (SHAPE_SPHERE, fDistance, lPC);
while (GetIsObjectValid (oObject))
{
sObject = GetTag(oObject);
// if all rats starting with "5_rat" can be affected, the commented out line is better.
// if (GetStringLeft (sObject, 5) == "5_rat")
if(sObject == "5_ratA" || sObject == "5_ratB" || sObject == "5_ratC" || sObject == "5_ratD" || sObject == "5_ratE" || sObject == "5_ratF")
{
SetIsTemporaryFriend(oPC, oObject, TRUE, fDuration);
AssignCommand(oObject, ClearAllActions());
AssignCommand(oObject, ActionForceFollowObject(oPC, 2.0));
}
oObject = GetNextObjectInShape (SHAPE_SPHERE, fDistance, lPC);
}
}
Edit: Just noticed the "D" in duration was missing, which is odd since I compiled it before copy/pasting.
Modifié par Failed.Bard, 04 novembre 2011 - 02:37 .