Author Topic: DM NPC control & onExit event  (Read 547 times)

Legacy_Yester

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
DM NPC control & onExit event
« on: August 07, 2010, 11:55:24 am »


               Greetings,
I'm trying to make script using onExit event, but I found a problem I can't manage by myself.
The problem is, that in the case of taking control on NPC by DM, the DM avatar is calling Area onExit event. What's more - leaving NPC alone does not call onEnter script.
I have easy solution of the problem in my mind, but the real problem is how to recognize the event onExit with was called by taking control on NPC. Is there any way to do this?
Thanks for help, and sorry for my "English".
Yester

PS. Is there any reverse function of GetMaster()? I mean - the function with can found NPC possesed by given DM.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
DM NPC control & onExit event
« Reply #1 on: August 07, 2010, 12:17:23 pm »


               Not sure if this is the one you are looking for.  



// Returns TRUE if the creature oCreature is currently possessed by a DM character.

// Returns FALSE otherwise.

// Note: GetIsDMPossessed() will return FALSE if oCreature is the DM character.

// To determine if oCreature is a DM character use GetIsDM()

int GetIsDMPossessed(object oCreature)


               
               

               
            

Legacy_Yester

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
DM NPC control & onExit event
« Reply #2 on: August 07, 2010, 12:26:20 pm »


               Thanks for answer,

I know about this function, but using this function i can only find a NPC controlled by DM, looping through all NPC around.

It's kind of ugly solution...

The question is how to find NPC controlled by DM without looping trough all creatures in module.

Hm... Maybe there is a script called when DM is entering into creature? I couldn't find anything like that, but if You know about this kind of script I will be grateful ;-)
               
               

               
            

Legacy_Yester

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
DM NPC control & onExit event
« Reply #3 on: August 07, 2010, 02:02:47 pm »


               Ok,
For now i use this ugly solution, but if sombody have idea to do this better - please write a note here.

IMHO ugly solution (but still solution):
In onExit script conditional:

if(!GetIsDM(oPC) || !GetIsObjectValid(oGetIsInside(oPC, lArea)))

And function oGetIsInside:

object oGetIsInside(object oMaster, location lMarker){
    int nWO = 1;
    object oCreature = GetNearestCreatureToLocation(CREATURE_TYPE_IS_ALIVE, TRUE, lMarker, nWO);
    while(GetIsObjectValid(oCreature)){
        if(GetMaster(oCreature)==oMaster){
            return oCreature;
        }else{
            nWO++;
            oCreature = GetNearestCreatureToLocation(CREATURE_TYPE_IS_ALIVE, TRUE, lMarker, nWO);
        }
    }
    return OBJECT_INVALID;
}

Thanks for help, and please write if You have any better ideas.

--
Yester
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
DM NPC control & onExit event
« Reply #4 on: August 07, 2010, 05:18:43 pm »


               

The problem is, that in the case of taking control on NPC by DM, the DM avatar is calling Area onExit event.


You mean, that if DM use posses creature, that NPC will fire OnExit event in that moment?

if so, just simple check

if(GetIsDMPossessed(oPC)) return;

should do the trick I think
               
               

               
            

Legacy_Yester

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
DM NPC control & onExit event
« Reply #5 on: August 08, 2010, 03:27:30 pm »


               Nope

The think is, that onExit in this moment is called by DM avatar, so GetIsDMPossessed(oPC) will return false.

Maybe my solution isn't great, but it works. The question is how to find creature possessed by DM if we have only DM avatar object ;-)

Or.. Maybe there is another option to find out if onExit is executed by DM, with is currently getting control over creature.



Anyway - thanks for answer '<img'>
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
DM NPC control & onExit event
« Reply #6 on: August 08, 2010, 04:24:09 pm »


               I bet then exiting DM avatar is not PC...