/* Name: OnBlocked_Key
What it does: Same as the default OnBlocked script, but adds the ability for
NPC's to continue on their way to a destination that is set at either a run or
walk. Also allows NPC's to unlock doors if they have the key to the door.
Notes:
Each Key and Door set needs tags with the same prefix. The Door needs a suffix
of _DOOR, and the key needs a suffix of _KEY. For example, a door with the tag
ARMORY_DOOR, would need the key that unlocks it to have a tag of ARMORY_KEY. A
door with the tag X_DOOR, would need a key with the tag X_KEY.
There is a function, GetLockKeyTag(OBJECT), this is supposed to return the tag
of the key that unlocks the door(OBJECT). The problem is that a tag is a String
variable, and this function returns an integer. Even converting the integer to a
string does not give you the correct tag for the key to the door. This function
appears to me to be bugged. If anyone can get it working properly, I'd love to
know. If this function was working properly, there would not be a need to have
the prefix and suffix requirements. The script below works, its just that if the
GetLockKeyTag(OBJECT) function worked, I could write a much better script that
does the same thing. */
void main()
{
object oDoor = GetBlockingDoor();
string sDoorTag = GetTag(oDoor);
string sDoorTagC = GetStringUpperCase(sDoorTag);
int nDoorTagLngth = GetStringLength(sDoorTagC);
int nDoorKeyTagPos = FindSubString(sDoorTagC, "_DOOR");
int nDoorKeyTagLngth = (nDoorTagLngth-nDoorKeyTagPos);
string SKeyTagStart = GetStringLeft(sDoorTag, (nDoorKeyTagLngth+1));
string sKeyTag = (SKeyTagStart+"_KEY");
if (GetLocked(oDoor)==TRUE)
{
if (GetLockKeyRequired(oDoor)==TRUE)
{
object oKey = GetObjectByTag("ARMORY_KEY");
string skey = GetTag(oKey);
int nHasKey = GetIsObjectValid(GetItemPossessedBy(OBJECT_SELF, sKeyTag));
if (nHasKey == TRUE)
{
SetLocked(oDoor, 0);
}
}
}
if(GetAbilityScore(OBJECT_SELF, ABILITY_INTELLIGENCE) >= 5)
{
if(GetIsDoorActionPossible(oDoor, DOOR_ACTION_OPEN) &&
GetAbilityScore(OBJECT_SELF, ABILITY_INTELLIGENCE) >= 7 )
{
DoDoorAction(oDoor, DOOR_ACTION_OPEN);
object oDest = GetLocalObject(OBJECT_SELF,"DESTINATION");
int oSpeed = GetLocalInt(OBJECT_SELF,"SPEED");
if (oDest != OBJECT_INVALID)
{
ActionMoveToLocation(GetLocation(oDest),oSpeed);
}
}
else if(GetIsDoorActionPossible(oDoor, DOOR_ACTION_BASH))
{
DoDoorAction(oDoor, DOOR_ACTION_BASH);
object oDest = GetLocalObject(OBJECT_SELF,"DESTINATION");
int oSpeed = GetLocalInt(OBJECT_SELF,"SPEED");
if (oDest != OBJECT_INVALID)
{
ActionMoveToLocation(GetLocation(oDest),oSpeed);
}
}
}
}