Author Topic: How to make the Object Busy?  (Read 335 times)

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to make the Object Busy?
« on: April 06, 2014, 04:34:07 am »


               

I would like to do some actions to NPC (move to, open door, unlock door) and it can not be stopped (talking or object in front).


 


Example: you talked to the NPC and he has already started to do some actions, but he can not be stopped because the actions are canceled (he must finish all).


 


other bad is if someone is in front, the action is canceled, can not have anyone else in their way (even an object)


 


the NPC has 4 waypoints to walk random so whatever script action will be canceled to walk to this waypoints, so we need remove the AI (artificial inteligence) for a time (temporary)


 


I made a script, but is still in trouble


 


/////////////////////////////////////////////////////////////////////////


void main()

{

        if(GetArea(OBJECT_SELF) == GetArea(GetObjectByTag("WP_CarmemWalk_006")))

   {

    object oDoor1 = GetObjectByTag("Door_TavdaEstr_Out");

    object oDoor2 = GetObjectByTag("Door_ArredNefTum_In");

    if (GetObjectType(oDoor1) == OBJECT_TYPE_DOOR && GetObjectType(oDoor2) == OBJECT_TYPE_DOOR && GetLocked(oDoor2))

    {

    SetAILevel(OBJECT_SELF, AI_LEVEL_VERY_LOW);

    DelayCommand(85.0, SetAILevel(OBJECT_SELF, AI_LEVEL_DEFAULT));

    ActionMoveToObject(GetObjectByTag("WP_CarmemWalk_000"), TRUE);

    ActionMoveToObject(GetObjectByTag("WP_CarmemWalk_0001"), TRUE);

    ActionMoveToObject(GetObjectByTag("WP_CarmemWalk_001"), TRUE);

    ActionMoveToObject(GetObjectByTag("WP_CarmemWalk_002"), TRUE);

    ActionMoveToObject(GetObjectByTag("WP_CarmemWalk_003"), TRUE);

    ActionMoveToObject(GetObjectByTag("WP_CarmemWalk_004"), TRUE);

    ActionMoveToObject(GetObjectByTag("WP_CarmemWalk_005"), TRUE);

    ActionUnlockObject(oDoor2);

    ActionOpenDoor(oDoor2);

    ActionWait(10.0);

    ActionMoveToObject(GetObjectByTag("WP_CarmemWalk_006"), TRUE);

    return;

    }

 

    FloatingTextStringOnCreature ("Door already opened", GetPCSpeaker());

    return;

}

 

 

    FloatingTextStringOnCreature ("Carmem invalid area", GetPCSpeaker());

    return;

 

}

 

/////////////////////////////////////////////////////////////////////////


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
How to make the Object Busy?
« Reply #1 on: April 06, 2014, 09:58:39 am »


               If you want to ensure the NPC actions happen without interruption, don't change the AI level, just close the action queue, as follows:


Action..
Action..
Action..
ActionDoCommand(SetCommandable(TRUE));
SetCommandable(FALSE);
ActionDoCommand is preferable to DelayCommand, because it happens at precisely the right time, when all the other actions are complete.

To work around blocking, I use ActionForceMoveToObject.
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
How to make the Object Busy?
« Reply #2 on: April 06, 2014, 10:34:45 am »


               

This is what Proleric is talking about...


void DoStuff(object oDoor2)
{
    ActionForceMoveToObject(GetObjectByTag("WP_CarmemWalk_000"), TRUE);
    ActionForceMoveToObject(GetObjectByTag("WP_CarmemWalk_0001"), TRUE);
    ActionForceMoveToObject(GetObjectByTag("WP_CarmemWalk_001"), TRUE);
    ActionForceMoveToObject(GetObjectByTag("WP_CarmemWalk_002"), TRUE);
    ActionForceMoveToObject(GetObjectByTag("WP_CarmemWalk_003"), TRUE);
    ActionForceMoveToObject(GetObjectByTag("WP_CarmemWalk_004"), TRUE);
    ActionForceMoveToObject(GetObjectByTag("WP_CarmemWalk_005"), TRUE);
    ActionUnlockObject(oDoor2);
    ActionOpenDoor(oDoor2);
    ActionWait(10.0);
    ActionForceMoveToObject(GetObjectByTag("WP_CarmemWalk_006"), TRUE);
    ActionDoCommand(SetCommandable(TRUE));
    SetCommandable(FALSE);
}
 
void main()
{
    if(GetArea(OBJECT_SELF) == GetArea(GetObjectByTag("WP_CarmemWalk_006")))
    {
        object oDoor1 = GetObjectByTag("Door_TavdaEstr_Out");
        object oDoor2 = GetObjectByTag("Door_ArredNefTum_In");
        if (GetObjectType(oDoor1) == OBJECT_TYPE_DOOR && GetObjectType(oDoor2) == OBJECT_TYPE_DOOR && GetLocked(oDoor2))
        {
            AssignCommand(GetPCSpeaker(),DoStuff(oDoor2));
        }
        else FloatingTextStringOnCreature ("Door already opened", GetPCSpeaker());
    }
    else FloatingTextStringOnCreature ("Carmem invalid area", GetPCSpeaker());
}

               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to make the Object Busy?
« Reply #3 on: April 07, 2014, 06:57:18 am »


               

Thank you very much