This script is modified from HotU. It has a floor arrow that is supposed to unlock the thing it is facing (the arrow spins). In this one there are 2 chests and a door. The door unlocks as it should but the chests do not. All tags are set right. The script is set on the arrow (floor design)
If some one could figure out why the chests do not unlock I would appreciate it.
///////////////////////////////////////////////////////////////////////////////////
// This script will lock an unlock objects depending on which way the arrow faces.
//
// Created by: Brad Prince
// 9-17-02
//
//////////////////////////////////////////////////////////////////////////////////
void main()
{
/* The arrow visually faces the opposite direction of the "Facing" on the
object, so reverse the meaning of the direcions.
Also, East is 0.0, counter clockwise to north at 90.0, etc.
*/
float ARROW_NORTH = 270.0;
float ARROW_WEST = 180.0;
float ARROW_SOUTH = 90.0;
int NORTH = 90;
int EAST = 0;
int SOUTH = 270;
int WEST = 180;
float fFacing = GetFacing(OBJECT_SELF);
// Flip the fFacing to represent the way the arrow is actually pointing.
int aFacing = (FloatToInt(fFacing) + 180) % 360;
object oNorth = GetObjectByTag("chest_north");
object oSouth = GetObjectByTag("chest_south");
object oWest = GetObjectByTag("door_west");
// Variable for random direction calculating.
int x;
if (oNorth==OBJECT_INVALID){SpeakString ("north invalid");}
if (oSouth==OBJECT_INVALID){SpeakString ("south invalid");}
// Query the current direction.
if(aFacing > (NORTH-5) && aFacing < (NORTH+5)) {
// Arrow is currently facing North
x = 1;
}
else if(aFacing > (SOUTH-5) && aFacing < (SOUTH+5)) {
// Arrow is currently facing South
x = 2;
}
else if(aFacing > (WEST-5) && aFacing < (WEST+5)) {
// Arrow is currently facing West
x = 4;
}
else {
// This one (east) isn't used.
x = 3;
}
// Have us say something.
SpeakString("(was x = " + IntToString(x) + ", arrow facing " + IntToString(aFacing) + ")" );
switch(x) {
case 1:
// Originally North, change to South
if(!GetIsOpen(oNorth)) {
SetLocked(oNorth, 1);
}
SetLocked(oSouth, 0);
SetLocked(oWest, 1);
AssignCommand(oWest, ActionCloseDoor(OBJECT_SELF));
SetFacing(ARROW_SOUTH);
SpeakString("1 south chest unlocked");
break;
case 2:
// Originally South, change to West
if(!GetIsOpen(oNorth)) {
SetLocked(oNorth, 1);
}
if(!GetIsOpen(oSouth)) {
SetLocked(oSouth, 1);
}
SetLocked(oWest, 0);
SetFacing(ARROW_WEST);
SpeakString("2 west door unlocked");
break;
case 3:
// Originally West, change to North
SetLocked(oNorth, 0);
if(!GetIsOpen(oSouth)) {
SetLocked(oSouth, 1);
}
SetLocked(oWest, 1);
AssignCommand(oWest, ActionCloseDoor(OBJECT_SELF));
SetFacing(ARROW_NORTH);
SpeakString("3 north chest unlocked");
break;
default:
SetLocked(oNorth, 1);
SetLocked(oSouth, 1);
SetLocked(oWest, 1);
AssignCommand(oWest, ActionCloseDoor(OBJECT_SELF));
SetFacing(DIRECTION_WEST);
SpeakString("Default");
break;
}
SpeakString("(now x = " +IntToString(x)+", arrow facing "+FloatToString(GetFacing(OBJECT_SELF)) + ")" );
}