Author Sticky: Post Working Scripts Here
Adam_wasserman Posted: Tuesday, 02 July 10:00AM
Draggable Placeable Objects

I think the write up is self explanitory. Feel free to email me with questions...

draelons@hotmail.com


Objects Needed:

1 needed per area
--------------------------
Name: Area Variable Holder
Tag: AVH
Appearance Type: Invisible Object

Properties
----------
Static: yes
Plot: yes

The AVH is responsible for storing the LocalVariables that are sent to it from any given draggable object.


1 needed per draggable instance
----------------------- ----------------------
Name: Statue Handle
Tag: hdl_ad_statue1

Properties
----------
Identified: yes
Weight Increase (set to what ever you desire the weight of the dragged object to be. This allows the aurora engine to automatically calculate encumbrance)

It is important to note the naming convention used for the tag of the handle. The convention is the prefix "hdl_" followed by the Blueprint ResRef of the custom placeable object you make. (In this example, "ad_statue1") Without the proper tag on the handle, your object will not be draggable.

1 needed per draggable instance
------------------------ ----------------------
Name: Draggable Statue
Tag: StatueStone
Appearance Type: Statue
Blueprint ResRef: ad_statue1

Properties
----------
Useable: yes
Has Inventory: yes
In the inventory, place the related handle object.
onClose: close_drag

This can be any placeable object. For my testing, I decided to use a statue. The script that runs onClose is basically responsible for storing local values in the AVH if a player loots the handle object. Once you set up the properties, make a custom object out of it and note the Blueprint ResRef so that you can create the proper tag for your handle object.

NWScript:
// =========== ============== ================ =========

//  array include

//	This function is responsible for simulating an array. It iterates over a set of local variables and returns the highest index.

//	If the object is invalid, or there are no values set yet, then it returns -1

// 	This should be included at the top of both of the other 2 scripts. You can cut and paste it in it's entirety or use an include file.

// ============= ============= ============== ===========

int fnGetIndex( object oObject, string sVarName, string sVarType ) {

    if ( GetIsObjectValid(oObject) != TRUE ) {

        return -1;

    }

    sVarType = GetStringLowerCase( sVarType );

    int i = 1;

    int iIndex = 1;

    if( sVarType == "object" ) {

      object oObjectToIndex = GetLocalObject( oObject, sVarName + IntToString(i) );

      if( oObjectToIndex != OBJECT_INVALID ) {

         while ( oObjectToIndex != OBJECT_INVALID ) {

            iIndex = i;

            i++;

            oObjectToIndex = GetLocalObject( oObject, sVarName + IntToString(i) );

         }

           return iIndex;

      } else {

         return -1;

      }

    } else if ( sVarType == "string" ) {

        string sObjectToIndex = GetLocalString( oObject, sVarName + IntToString(i) );

        if( sObjectToIndex != "" ) {

           while ( sObjectToIndex != "" ) {

               iIndex = i;

               i++;

               sObjectToIndex = GetLocalString( oObject, sVarName + IntToString(i) );

           }

           return iIndex;

      } else {

         return -1;

      }

    } else if ( sVarType == "int" ) {

        int iObjectToIndex = GetLocalInt( oObject, sVarName + IntToString(i) );

        if( iObjectToIndex != 0 ) {

           while ( iObjectToIndex != 0 ) {

               iIndex = i;

               i++;

               iObjectToIndex = GetLocalInt( oObject, sVarName + IntToString(i) );

           }

           return iIndex;

      } else {

         return -1;

      }

    } else if ( sVarType == "float" ) {

        float fObjectToIndex = GetLocalFloat( oObject, sVarName + IntToString(i) );

        if( fObjectToIndex != 0.0 ) {

           while ( fObjectToIndex != 0.0 ) {

               iIndex = i;

               i++;

               fObjectToIndex = GetLocalFloat( oObject, sVarName + IntToString(i) );

           }

           return iIndex;

      } else {

         return -1;

      }

    } else {

        return -1;

    }

}



NWScript:
// ============= ============= ================= ========

//  close_drag

//	This script is responsible for set local variables whenever a handle object is picked up. It should be placed in the

