Author Topic: NPC opens and closes a placeable  (Read 565 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NPC opens and closes a placeable
« on: April 14, 2011, 03:04:51 am »


               The following code should direct an NPC to walk over toward, and then open and close a placeable:

ActionMoveToObject(oCabinet);
ActionInteractObject(oCabinet);
ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,1.0,3.0);
ActionInteractObject(oCabinet);


The NPC clearly walks to the placeable and does something with the placeable, but the placeable does not appear to open or close. I have also tried:

ActionMoveToObject(oCabinet);
AssignCommand(oCabinet, PlayAnimation(ANIMATION_PLACEABLE_OPEN));
ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,1.0,3.0);
AssignCommand(oCabinet, PlayAnimation(ANIMATION_PLACEABLE_CLOSE));


Still nothing which I am quite surprised by. (Yes, the oCabinet was set to commandable, and yes it can be opened and closed by a PC). What does it take to show a placeable's open/close animation?
               
               

               


                     Modifié par henesua, 14 avril 2011 - 02:05 .
                     
                  


            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #1 on: April 14, 2011, 03:19:50 am »


               Just throwing the ovious out there.Make sure its useable and has inventory
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #2 on: April 14, 2011, 03:26:11 am »


               DoPlaceableObjectAction( oCabinet,PLACEABLE_ACTION_USE);
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #3 on: April 14, 2011, 03:50:41 am »


                Anthony - yup.
Lightfoot8 - I should have mentioned that I tried that as well. It doesn't work. And furthermore, that function also breaks conversation which I don't necessarily want to do.

Could it be the placeable? This is the "Shelf_2" placeable  from Project Q. Could it be that some placeables will only respond to the PC?

On top of all of the above, I have the NPC look inside the cabinet, and if they find a particular item there, they retrieve it. The script finds the item, but the NPC is unable to take it.

if ( GetLocalInt(OBJECT_SELF, "package_found") )
{
       ActionSpeakString(q+"That's odd."+q);
       ActionTakeItem(oItem, oCabinet);
}


The NPC says "That's odd." which indicates to me that the package was found in oCabinet, but the NPC does not take the item.

-- Anyhow, I need to step away from thecomputer and do other things for a bit. Hopefully, I'll have some insight when I return.
               
               

               


                     Modifié par henesua, 14 avril 2011 - 02:52 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #4 on: April 14, 2011, 03:57:11 am »


               First sugestion-- is to try to change the placeable to a standard NWN placeable and see what happens.

two-- see if applying the actions to a pc works.  

Three-- Make sure the placeable does not have any scripts on it that are preventing the NPC from working it.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #5 on: April 14, 2011, 05:11:44 am »


               Oddly enough..when I went in to test some different things...I can't get an NPC to interact with a chest. I can get it to move to the chest with both ActionMoveToObject or ActionInteractObject but once he gets there, via the ActionInteractObject function or moving him there and then calling the ActionInteractObject funcion, he freezes in place and won't open the chest. After this happens a PC can not open the chest either. Interesting.

And using a debugging line with the function GetIsPlaceableObjectActionPossible(oChest, PLACEABLE_ACTION_USE) the NPC says he can't use the chest. ~scratches head~ Seems like this should be straight forward.

Actually I don't think I've ever tried to script something like this before so It would be nice to figure this out for myself as well.
               
               

               


                     Modifié par GhostOfGod, 14 avril 2011 - 04:14 .
                     
                  


            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #6 on: April 14, 2011, 05:28:02 am »


               Must be the on open script then maybe it checks the last pc that opens the chest and gets stuck so no one else can open it...............i dunno..my 2 cents.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #7 on: April 14, 2011, 05:39:24 am »


               Interesting,  I guess it make since that if the Object has inventory and the game tryes to open an inventory window to the NPC's Client., things are going to freeze up.  

Try removing the inventory for the placeable and see if it works.  

If it does just move the inventory to an invisiable object and have the OnUse script open that container if the first one is used by a PC.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #8 on: April 14, 2011, 02:04:00 pm »


               The inventory is definitely the problem. Once the inventory is removed, the placeable responds to scripts that call its animations. I placed a script that plays open and close animations in the onused event, and the NPC now appears to open and close the cabinet.

Now I need to implement the workaround of the invisible inventory object.

{Edit}
Using a second object to handle inventory is clunky, but not so bad that I won't do it. Is there a better way for a PC to access the invisible object's inventory than assigning ActionInteractObject to the PC?

Here's the code:
object oPC  =   GetLastUsedBy();
if (GetIsPC(oPC))
{
     // Reveal
     object oInventory = GetObjectByTag(GetTag(OBJECT_SELF) + "_inventory");
     AssignCommand(oPC, ActionInteractObject(oInventory));
}

               
               

               


                     Modifié par henesua, 14 avril 2011 - 01:50 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #9 on: April 14, 2011, 03:39:15 pm »


               In case anyone else ever needs to do the same thing here's the code I wrote to handle this problem:

This first script goes on the placeable you want an NPC to animate when they use it. You will need to use a second object for handling inventory.
//::///////////////////////////////////////////////
//:: mg_plc_openclose
//:://////////////////////////////////////////////
/*
    App: OnUsed event of a placeable which lacks inventory
             associate this placeable with an invisible placeable that has inventory
             invis plc has the same tag as parent + "_inv"
    Reason: NPCs and Scripts are unable to animate placeables with inventory.

Used Event:
    - animates object to open or close
    - if used by PC: looks in the associated object's inventory

Local Int
    - OPEN  (Tracks state of object)
*/
//:://////////////////////////////////////////////
//:: Created: The Magus (2011 apr 14)
//:://////////////////////////////////////////////

void main()
{
    int bOpen             =   GetLocalInt(OBJECT_SELF,"OPEN");
    if (!bOpen)
    {
        SetLocalInt(OBJECT_SELF,"OPEN", TRUE);
        PlayAnimation(ANIMATION_PLACEABLE_OPEN);
        // Inventory Object
        object oPC  =   GetLastUsedBy();
        if (GetIsPC(oPC))
        {
            // Reveal
            object oInventory = GetObjectByTag(GetTag(OBJECT_SELF) + "_inv");
            AssignCommand(oPC, ActionInteractObject(oInventory));
        }
    }
    else
    {
        DeleteLocalInt(OBJECT_SELF,"OPEN");
        PlayAnimation(ANIMATION_PLACEABLE_CLOSE);
    }
}



This second script goes on the invisible placeable. The invisible placeable should be usable and have inventory.
//::///////////////////////////////////////////////
//:: mg_plc_invclose
//:://////////////////////////////////////////////
/*
On closed event of an invisible placeable with inventory
This is for an invisible placeable paired with a visible one,
    and acting as its inventory. See mg_plc_openclose

Closed event:
    - directs the parent object to close
*/
//:://////////////////////////////////////////////
//:: Created: The Magus (2011 apr 14)
//:://////////////////////////////////////////////
void main()
{
    string sTag         = GetTag(OBJECT_SELF);
    int iPos1           = FindSubString(sTag, "_inv");
    string sTagParent   = GetStringLeft(sTag, iPos1);
    object oParent      = GetObjectByTag(sTagParent);
    DeleteLocalInt(oParent, "OPEN");
    AssignCommand(oParent, PlayAnimation(ANIMATION_PLACEABLE_CLOSE) );
}

               
               

               


                     Modifié par henesua, 14 avril 2011 - 02:44 .
                     
                  


            

Legacy_Artistmonk

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +0/-0
NPC opens and closes a placeable
« Reply #10 on: May 04, 2011, 04:41:55 pm »


               Thanks.