If you mark a door as needing a specific key to unlock, you can normally only supply it 1 key tag to be used. I needed to have multiple tags, so finally got this work-around functional
If you have a Door tag as "Jord_Door_1", you need to place a generic trigger in front of it named "Jord_Door_1_trig". The door is marked as locked and also marked as needing a specific key to open. The trigger's tag must correctly match the Door's tag with the additional ending for the script to work properly.
On the trigger's OnEnter event add this script:
Code: Select all
int HasItem(object oPlayer, string sItemTag)
{
int bReturnValue = FALSE;
object oItem = GetItemPossessedBy(oPlayer, sItemTag);
if (GetIsObjectValid(oItem)==TRUE){
bReturnValue = TRUE;
}
return bReturnValue;
}
void main()
{
object oPC = GetEnteringObject();
string sTrig = GetTag(OBJECT_SELF);
int iTrig = GetStringLength(sTrig) - 5;
string sDoor = GetStringLeft(sTrig, iTrig);
object oDoor = GetObjectByTag(sDoor);
string sItem1 = "XYZ1"; // tag of first key
string sItem2 = "XYZ2"; // tag of second key
string sItem3 = "XYZ3"; // tag of third key
string sItem4 = "XYZ4"; // tag of fourth key
string sItem5 = "XYZ5"; // tag of fifth key
if (HasItem(oPC, sItem1)|HasItem(oPC, sItem2)|HasItem(oPC, sItem3)|HasItem(oPC, sItem4)|HasItem(oPC, sItem5))
{
ActionDoCommand(SetLocked(oDoor, FALSE));
ActionOpenDoor(oDoor);
DelayCommand(6.0f, ActionCloseDoor(oDoor));
DelayCommand(6.0f, SetLocked(oDoor, TRUE));
SendMessageToPC(oPC, "You may pass");
}else
{
SendMessageToPC(oPC, "This area is restricted");
}
}
FYI, in case you were wondering, we found that you cannot apply this to the actual door, because the OnFailedToOpen() event of a door, does not generate either a valid GetLastUsedBy() or GetLastOpenedBy() value. Either of those would have been a much simpler solution.
If anyone sees something that could be optimized more, please let me know. Otherwise, please feel free to use.