//	onClose event for the draggable object.

// ============ ============= ============ ==============

void main() {

    object oAVH = GetObjectByTag( "AVH", 0 );

    object oDragItem = OBJECT_SELF;

    object oPlayer = GetLastUsedBy();

    int nDragItemType = GetObjectType( oDragItem );

    object oInvItem = GetFirstItemInInventory(oPlayer);

    while ( oInvItem != OBJECT_INVALID ) {

        string sInvItemTag = GetTag(oInvItem);

        // check to see if inventory contains any handles

        if ( GetStringLeft( sInvItemTag, 4 ) == "hdl_" ) {

            // strip out resref

            string sDragItemResRef = GetSubString( sInvItemTag, 4, GetStringLength(sInvItemTag) );

            // store variables with the area variable handler

            int nIndex = fnGetIndex( oAVH, "oDragItem", "object" );

            if (nIndex == -1) {

                nIndex = 1;

            } else {

                nIndex++;

            }

            SetLocalObject( oAVH, "oDragItem" + IntToString( nIndex ), oDragItem );

            SetLocalInt( oAVH, "nDragItemType" + IntToString( nIndex ), nDragItemType );

            SetLocalString( oAVH, "sDragItemResRef" + IntToString( nIndex ), sDragItemResRef );

            SetLocalObject( oAVH, "oPlayer" + IntToString( nIndex ), oPlayer );

            break;

        }

        oInvItem = GetNextItemInInventory(oPlayer);

    }

}



NWScript:
// ============ ============== ================= ========

//  area_heart_drag

//	This is the workhorse of the package. It goes in the onHeartbeat event of the area. It basically uses the variables 

//	stored on our invisible object to first destroy the object that is being dragged, and then create a new object of the

//	same type. Currently the script does not maintain inventory items on the dragged item. They will be dumped to the

//	when the object is destroyed. This segment of code is also responsible for checking to make sure the players still 

//	have the handle object and cleaning up the AVH if they don't.

// =========== ============== ================ ==========

void main() {

    object oAVH = GetObjectByTag( "AVH", 0 );

    int nStop = fnGetIndex(  oAVH, "oDragItem", "object"  );

    int i;

    // drag all items that are flagged for dragging

    for( i = 1; i <= nStop; i++) {

        string sI = IntToString(i);

        // get the values from the AVH

        object oDragItem = GetLocalObject( oAVH, "oDragItem" + sI );

        int nDragItemType = GetLocalInt( oAVH, "nDragItemType" + sI );

        string sDragItemResRef = GetLocalString( oAVH, "sDragItemResRef" + sI );

        object oPlayer = GetLocalObject( oAVH, "oPlayer" + sI );

        location lDragLocation = GetLocation( oPlayer );



        // make sure the player still has the handle in their inventory

        object oHandle = GetObjectByTag( "hdl_" + sDragItemResRef );

        if( GetItemPossessor( oHandle ) == oPlayer ) {

            // Destroy old item

            DestroyObject(oDragItem, 0.0);

            // Create new item

            oDragItem = CreateObject( nDragItemType, sDragItemResRef, lDragLocation, FALSE );

                // ensure that we remove newly created handles

                object oHandle = GetFirstItemInInventory(oDragItem);

                while( oHandle != OBJECT_INVALID ) {

                    // check to see if of placeable inventory contains any handles

                    if ( GetStringLeft( GetTag(oHandle), 4 ) == "hdl_" ) {

                        DestroyObject(oHandle);

                    }

                    oHandle = GetNextItemInInventory(oDragItem);

                }

            // reassociate the placeable object with the AVH

            SetLocalObject( oAVH, "oDragItem" + sI, oDragItem );

        // otherwise, the handle has been dropped, so delete the references in the AVH

        } else {

            DeleteLocalObject( oAVH, "oDragItem" + sI );

            DeleteLocalInt( oAVH, "nDragItemType" + sI );

            DeleteLocalString( oAVH, "sDragItemResRef" + sI );

            DeleteLocalObject( oAVH, "oPlayer" + sI );

        }

    }

}