Author Topic: OnPerception Invisibility Script  (Read 341 times)

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
OnPerception Invisibility Script
« on: November 19, 2013, 01:26:32 am »


               Put this together but the OnPercieved Event fires, even though the player is invisible. Only the player is in the party, no summons, companions, etc., but the guard still shouts "You there! Stop!", goes hostile and runs toward the PC.

The PC is invisible via the Invisibility spell, so the guard eventually returns to the friendly faction, then repeats the actions over again.

Anyone care to see what I've done wrong here?

#include "NW_I0_GENERIC"
void SetDetectState()
{

object oHostile = GetObjectByTag("hostile");
object oPC = GetFirstPC();
object oDetected = GetLastPerceived();

object oAC = GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oPC);
object oD = GetAssociate(ASSOCIATE_TYPE_DOMINATED, oPC);
object oF = GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oPC);
object oH = GetAssociate(ASSOCIATE_TYPE_HENCHMAN, oPC);
object oS = GetAssociate(ASSOCIATE_TYPE_SUMMONED, oPC);

int nPC = InvisibleTrue(oPC);
int nAnimalCompanion = InvisibleTrue(oAC);
int nDominated = InvisibleTrue(oD);
int nFamiliar = InvisibleTrue(oF);
int nHenchman = InvisibleTrue(oH);
int nSummoned = InvisibleTrue(oS);

int nIsDetected = GetLocalInt(oPC, "IsDetected");

  // PLAYER IN TRIGGER BEHIND CRATES HIDING
 // DEBUG: WORKS!
  if (GetLocalInt(GetFirstPC(), "lbhide") == 1) return;

  // PLAYER MAY HAVE KILLED A GUARD AND IS WALKING AROUND AS ONE
  // DEBUG: WORKS!
  if ( (GetTag(GetItemInSlot(INVENTORY_SLOT_CHEST, GetFirstPC())) == "bghguardarmor") &&
       (GetTag(GetItemInSlot(INVENTORY_SLOT_HEAD, GetFirstPC())) == "bghguardhelm") ) return;

  // CHECK TO SEE IF PLAYER PARTY IS INDEED INVISIBLE
  // DEBUG: HALF-ASSED FAIL
  if ( (nPC == TRUE) &&
     (nAnimalCompanion == TRUE) &&
     (nDominated == TRUE) &&
     (nFamiliar == TRUE) &&
     (nHenchman == TRUE) &&
     (nSummoned == TRUE)) return;

  if ((oDetected == oPC) && (GetLocalInt(OBJECT_SELF, "SeenPC") == 0))
  {
    SetLocalInt(OBJECT_SELF, "SeenPC", 1);
    SetLocalInt(oPC, "IsDetected", (nIsDetected +1));

    //FloatingTextStringOnCreature("[DeBug] +1 Detected!", oPC, FALSE);
    AssignCommand(OBJECT_SELF, ClearAllActions());
    AssignCommand(GetObjectByTag("250B13_GUARD2"), ClearAllActions());
    AssignCommand(GetObjectByTag("250B13_GUARD3"), ClearAllActions());

    DelayCommand(0.5, ChangeFaction(OBJECT_SELF, oHostile));
    DelayCommand(0.5, ChangeFaction(GetObjectByTag("250B13_GUARD2"), oHostile));
    DelayCommand(0.5, ChangeFaction(GetObjectByTag("250B13_GUARD3"), oHostile));

    DelayCommand(0.5, AssignCommand(OBJECT_SELF, SpeakString("You there! Stop!")));

    DelayCommand(0.6, ActionForceMoveToObject(oPC, TRUE, 1.0f, 20.0f));
    DelayCommand(0.7, DetermineCombatRound());
    DelayCommand(0.7, AssignCommand(GetObjectByTag("250B13_GUARD2"), DetermineCombatRound()));
    DelayCommand(0.7, AssignCommand(GetObjectByTag("250B13_GUARD3"), DetermineCombatRound()));
    SetLocalObject(OBJECT_SELF, "PCSeen", oDetected);
    SetLocalInt(GetModule(), "lbalarm", 1);
    }

  }


void ClearDetectState()
{

object oPC = GetLocalObject(OBJECT_SELF, "PCSeen");
object oFriendly = GetObjectByTag("friendly");
object oForgotten = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_NOT_SEEN_AND_NOT_HEARD, 1);

int nIsDetected = GetLocalInt(oPC, "IsDetected");

  if ((GetLocalInt(OBJECT_SELF, "SeenPC") == 1) && (oPC == oForgotten))
  {

    SetLocalInt(OBJECT_SELF, "SeenPC", 0);
    SetLocalInt(oPC, "IsDetected", (nIsDetected -1));

    //FloatingTextStringOnCreature("[DeBug] -1 Forgotten!", oPC, FALSE);
    DelayCommand(0.5, ChangeFaction(OBJECT_SELF, oFriendly));
    DelayCommand(0.5, ChangeFaction(GetObjectByTag("250B13_GUARD2"), oFriendly));
    DelayCommand(0.5, ChangeFaction(GetObjectByTag("250B13_GUARD3"), oFriendly));
    if ( (GetLocalInt(oPC, "IsDetected") < 0) )

    SetLocalInt(oPC, "IsDetected", 0);
    }
}

void main()
{
SetDetectState();
ClearDetectState();
}


Thanks,

FP!
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
OnPerception Invisibility Script
« Reply #1 on: November 19, 2013, 02:54:52 am »


               I suspect InvisibleTrue returns FALSE for invalid objects. You say there is no henchperson, no animal companion etc...

Your big // CHECK TO SEE IF PLAYER PARTY IS INDEED INVISIBLE test will only work if the PC has each of those types of companions _and_ they are all invisible.

Cheers,
Meaglyn