Author Sticky: Post Working Scripts Here
Andalus Posted: Thursday, 04 July 06:36PM
After much trial and tribulation, I’ve put together the following collection of scripts that allow PCs to pick up and move placeable objects (chairs, in this case). Everything works except for setting the facing after placement – if someone can get that working, please let me know!

What does it do These scripts will allow PCs to both sit in and to pick up and reposition chairs.

What would I use this for? Initially, I started working on the folding chair to allow PCs to reposition tavern furniture to suit the needs of the moment - to sit around tables, or set up concert seating, for example. However, these same methods could be applied to any placeable object you want the PCs to be able to move (stools, anvils, corpses, etc.). Note, if you only want PCs to be able to pick up the object (and not sit or perform some other action as well), then you can get rid of the coversation and put the appropriate script in the OnUsed event of the object.

How does it work?

There are several steps involved, but nothing's too complicated.

1) Create a custom chair object. Make it useable. I called mine "Folding Chair" (with "FoldingChair" as the tag). NOTE: You could just use the standard chair object, if you plan to let PCs pick up every chair you place. NOTE2: If you're running scripts that make NPCs sit in chairs, you'll need to update those to make them look for both standard chair objects and your new custom chair objects.

2) Create a custom item to represent the chair in the PC's inventory. Use something innocuous; I used a book. (NOTE: There aren't any appearances available that look much like a chair. I used a book because it sort of looks like it could be a chair that's folded up, and because it's not equipable or useable.). Be sure to give this item a name that will let PCs know what they're carrying. I used "Folded Chair." It also helps to put something in the description explaining that this object is in fact a chair. You may also want to make the item heavier: Properties -> Weight Increase.

3) In the OnUsed event of the "Folding Chair" object, place the following script:

NWScript:
void main()

{

//Start a conversation between the chair and the using PC.

    ActionStartConversation(GetLastUsedBy());

}



4) Create a conversation for your chair (advanced tab) that looks something like this:

NWScript:
1    Root

2    ....[OWNER] - Someone is already sitting in this chair. [END DIALOGUE]

3    ....[OWNER] - What do you want to do with this chair?

4    ....|.... Sit down.  [END DIALOGUE]

5    ....|.... Pick it up.  [END DIALOGUE]

6    ....|.... Nothing.  [END DIALOGUE]



5) On line (2) of the coversation, use the following script in Text Appears When...

NWScript:
int StartingConditional()

{

//Check to see if the chair is occupied.

    int iResult;

    iResult = GetIsObjectValid(GetSittingCreature(OBJECT_SELF)) == TRUE;

    return iResult;

}



6) On line (4) of the conversation, use the following script in Actions Taken:

NWScript:
void main()

{

//Sits the player in the chair, if it is unoccupied.

//Replace "FoldingChair" with the Tag of your object.

    object oPlayer = GetLastUsedBy();

    object oChair;

    if (GetIsPC(oPlayer))

    {

        oChair = GetNearestObjectByTag("FoldingChair", oPlayer, 0);

        if (GetIsObjectValid(oChair) && !GetIsObjectValid (GetSittingCreature (oChair)))

        {

            AssignCommand(oPlayer, ActionSit(oChair));

        }

    }

}



7) One line (5) of the conversation, use the following script in Actions Taken:

NWScript:
void main()

{

    // Put a folding chair in the PC's inventory.  Replace "FoldedChair" with the Tag of your inventory item.

    CreateItemOnObject("FoldedChair", GetPCSpeaker(), 1);

    // Make the chair object disappear

    DestroyObject(OBJECT_SELF);

}



8) In the OnUnAcquireItem event in Module Properties, place the following script:

NWScript:
void main()

{

//Define the Folding Chair inventory item - replace "FoldedChair" with the Tag of your Chair inventory item.

object oFChair = GetObjectByTag("FoldedChair");

//Check if the dropped item is the folding chair.

if (GetModuleItemLost() == oFChair)

    {

    location lFChair = GetLocation (oFChair);

    DestroyObject(oFChair);

    //Create a new chair in place of the dropped item.

    //Replace "foldingchair001" with the Blueprint of your Folding Chair Object

    CreateObject(OBJECT_TYPE_PLACEABLE, "foldingchair001", lFChair);

//    Here I want to set the facing of the chair, to either face directly towards or away from the dropping PC.

//    I've tried the following methods (and several minor variations of them):

//    SetFacingPoint(GetPosition(GetModuleItemLostBy()));

//    -and-

//    float fChairFacing = GetFacingFromLocation(GetLocation(GetModuleItemLostBy()));

//    SetFacing(fChairFacing);

//    ...neither works for me.  If you can get it working, please let me know!

    }

}



Enjoy!