Lever to Unlock and Open a Door

Greetings Vault Community, I’m currently beating my head against the wall trying to understand why the following script is not working. Basically, it’s just a simple lever that has the OnUsed Event to Unlock and Open a gate. For whatever reason, I am unable to get it to work, and I’m not sure what I’m missing since it seems like a relatively mundane thing to do, so I’m wondering if there’s something buggy about certain doors. I do have the appropriate tag set for the door:

void main()
{
object oPortcullis;
object oSound;
// Get the creature who triggered this event.
object oPC = GetLastUsedBy();

oPortcullis = GetObjectByTag("FE_Portcullis");

// Animate lever.
PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
DelayCommand(1.0, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
 oSound = GetObjectByTag("MillWheel");
DelayCommand(2.0, SoundObjectSetVolume(oSound, 127));
DelayCommand(2.2, SoundObjectPlay(oSound));

// Make changes to the sound object "MillWheel.
DelayCommand(6.0, SoundObjectStop(oSound));

SetLocked(oPortcullis, FALSE);
AssignCommand(oPortcullis, ActionOpenDoor(oPortcullis));

}

In another area of my module, I use this script to open two gates at once and it works fine:

void main()
{
object oTarget;
object oTarget2;
object oTarget3;
// Get the creature who triggered this event.
object oPC = GetLastUsedBy();

// Unlock and open "FE_Portcullises".
oTarget = GetObjectByTag("FE_Portcullis1");
oTarget2 = GetObjectByTag("FE_Portcullis2");

// Animate the lever.
PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
DelayCommand(1.0, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
 oTarget3 = GetObjectByTag("MillWheel2");
DelayCommand(2.0, SoundObjectSetVolume(oTarget3, 127));
DelayCommand(2.2, SoundObjectPlay(oTarget3));

// Make changes to the sound object "MillWheel.
DelayCommand(6.0, SoundObjectStop(oTarget3));

SetLocked(oTarget, FALSE);
SetLocked(oTarget2, FALSE);
AssignCommand(oTarget, ActionOpenDoor(oTarget));
AssignCommand(oTarget2, ActionOpenDoor(oTarget2));

}

one thing you might want to try is adding the following after line 8 :

if (!GetIsObjectValid(oPortcullis)) {
	SendMessageToPC(GetFirstPC(), "OH MY GODS! Someone stole the portcullis!!!");
}

if your portcullis object is actually valid, try verifying that its object type is OBJECT_TYPE_DOOR and that it has an open animation. it could be that the object returned isn’t the one you think, if there are multiple objects w/the same tag.

Thanks, Xorbaxian, but I think I figured it out. It turns out I should have been using GetNearestObjectByTag instead of GetObjectByTag. Apparently I had a couple other doors somewhere that had the same tag. Fixed, and all is well. Thank you.

1 Like