Page 2 of 2

Re: Attacking Order

Posted: Mon Jun 15, 2009 4:26 pm
by Juutis
I know this is an old topic but since at least two people seem to have problems and questions I'm bumping this.

Here's an updated version of the method. This one targets the nearest visible enemy (as in enemy of the pawn running this script. Not necessarily enemy of the player):

Code: Select all

newtarget[ ()
{
    nearesttarget = StringCopy("none");
    nearestrange = ALERTSIGHTDIST + 0;

for targetnumber=0 to MAXENEMYPAWNS step 1
{
     targetname = StringCopy(TARGETPREFIX # targetnumber);

     if(FastDistance(targetname,nearestrange))
     {
          if(IsEntityVsible(targetname))
          {
               if(GetAttribute(DAMAGEATTRIBUTE,targetname) > 0)
               {
                    nearesttarget = StringCopy(targetname);
                    nearestrange = GetDistanceTo(targetname);
               }
          }
     }
}

if(HOSTILEPLAYER)
{
     if(player_range < nearestrange)
     {
          if(player_vis)
          {
               if(GetAttribute(DAMAGEATTRIBUTE,"Player") > 0)
               {
                    nearesttarget = StringCopy("Player");
               }
          }
     }
}

if(nearesttarget = StringCopy("none"))
{
    return false;
}

if(nearesttarget = StringCopy("Player"))
{
    TargetPlayer();
    return true;
}

SetTarget(nearesttarget);
return true;
} ]
If you're using perfectAI the only variables you need to add to the beginning of the script are MAXENEMYPAWNS and TARGETPREFIX. Otherwise all the fully uppercase variables are needed.

MAXENEMYPAWNS simply tells the script how many enemies there are in the level. And again, enemies refer to pawns that the script can target.

TARGETPREFIX defines the names of the pawns the script can target. This prefix is used to identify the "sides" of the pawns. The names of the enemies should be the prefix followed by a number starting from 0 (instead of 1 as I said in the old post). Like enemy0, friend28 etc.


I've tested this piece of script - not very thoroughly, though - but it should work. So if you're having problems, it would help a lot if you posted the whole script or at least the parts where you're using this method.

Re: Attacking Order

Posted: Mon Jun 15, 2009 10:18 pm
by metal_head
awesome, that works perfect! This gives a really big boost to my game!!! Guys, this really works, so try it out!

Btw, here's a pic of the fight enemies and friends (level - MF's test box) it
s nothing specil, but I just love how all my palls and aliens died in the fight:
massacre.jpg
(55.89 KiB) Not downloaded yet