Author Topic: Prioritizing Targets  (Read 890 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Prioritizing Targets
« on: May 04, 2016, 03:33:46 am »


               

Is there a way to further specify in general which things you want a creature to target with using an object?


 


I'd like to have the NPC that I'm working on target players first always before regular mobs/summons.


In addition to that I'd like it to go for things that are wizards/sorcerers, then clerics/druids, then all the rest after that.


 


Can I fit that all into the object oTarget like what I have down below?


 


 


object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY | !REPUTATION_TYPE_NEUTRAL | !REPUTATION_TYPE_FRIEND , OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);

 



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Prioritizing Targets
« Reply #1 on: May 04, 2016, 09:53:24 am »


               

PLAYER_CHAR_IS_PC    - If you use this flag, it will only target Players.


You can then say, if oTarget ==OBJECT_INVALID, then target NPC's instead.


Getting a single call that uses NPC's as a failsafe and Players as a pirority is unlikely.


You will need to call the method twice: but you can wrap it in your own method, to make it a single call in your script.


 


 


http://www.nwnlexico...NearestCreature


               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Prioritizing Targets
« Reply #2 on: May 04, 2016, 12:34:47 pm »


               

Here is something that may get you what you want.


 
// Will only return a target if they have mage or priest levels, are alive,
// can be seen, and are an enemy. Otherwise returns OBJECTINVALID.
// Mage levels are weighted for.
// Only PC's, Henchmen, and Dominated types are concidered.
object PriorityTarget()
{
    object oTarget = OBJECT_INVALID;
    int nCount = 1;
    object oCantidate = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, nCount, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY );
    while(GetIsObjectValid(oCantidate))
    {
        int PriorityLevel = 0;
        if(GetMaster(oCantidate) == OBJECT_INVALID || GetAssociateType(oCantidate) == ASSOCIATE_TYPE_HENCHMAN|| GetAssociateType(oCantidate) == ASSOCIATE_TYPE_DOMINATED)
        {
            int SorcerorLavels  = GetLevelByClass(CLASS_TYPE_SORCERER)*2;
            int WizardLavels    = GetLevelByClass(CLASS_TYPE_WIZARD)*2;
            int ClericLevels    = GetLevelByClass(CLASS_TYPE_CLERIC);
            int DruidLavels     = GetLevelByClass(CLASS_TYPE_DRUID);
 
            int CandidatePriorityLevel = SorcerorLavels+WizardLavels+ClericLevels+DruidLavels;
            if(CandidatePriorityLevel > PriorityLevel)
                oTarget = oCantidate;
        }
        oCantidate = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, ++nCount, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY );
    }
    return oTarget;
}

               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Prioritizing Targets
« Reply #3 on: May 07, 2016, 07:21:14 pm »


               

thanks for the replies, very helpful as always '<img'>