void ThingRangeEvent(int rX, int rZ, int rA, int checkBehind, char type, int count)
{
char find_type;
switch(type)
{
case "player":
find_type = openborconstant("TYPE_PLAYER");
break;
case "npc":
find_type = openborconstant("TYPE_NPC");
break;
default:
return;
}
char name = getentityproperty(vSelf, "thing"); //"defaultmodel"
void vSelf = getlocalvar("self");
int seeingEntities = getentityvar(vSelf, "seeing_" + type);
int didShout = 0;
int lastShout = getentityvar(vSelf, "lastShout");
int elapsed_time = openborvariant("elapsed_time");
if(seeingEntities == NULL() && (lastShout == NULL() || lastShout != NULL() && elapsed_time > lastShout + 1000))
{
if(findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "hulk"))
{
//playSound("data/chars/thing/see_hulk.wav");
variableSound("data/chars/" + name + "/hulk", 1, 50);
didShout = 1;
}
else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "human_torch"))
{
//playSound("data/chars/thing/see_human_torch.wav");
variableSound("data/chars/" + name + "/torch", 1, 50);
didShout = 1;
}
else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "reed"))
{
variableSound("data/chars/" + name + "/reed", 1, 50);
didShout = 1;
}
else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "sue"))
{
variableSound("data/chars/" + name + "/sue", 1, 50);
didShout = 1;
}
if(didShout)
{
setentityvar(vSelf, "lastShout", elapsed_time);
setentityvar(vSelf, "seeing_" + type, 1);
return; // return so that we don't call generic rangeEvent
}
}
// if not returned yet, call generic rangeEvent
rangeEvent(rX, rZ, rA, checkBehind, type, count)
}
int checkType(void vEnt, char typeSeq)
{
switch(typeSeq)
{
case "pl":
return getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER");
break;
case "npc":
return getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC");
break;
case "pl|npc":
return (getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER") ||
getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC"));
break;
default:
return 0;
}
}
void findTarget02(int Rx, int Rz, int Ra, int searchBack, char find_type, char name){
int iECnt = openborvariant("count_entities");
int iEnt;
void vEnt,ani;
void self = getlocalvar("self");
float x = getentityproperty(self, "x");
float z = getentityproperty(self, "z");
float a = getentityproperty(self, "a");
int dir=getentityproperty(self,"direction");
for(iEnt=0; iEnt<iECnt; iEnt++) {
vEnt = getentity(iEnt);
if(!getentityproperty(vEnt,"exists")) continue;
if (
getentityproperty(vEnt,"defaultmodel") == name &&
checkType(vEnt, find_type) &&
!getentityproperty(vEnt,"dead") &&
vEnt
){
if (isInRange(self,dir,vEnt,Rx,Rz,Ra,x,z,a, searchBack)){
return vEnt;
}
}
}
return NULL();
}