void main()
{
    // Get the creature that triggered the OnOpen event.
    object oUser = GetLastOpenedBy();

    // Check if the creature has the CAS_VIPBADGE or the I_CAS_STAFF_KEY.
    if (GetIsObjectValid(GetItemPossessedBy(oUser, "CAS_VIPBADGE")) ||
        GetIsObjectValid(GetItemPossessedBy(oUser, "I_CAS_STAFF_KEY")))
    {
        // Unlock the door.
        SetLocked(OBJECT_SELF, FALSE);

        // Open the door.
        ActionDoCommand(ActionOpenDoor(OBJECT_SELF));

        // Close and lock the door after 30 seconds.
        DelayCommand(30.0, ActionDoCommand(ActionCloseDoor(OBJECT_SELF)));
        DelayCommand(30.1, SetLocked(OBJECT_SELF, TRUE));
    }
    else
    {
        // Send a message to the creature if the necessary item is not found.
        SendMessageToPC(oUser, "VIP BADGE not found, please go purchase one from the prize room.");
        
        // Prevent the door from opening by forcing it to close immediately.
        ActionDoCommand(ActionCloseDoor(OBJECT_SELF));
        
        // Ensure the door remains locked in case it wasn't already.
        SetLocked(OBJECT_SELF, TRUE);
    }
}
