Script Name: GetNearestNPC
What it does: Will return an object representing the closest (starting at
nNth) NPC or Creature to the calling object
Notes: Takes three parameters -
nGender: only get NPCs of a certain gender
GENDER_MALE
GENDER_FEMALE
GENDER_BOTH (Default)
nBasicRacesOnly: Only consider creatures of a playable race?
nNth: Return the nNth closest NPC
Contains one support function call IsBasicRace that defaults to return TRUE
if it is one of the player races, but can be set to ignore Half Orcs.
NWScript:
int IsBasicRace(object oCreature, int nRacist);
object GetNearestNPC(int nGender = GENDER_BOTH, int nBasicRacesOnly = TRUE, int nNth=1);
int IsBasicRace(object oCreature, int nRacist = FALSE){
if(GetRacialType(oCreature) == RACIAL_TYPE_DWARF){
return TRUE;
}
if(GetRacialType(oCreature) == RACIAL_TYPE_ELF){
return TRUE;
}
if(GetRacialType(oCreature) == RACIAL_TYPE_GNOME){
return TRUE;
}
if(GetRacialType(oCreature) == RACIAL_TYPE_HALFELF){
return TRUE;
}
if(GetRacialType(oCreature) == RACIAL_TYPE_HALFLING){
return TRUE;
}
if(GetRacialType(oCreature) == RACIAL_TYPE_HUMAN){
return TRUE;
}
if(GetRacialType(oCreature) == RACIAL_TYPE_HALFORC && nRacist == FALSE){
return TRUE;
}
return FALSE;
}
object GetNearestNPC(int nGender = GENDER_BOTH, int nBasicRacesOnly = TRUE, int nNth=1){
int nFound = FALSE;
object oCreature;
while(nFound == FALSE){
object oCreature = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC, OBJECT_SELF, nNth);
if(GetIsObjectValid(oCreature) && oCreature != OBJECT_SELF & !GetIsDM(oCreature)){
if(GetRacialType(oCreature) == GetRacialType(OBJECT_SELF)){
if(GetGender(oCreature) == nGender){
return oCreature;
}
}else{
if(IsBasicRace(oCreature) && GetGender(oCreature) == nGender){
return oCreature;
}
}
}
nNth++;
}
if(nFound == TRUE){
return oCreature;
}else{
return OBJECT_INVALID;
}
}
I use this to cause NPCs to initiate conversations with other nearby NPCs.
Since I do not want them wandering a mile just to talk with another NPC. It
is also a bit racist in that the NPC will prefer another NPC of it's own
race. Still some work left for that part but works as is.
_________________
----
Jaks
A mind so closed can only find life a small, sad cage
|