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:
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:
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);
if ( GetStringLeft( sInvItemTag, 4 ) == "hdl_" ) {
string sDragItemResRef = GetSubString( sInvItemTag, 4, GetStringLength(sInvItemTag) );
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:
void main() {
object oAVH = GetObjectByTag( "AVH", 0 );
int nStop = fnGetIndex( oAVH, "oDragItem", "object" );
int i;
for( i = 1; i <= nStop; i++) {
string sI = IntToString(i);
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 );
object oHandle = GetObjectByTag( "hdl_" + sDragItemResRef );
if( GetItemPossessor( oHandle ) == oPlayer ) {
DestroyObject(oDragItem, 0.0);
oDragItem = CreateObject( nDragItemType, sDragItemResRef, lDragLocation, FALSE );
object oHandle = GetFirstItemInInventory(oDragItem);
while( oHandle != OBJECT_INVALID ) {
if ( GetStringLeft( GetTag(oHandle), 4 ) == "hdl_" ) {
DestroyObject(oHandle);
}
oHandle = GetNextItemInInventory(oDragItem);
}
SetLocalObject( oAVH, "oDragItem" + sI, oDragItem );
} else {
DeleteLocalObject( oAVH, "oDragItem" + sI );
DeleteLocalInt( oAVH, "nDragItemType" + sI );
DeleteLocalString( oAVH, "sDragItemResRef" + sI );
DeleteLocalObject( oAVH, "oPlayer" + sI );
}
}
}
|