Files
HeroesStone_PRC8/_module/nss/flee_torch.nss
Jaysyn904 1eefc84201 Initial Commit
Initial Commit.
2025-09-14 15:40:46 -04:00

64 lines
2.2 KiB
Plaintext

#include "NW_I0_GENERIC"
int TorchCheck (object oPC);
int PCIsLooking(object oPC);
void main()
{
int nUD = GetUserDefinedEventNumber();
if (nUD == 1001)
{
//Creature searches for a PC that it can see and is
//bearing a torch.
int nCount = 1;
object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC, OBJECT_SELF,nCount, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
while (GetIsObjectValid(oPC))
{
if (TorchCheck(oPC) >= 0 &&
GetDistanceBetween(OBJECT_SELF,oPC) <= 10.0 &&
PCIsLooking(oPC))
{
//If the creature is within 10 meters of a PC seen
//carrying a torch, it moves until it is 10 meters
//away, then turns back around to fight again.
ClearAllActions();
ActionMoveAwayFromObject(oPC,FALSE,10.0);
ActionDoCommand(SetCommandable(TRUE,OBJECT_SELF));
ActionDoCommand(DetermineCombatRound());
SetCommandable(FALSE,OBJECT_SELF);
}
nCount++;
oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC, OBJECT_SELF,nCount, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
}
}
}
int TorchCheck (object oPC)
{
int nTCheck;
string sTag = GetTag(GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oPC));
string sTagLow = GetStringLowerCase(sTag);
nTCheck = FindSubString(sTagLow,"torch");
return nTCheck;
}
int PCIsLooking(object oPC)
{
// make all angles Integer, since we do not need floating point precision
int nPCFacing = FloatToInt( GetFacing(oPC) ); // angle PC is facing
int nPosition = FloatToInt( VectorToAngle( GetPosition(OBJECT_SELF)-GetPosition(oPC) ) ); // angle to NPC from PC
int nViewingAngle = 60; // VIEWING ANGLE to either side of forward facing
int nAngle = abs( nPCFacing - nPosition ); // difference in angles
if ( nAngle > 180 ) nAngle = 360-nAngle; // compensate for large differences (result of 0, 360 being same angle)
if ( nAngle <= nViewingAngle ) // check whether NPC is within PC "viewing angle"
{
return TRUE;
}
else
{
return FALSE;
}
}